unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* RFC: tag macros
@ 2012-01-18 14:45 David Bremner
  2012-01-18 15:04 ` David Edmondson
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: David Bremner @ 2012-01-18 14:45 UTC (permalink / raw)
  To: Notmuch Mail


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)))

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-01-19 13:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-18 14:45 RFC: tag macros David Bremner
2012-01-18 15:04 ` David Edmondson
2012-01-18 18:33 ` Austin Clements
2012-01-18 19:03   ` David Bremner
2012-01-18 19:11     ` Austin Clements
2012-01-18 19:28     ` Jameson Graef Rollins
2012-01-18 18:50 ` Jameson Graef Rollins
2012-01-19  0:04   ` David Bremner
2012-01-19  2:15     ` Jameson Graef Rollins
2012-01-19  2:37       ` David Bremner
2012-01-19 13:10   ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).