From d89f475052d60251c6b26f89ec067ddeeac5f2a3 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 19 Dec 2022 11:06:40 -0700 Subject: mailscripts.el: notmuch-extract-thread-patches: add Gnus support Signed-off-by: Sean Whitton --- debian/changelog | 1 + mailscripts.el | 36 ++++++++++++++++++++++-------------- 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") -- cgit v1.2.3