summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-12-19 11:06:40 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-12-19 12:26:04 -0700
commitd89f475052d60251c6b26f89ec067ddeeac5f2a3 (patch)
tree5c690a65296f5013660a2e5bc2fa5436fc20588b
parent0d0ec3916c1a7089dc172347b0031cca4046b21d (diff)
downloadmailscripts-d89f475052d60251c6b26f89ec067ddeeac5f2a3.tar.gz
mailscripts.el: notmuch-extract-thread-patches: add Gnus support
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--debian/changelog1
-rw-r--r--mailscripts.el36
2 files changed, 23 insertions, 14 deletions
diff --git a/debian/changelog b/debian/changelog
index f5bf071..d195a03 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,7 @@ mailscripts (28-1) UNRELEASED; urgency=medium
* mailscripts.el:
- new commands: mailscripts-git-format-patch-{attach,drafts}
- new DWIM wrapper command: mailscripts-prepare-patch
+ - notmuch-extract-thread-patches: add Gnus support
- rewrite short description and add a brief commentary
- load the notmuch library only when code that requires it is called
- move the mailscripts customisation group into the mail group
diff --git a/mailscripts.el b/mailscripts.el
index 566b38b..8bf6bc6 100644
--- a/mailscripts.el
+++ b/mailscripts.el
@@ -133,27 +133,31 @@ particular, this Emacs Lisp function supports passing only entire
threads to the notmuch-extract-patch(1) command."
(interactive
"Dgit repo: \nsnew branch name (or leave blank to apply to current HEAD): \nP")
- (require 'notmuch)
- (let ((thread-id
- ;; If `notmuch-show' was called with a notmuch query rather
- ;; than a thread ID, as `org-notmuch-follow-link' in
- ;; org-notmuch.el does, then `notmuch-show-thread-id' might
- ;; be an arbitrary notmuch query instead of a thread ID. We
- ;; need to wrap such a query in thread:{} before passing it
- ;; to notmuch-extract-patch(1), or we might not get a whole
- ;; thread extracted (e.g. if the query is just id:foo)
- (if (string= (substring notmuch-show-thread-id 0 7) "thread:")
- notmuch-show-thread-id
- (concat "thread:{" notmuch-show-thread-id "}")))
+ (let ((search
+ (cond
+ ((derived-mode-p 'gnus-summary-mode 'gnus-article-mode)
+ (mailscripts--gnus-message-id-search t))
+ ((derived-mode-p 'notmuch-show-mode)
+ ;; If `notmuch-show' was called with a notmuch query rather
+ ;; than a thread ID, as `org-notmuch-follow-link' in
+ ;; org-notmuch.el does, then `notmuch-show-thread-id' might
+ ;; be an arbitrary notmuch query instead of a thread ID. We
+ ;; need to wrap such a query in thread:{} before passing it
+ ;; to notmuch-extract-patch(1), or we might not get a whole
+ ;; thread extracted (e.g. if the query is just id:foo)
+ (if (string= (substring notmuch-show-thread-id 0 7) "thread:")
+ notmuch-show-thread-id
+ (concat "thread:{" notmuch-show-thread-id "}")))
+ (t (user-error "Unsupported major mode"))))
(default-directory (expand-file-name repo)))
(mailscripts--check-out-branch branch)
(shell-command
(if reroll-count
(format "notmuch-extract-patch -v%d %s | git am"
(prefix-numeric-value reroll-count)
- (shell-quote-argument thread-id))
+ (shell-quote-argument search))
(format "notmuch-extract-patch %s | git am"
- (shell-quote-argument thread-id)))
+ (shell-quote-argument search)))
"*notmuch-apply-thread-series*")))
;;;###autoload
@@ -359,6 +363,10 @@ See also the interactive wrapper command `mailscripts-prepare-patch'."
(concat mailscripts-extract-patches-branch-prefix branch)
branch))))))
+(defun mailscripts--gnus-message-id-search (&optional thread)
+ (format (if thread "thread:{id:%s}" "id:%s")
+ (string-trim (gnus-summary-header "message-id") "<" ">")))
+
(defvar projectile-known-projects)
(declare-function project-prompt-project-dir "project")
(declare-function projectile-completing-read "projectile")