unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] New function notmuch-search-operate-all: operate on all messages in the current query.
@ 2009-11-22 20:12 Jed Brown
  2009-11-23  4:14 ` Carl Worth
  0 siblings, 1 reply; 12+ messages in thread
From: Jed Brown @ 2009-11-22 20:12 UTC (permalink / raw)
  To: notmuch

It is often convenient to change tags on several messages at once.  This
function applies any number of tag whitespace-delimited tag
modifications to all messages matching the current query.

I have bound this to `*'.

Signed-off-by: Jed Brown <jed@59A2.org>
---
 notmuch.el |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index a547415..b848e9a 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -764,6 +764,7 @@ thread from that buffer can be show when done with this one)."
     (define-key map (kbd "RET") 'notmuch-search-show-thread)
     (define-key map "+" 'notmuch-search-add-tag)
     (define-key map "-" 'notmuch-search-remove-tag)
+    (define-key map "*" 'notmuch-search-operate-all)
     (define-key map "<" 'beginning-of-buffer)
     (define-key map ">" 'notmuch-search-goto-last-thread)
     (define-key map "=" 'notmuch-search-refresh-view)
@@ -940,6 +941,29 @@ This function advances point to the next line when finished."
   (notmuch-search-remove-tag "inbox")
   (forward-line))
 
+(defun notmuch-search-operate-all (action)
+  "Operate on all messages matching the current query.  Any
+number of whitespace separated actions can be given.  Each action
+must have one of the two forms
+
+  +tagname              Add the tag `tagname'
+  -tagname              Remove the tag `tagname'
+
+Each character of the tag name may consist of alphanumeric
+characters as well as `_.+-'.
+"
+  (interactive "sOperation (+add -drop): notmuch tag ")
+  (let ((action-split (split-string action " +")))
+    ;; Perform some validation
+    (let ((words action-split))
+      (when (null words) (error "No operation given"))
+      (while words
+	(unless (string-match-p "^[\+\-][_\+\-\\w]+$" (car words))
+	  (error "Action must be of the form `+thistag -that_tag'"))
+	(setq words (cdr words))))
+    (apply 'notmuch-call-notmuch-process "tag"
+	   (append action-split (list notmuch-search-query-string) nil))))
+
 (defun notmuch-search (query &optional oldest-first)
   "Run \"notmuch search\" with the given query string and display results."
   (interactive "sNotmuch search: ")
-- 
1.6.5.3

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

end of thread, other threads:[~2009-11-28 20:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-22 20:12 [PATCH] New function notmuch-search-operate-all: operate on all messages in the current query Jed Brown
2009-11-23  4:14 ` Carl Worth
2009-11-23 13:07   ` Jed Brown
2009-11-26 21:00     ` Carl Worth
2009-11-26 21:36       ` [PATCH 1/2] " Jed Brown
2009-11-26 21:36         ` [PATCH 2/2] notmuch-search-add/remove-tag: restrict to messages in " Jed Brown
2009-11-27 14:02         ` [PATCH 1/2] New function notmuch-search-operate-all: operate on all messages in the " Carl Worth
2009-11-27 14:32           ` Jed Brown
2009-11-28  5:48             ` Carl Worth
2009-11-28 19:51           ` [PATCH] More portable and easier to read regex in notmuch-search-operate-all Jed Brown
2009-11-28 19:58             ` Keith Packard
2009-11-28 20:01               ` Carl Worth

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