unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: "Notmuch Mail" <notmuch@notmuchmail.org>
Subject: RFC: tag macros
Date: Wed, 18 Jan 2012 10:45:06 -0400	[thread overview]
Message-ID: <874nvtvzm5.fsf@convex-new.cs.unb.ca> (raw)


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

             reply	other threads:[~2012-01-18 14:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-18 14:45 David Bremner [this message]
2012-01-18 15:04 ` RFC: tag macros 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874nvtvzm5.fsf@convex-new.cs.unb.ca \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).