From a2a9bb379e97085249287b29560f789c7ccc63a5 Mon Sep 17 00:00:00 2001 From: jao Date: Thu, 3 Mar 2022 22:15:21 +0000 Subject: more gnus and notmuch tagging integration --- gnus.org | 6 ++++++ lib/net/jao-notmuch-gnus.el | 30 +++++++++++++++--------------- notmuch.org | 2 +- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/gnus.org b/gnus.org index 558b98e..c6320c8 100644 --- a/gnus.org +++ b/gnus.org @@ -530,10 +530,16 @@ (gnus-summary-goto-article (cdr jao-gnus--last-move) nil t))) (add-hook 'gnus-summary-article-move-hook 'jao-gnus-move-hook) + (defun jao-gnus--tag-archiving () + (when (string-match ".+:\\(.+\\)" jao-gnus--archiving-group) + (let ((tags (match-string 1 jao-gnus--archiving-group))) + (jao-notmuch-gnus-toggle-tags (split-string tags "\\."))))) + (defun jao-gnus-archive (follow) (interactive "P") (if jao-gnus--archiving-group (progn + (jao-gnus--tag-archiving) (if (or jao-gnus--archive-as-copy-p (not (gnus-check-backend-function 'request-move-article gnus-newsgroup-name))) diff --git a/lib/net/jao-notmuch-gnus.el b/lib/net/jao-notmuch-gnus.el index 3f18f12..1951ae0 100644 --- a/lib/net/jao-notmuch-gnus.el +++ b/lib/net/jao-notmuch-gnus.el @@ -31,28 +31,30 @@ ;;; Tagging in notmuch from Gnus buffers (defun jao-notmuch-gnus-message-id () - "Find the id currently selected message in Gnus." + "Find the id of currently selected message in Gnus or notmuch." (when (derived-mode-p 'gnus-summary-mode) (save-window-excursion (gnus-summary-show-article))) - (when gnus-original-article-buffer - (with-current-buffer gnus-original-article-buffer - (when-let (id (message-field-value "message-id")) - (if (string-match "<\\(.+\\)>" id) - (match-string 1 id) - id))))) + (cond (gnus-original-article-buffer + (with-current-buffer gnus-original-article-buffer + (when-let (id (message-field-value "message-id")) + (if (string-match "<\\(.+\\)>" id) + (match-string 1 id) + id)))) + ((derived-mode-p 'notmuch-show-mode 'notmuch-tree-mode) + (notmuch-show-get-message-id)))) (defun jao-notmuch-gnus-message-tags (id) "Ask notmuch for the tags of a message with the given ID." (let ((cmd (format "notmuch search --output=tags 'id:%s'" id))) (split-string (shell-command-to-string cmd)))) -(defun jao-notmuch-gnus-tag-message () +(defun jao-notmuch-gnus-tag-message (&optional id tags) "Interactively add or remove tags to the current message." (interactive) - (let* ((id (jao-notmuch-gnus-message-id)) + (let* ((id (or id (jao-notmuch-gnus-message-id))) (current (jao-notmuch-gnus-message-tags id)) (prompt (format "Change tags %s" (string-join current "/"))) - (tags (notmuch-read-tag-changes current prompt))) + (tags (or tags (notmuch-read-tag-changes current prompt)))) (notmuch-tag (concat "id:" id) tags) (message "%s -> %s" current (jao-notmuch-gnus-message-tags id)))) @@ -72,17 +74,16 @@ (notmuch-tag (concat "id:" id) tags) (message "New tags: %s" (jao-notmuch-gnus-message-tags id)))) - ;;;; Displaying search results in Gnus (defvar jao-notmuch-gnus-server "nnml" "Name of the target Gnus server, e.g. nnml+mail.") -(defvar jao-notmuch-gnus-mail-directory message-directory +(defvar jao-notmuch-gnus-mail-directory (expand-file-name "~/.emacs.d/gnus/Mail") "Directory where Gnus stores its mail.") -(defvar jao-notmuch-gnus-leafnode-directory "~/var/news" +(defvar jao-notmuch-gnus-leafnode-directory (expand-file-name "~/var/news") "Directory where leafnode stores its messages as seen by notmuch.") (defun jao-notmuch-gnus-file-to-group (file &optional maildir newsdir) @@ -122,8 +123,7 @@ Example: (defun jao-notmuch-gnus-goto-message () "Open a summary buffer containing the current notmuch article." (interactive) - (let ((group (jao-notmuch-gnus-file-to-group (notmuch-show-get-filename) - jao-notmuch-gnus-mail-directory)) + (let ((group (jao-notmuch-gnus-file-to-group (notmuch-show-get-filename))) (message-id (replace-regexp-in-string "^id:" "" (notmuch-show-get-message-id)))) diff --git a/notmuch.org b/notmuch.org index 236c9a3..4a0a98d 100644 --- a/notmuch.org +++ b/notmuch.org @@ -492,7 +492,7 @@ ("M-u" . jao-notmuch-tree-reset-tags)))) #+end_src * org mode - Stolen and adapted from [[https://gist.github.com/fedxa/fac592424473f1b70ea489cc64e08911][Fedor Bezrukov]]. + Stolen and adapted from [[https://gist.github.com/fedxa/fac592424473f1b70ea489cc64e08911][Fedor Bezrukov]]. #+begin_src emacs-lisp (defvar jao-org-notmuch-last-subject nil) (defun jao-org-notmuch-last-subject () jao-org-notmuch-last-subject) -- cgit v1.2.3