RFC: tag macros
David Bremner
david at tethera.net
Wed Jan 18 06:45:06 PST 2012
Hi All;
Here is a very early stage proposal to provide tagging macros for
notmuch show mode.
The idea is that user defines a mapping from single key to a sequence of
tagging operations. It might be nice if there as some kind of pop-up
menu, or at least a prompt, but I didn't do that so far.
The advantage of this rather than just writing lots of little lambdas is
that it combines adding and deleting, and it could be done via
customize.
As provided, the code should just paste into .emacs, and with a little
editing into notmuch-show.el.
% ---- cut here ----
(eval-after-load 'notmuch-show
'(define-key notmuch-show-mode-map "t" 'notmuch-show-apply-tag-macro))
(setq notmuch-show-tag-macro-alist
(list '("p" "+notmuch::patch" "+notmuch::needs-review")
'("r" "+notmuch::review")
'("o" "+notmuch::patch" "+notmuch::obsolete" "-notmuch::needs-review")
'("m" "+notmuch::patch" "+notmuch::moreinfo" "-notmuch::needs-review")))
(defun notmuch-show-apply-tag-macro (key)
(interactive "k")
(let ((macro (assoc key notmuch-show-tag-macro-alist)))
(apply 'notmuch-show-add-or-del-tags (cdr macro))))
(defun notmuch-show-add-or-del-tags (&rest add-or-dels)
"Add or delete tags to/from the current message."
(let* ((current-tags (notmuch-show-get-tags))
(new-tags (notmuch-show-add-or-del-tags-worker current-tags add-or-dels)))
(unless (equal current-tags new-tags)
(apply 'notmuch-tag (notmuch-show-get-message-id) add-or-dels)
(notmuch-show-set-tags new-tags))))
(defun notmuch-show-add-or-del-tags-worker (current-tags add-or-dels)
"Remove any tags in `add-or-del' prefixed with `-' from `current-tags', add any prefixed with `+'
and return the result."
(let (adds deletes)
(mapc (lambda (tag-str)
(if (string-match "^\\([+\-]\\)\\(.*\\)" tag-str)
(let ((op (match-string 1 tag-str))
(tag (match-string 2 tag-str)))
(if (equal op "+")
(setq adds (cons tag adds))
(setq deletes (cons tag deletes))))
(error "%s: does not start with + or -" tag-str)))
add-or-dels)
(notmuch-show-del-tags-worker
(notmuch-show-add-tags-worker current-tags adds)
deletes)))
More information about the notmuch
mailing list