[notmuch] [PATCH 1/2] New function notmuch-search-operate-all: operate on all messages in the current query.

2009-11-27 Thread Carl Worth
On Fri, 27 Nov 2009 15:32:44 +0100, Jed Brown  wrote:
> On Fri, 27 Nov 2009 06:02:45 -0800, Carl Worth  wrote:
> > Since this operates via a single call to "notmuch tag" you might mention
> > here that all tag removals occur before any tag additions.
> 
> I was unaware of this point, if I do
> 
>   notmuch tag -inbox +star tag:inbox some-expression
> 
> I will have starred nothing?

Oh no, it's not that.

It does one search and then does a single pass over all the messages
returned. So the above will star things.

The clarification about removing and adding really only matters if you
have the same tag appearing as both -foo and +foo in the same command
line, (which doesn't seem that useful, but there you have it).

I don't recall now why I made the special effort to handle tag removal
before tag addition rather than just applying tag changes in order. But
since that's what the current "notmuch tag" code does, I thought I
should point it out.

> > > + (unless (string-match-p "^[\+\-][_\+\-\\w]+$" (car words))
> > > +   (error "Action must be of the form `+thistag -that_tag'"))
> > 
> > The error message has inconsistent "thistag" and "that_tag".
> 
> That was somewhat intentional to illustrate that non-alphanumeric
> characters could be used in tags.  Should the alphabet for tags be based
> on a whitelist or blacklist?  It would be rather hard to validate a tag
> operation when there is no assumption/restriction on the alphabet.

Yeah, that's something we need to document. The current interface does
use space-separated tag lists without any escaping. But the command line
doesn't yet impose any restriction on tag names, and I did accidentally
add a tag once of just " " (oops!).

We should nail this down so that interface authors can know how to
validate things consistently. Any suggestions?

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[notmuch] [PATCH 1/2] New function notmuch-search-operate-all: operate on all messages in the current query.

2009-11-27 Thread Jed Brown
On Fri, 27 Nov 2009 06:02:45 -0800, Carl Worth  wrote:
> Since this operates via a single call to "notmuch tag" you might mention
> here that all tag removals occur before any tag additions.

I was unaware of this point, if I do

  notmuch tag -inbox +star tag:inbox some-expression

I will have starred nothing?

> > +   (unless (string-match-p "^[\+\-][_\+\-\\w]+$" (car words))
> > + (error "Action must be of the form `+thistag -that_tag'"))
> 
> The error message has inconsistent "thistag" and "that_tag".

That was somewhat intentional to illustrate that non-alphanumeric
characters could be used in tags.  Should the alphabet for tags be based
on a whitelist or blacklist?  It would be rather hard to validate a tag
operation when there is no assumption/restriction on the alphabet.

Jed
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 



[notmuch] [PATCH 1/2] New function notmuch-search-operate-all: operate on all messages in the current query.

2009-11-27 Thread Carl Worth
On Thu, 26 Nov 2009 22:36:49 +0100, Jed Brown  wrote:
> 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.

Thanks Jed,

I've applied both this and the following patch, (giving the consistent
treatment to '+, '-', and 'a'). One or two minor comments:

> +  +tagname  Add the tag `tagname'
> +  -tagname  Remove the tag `tagname'
> +
> +Each character of the tag name may consist of alphanumeric
> +characters as well as `_.+-'.

Since this operates via a single call to "notmuch tag" you might mention
here that all tag removals occur before any tag additions.

> + (unless (string-match-p "^[\+\-][_\+\-\\w]+$" (car words))
> +   (error "Action must be of the form `+thistag -that_tag'"))

The error message has inconsistent "thistag" and "that_tag".

But niether nit was worth blocking the commit on.

Thanks again,

-Carl


Re: [notmuch] [PATCH 1/2] New function notmuch-search-operate-all: operate on all messages in the current query.

2009-11-27 Thread Carl Worth
On Thu, 26 Nov 2009 22:36:49 +0100, Jed Brown j...@59a2.org wrote:
 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.

Thanks Jed,

I've applied both this and the following patch, (giving the consistent
treatment to '+, '-', and 'a'). One or two minor comments:

 +  +tagname  Add the tag `tagname'
 +  -tagname  Remove the tag `tagname'
 +
 +Each character of the tag name may consist of alphanumeric
 +characters as well as `_.+-'.

Since this operates via a single call to notmuch tag you might mention
here that all tag removals occur before any tag additions.

 + (unless (string-match-p ^[\+\-][_\+\-\\w]+$ (car words))
 +   (error Action must be of the form `+thistag -that_tag'))

The error message has inconsistent thistag and that_tag.

But niether nit was worth blocking the commit on.

Thanks again,

-Carl
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH 1/2] New function notmuch-search-operate-all: operate on all messages in the current query.

2009-11-26 Thread Jed Brown
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 
---
 notmuch.el |   24 
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index d7c973c..6adac9e 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -801,6 +801,7 @@ thread from that buffer can be show when done with this 
one)."
 (define-key map [mouse-1] '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)
@@ -1001,6 +1002,29 @@ This function advances point to the next line when 
finished."
  (set 'more nil))
   (delete-process proc

+(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  oldest-first)
   "Run \"notmuch search\" with the given query string and display results."
   (interactive "sNotmuch search: ")
-- 
1.6.5.3