[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-04 Thread Carl Worth
On Wed,  2 Dec 2009 12:00:35 +0100, Jed Brown  wrote:
> notmuch-search-filter now accepts an arbitrary query and will group if
> necessary so that we get
> 
>   tag:inbox AND (gravy OR biscuits)
> 
> instead of the former
> 
>   tag:inbox AND gravy OR biscuits

Perfect. A nice clean patch for just the one feature. Thanks!

I've pushed this now.

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



Re: [notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-04 Thread Carl Worth
On Wed,  2 Dec 2009 12:00:35 +0100, Jed Brown j...@59a2.org wrote:
 notmuch-search-filter now accepts an arbitrary query and will group if
 necessary so that we get
 
   tag:inbox AND (gravy OR biscuits)
 
 instead of the former
 
   tag:inbox AND gravy OR biscuits

Perfect. A nice clean patch for just the one feature. Thanks!

I've pushed this now.

-Carl


pgpptmtW52QwL.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-02 Thread Jed Brown
Jan, thanks for looking into this.

On Wed, 2 Dec 2009 15:38:54 +0100, Jan Janak  wrote:
> This seems close enough to what you want and maybe we could somehow make it
> work with notmuch, too. This would be interesting to have, because then we
> could complete multiple tag names with a single TAB press not only in your
> expressions, but everywhere.

Yes, I think that is desirable.

> Let me know if you do not plan to work on this and I'll see if I can make it
> work.

I'm not using tags heavily at the moment, and am busy with other things
so I'm unlikely to get to it in the next couple weeks.  If you can make
completion work with this sort of input, I'll update my filter-by-tags
patch.

Jed


[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-02 Thread Jan Janak
Jed,

On 02-12 14:46, Jed Brown wrote:
> On Wed, 2 Dec 2009 14:18:08 +0100, Jan Janak  wrote:
> > I haven't been really following this thread in detail. What is that you need
> > from notmuch-select-tag-with-completion? To be able to process a list of 
> > tags
> > separated by spaces? Maybe I could help you with that.
> 
> No, it would need to take input separated by spaces, now I just get `[No
> match]' when I try to enter a space.  I think it's just not how
> completing-read works, the idea would be for the user to be able to type
> 
>   shorttag and not long
> 
> which would complete to
> 
>   shorttag and not longboringtagname

I see.

> The point of my patch was to be able to filter using arbitrary
> expressions where every non-operator, i.e. `and', `or', `not', `(', and
> `)', is interpreted as a tag name.  Is there an easy way to accept this
> input without sacrificing completion?

I am not completely sure, but there might be a way to do this with some of the
low-level completion functions. For example, the documentation on completion
styles:

http://www.gnu.org/software/emacs/elisp/html_node/Completion-Styles.html#Completion-Styles

mentions in the last paragraph that there is a style which completes each word
in the input separately. This can be enabled with (partial-completion-mode),
and indeed, if I enable this mode, try to visit a file and type ~/.n-c 
then it correctly completes ~/.notmuch-config. 

This seems close enough to what you want and maybe we could somehow make it
work with notmuch, too. This would be interesting to have, because then we
could complete multiple tag names with a single TAB press not only in your
expressions, but everywhere.

Right now we can only add one tag at a time with notmuch-search-add-tag and
similar functions. If we could make partial completion work, we could add
several tags with one command and still have their names completed.

Let me know if you do not plan to work on this and I'll see if I can make it
work.

-Jan


[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-02 Thread Jed Brown
On Wed, 2 Dec 2009 14:18:08 +0100, Jan Janak  wrote:
> I haven't been really following this thread in detail. What is that you need
> from notmuch-select-tag-with-completion? To be able to process a list of tags
> separated by spaces? Maybe I could help you with that.

No, it would need to take input separated by spaces, now I just get `[No
match]' when I try to enter a space.  I think it's just not how
completing-read works, the idea would be for the user to be able to type

  shorttag and not long

which would complete to

  shorttag and not longboringtagname

The point of my patch was to be able to filter using arbitrary
expressions where every non-operator, i.e. `and', `or', `not', `(', and
`)', is interpreted as a tag name.  Is there an easy way to accept this
input without sacrificing completion?

Jed


[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-02 Thread Jan Janak
On 02-12 11:59, Jed Brown wrote:
> A patch for notmuch-search-filter follows, my change to
> notmuch-search-filter-by-tag is not very useful since
> notmuch-select-tag-with-completion does not allow a space to be
> inserted.  I don't know how to get completion on multiple
> space-separated terms.

notmuch-select-tag-with-completion uses "\n" as tag separator. This is because
it gets the output of 'notmuch search-tags' as input and there is one tag on a
line.

I haven't been really following this thread in detail. What is that you need
from notmuch-select-tag-with-completion? To be able to process a list of tags
separated by spaces? Maybe I could help you with that.

-Jan


[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-02 Thread Jed Brown
notmuch-search-filter now accepts an arbitrary query and will group if
necessary so that we get

  tag:inbox AND (gravy OR biscuits)

instead of the former

  tag:inbox AND gravy OR biscuits

Signed-off-by: Jed Brown 
---
 notmuch.el |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 2509651..0bf82f5 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -995,6 +995,8 @@ thread from that buffer can be show when done with this 
one)."
 (defvar notmuch-search-oldest-first t
   "Show the oldest mail first in the search-mode")

+(defvar notmuch-search-disjunctive-regexp  "\\<[oO][rR]\\>")
+
 (defun notmuch-search-scroll-up ()
   "Move forward through search results by one window's worth."
   (interactive)
@@ -1327,7 +1329,8 @@ search."
 Runs a new search matching only messages that match both the
 current search results AND the additional query string provided."
   (interactive "sFilter search: ")
-  (notmuch-search (concat notmuch-search-query-string " and " query) 
notmuch-search-oldest-first))
+  (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp 
query) (concat "( " query " )") query)))
+(notmuch-search (concat notmuch-search-query-string " and " grouped-query) 
notmuch-search-oldest-first)))

 (defun notmuch-search-filter-by-tag (tag)
   "Filter the current search results based on a single tag.
-- 
1.6.5.3



[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-02 Thread Jed Brown
A patch for notmuch-search-filter follows, my change to
notmuch-search-filter-by-tag is not very useful since
notmuch-select-tag-with-completion does not allow a space to be
inserted.  I don't know how to get completion on multiple
space-separated terms.

On Tue, 01 Dec 2009 18:56:59 -0800, Carl Worth  wrote:
> PS. Hmm... "notmuch reply" needs to be more clever to avoid duplicate
> addresses in the To: and Cc: lines. See above.

Yes, uniquifying the headers actually requires some effort, unless I'm
missing something in the gmime API (which I've never looked at before).

Jed


Re: [notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-02 Thread Jan Janak
Jed,

On 02-12 14:46, Jed Brown wrote:
 On Wed, 2 Dec 2009 14:18:08 +0100, Jan Janak j...@ryngle.com wrote:
  I haven't been really following this thread in detail. What is that you need
  from notmuch-select-tag-with-completion? To be able to process a list of 
  tags
  separated by spaces? Maybe I could help you with that.
 
 No, it would need to take input separated by spaces, now I just get `[No
 match]' when I try to enter a space.  I think it's just not how
 completing-read works, the idea would be for the user to be able to type
 
   shorttag and not longTAB
 
 which would complete to
 
   shorttag and not longboringtagname

I see.

 The point of my patch was to be able to filter using arbitrary
 expressions where every non-operator, i.e. `and', `or', `not', `(', and
 `)', is interpreted as a tag name.  Is there an easy way to accept this
 input without sacrificing completion?

I am not completely sure, but there might be a way to do this with some of the
low-level completion functions. For example, the documentation on completion
styles:

http://www.gnu.org/software/emacs/elisp/html_node/Completion-Styles.html#Completion-Styles

mentions in the last paragraph that there is a style which completes each word
in the input separately. This can be enabled with (partial-completion-mode),
and indeed, if I enable this mode, try to visit a file and type ~/.n-cTAB 
then it correctly completes ~/.notmuch-config. 

This seems close enough to what you want and maybe we could somehow make it
work with notmuch, too. This would be interesting to have, because then we
could complete multiple tag names with a single TAB press not only in your
expressions, but everywhere.

Right now we can only add one tag at a time with notmuch-search-add-tag and
similar functions. If we could make partial completion work, we could add
several tags with one command and still have their names completed.

Let me know if you do not plan to work on this and I'll see if I can make it
work.

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


Re: [notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-02 Thread Jed Brown
Jan, thanks for looking into this.

On Wed, 2 Dec 2009 15:38:54 +0100, Jan Janak j...@ryngle.com wrote:
 This seems close enough to what you want and maybe we could somehow make it
 work with notmuch, too. This would be interesting to have, because then we
 could complete multiple tag names with a single TAB press not only in your
 expressions, but everywhere.

Yes, I think that is desirable.

 Let me know if you do not plan to work on this and I'll see if I can make it
 work.

I'm not using tags heavily at the moment, and am busy with other things
so I'm unlikely to get to it in the next couple weeks.  If you can make
completion work with this sort of input, I'll update my filter-by-tags
patch.

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


[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-12-01 Thread Carl Worth
On Mon, 23 Nov 2009 19:07:23 +0100, Jed Brown  wrote:
> notmuch-search-filter accepts now accepts an arbitrary query and will
> group if necessary so that we get
> 
>   tag:inbox AND (gravy OR biscuits)
> 
> notmuch-search-filter-tag now handles multiple terms.  All terms in the
> query except AND and OR are interpreted as tags.

Hi Jed,

Sorry this one has sat in my queue for a while. But I finally got around
to it.

The above commit message (and the patch below) really do implement two
separate features, so really should be separated into two separate
commits. I do like both of the ideas, and will be glad to commit both
when they arrive separate.

> This version has nice regexes and handles NOT.

And that kind of commentary, (referring to a previous revision of the
patch), is great in an email discussion like we're having here, but
won't make any sense within the context of the log of commit
messages. So such commentary is best placed *after* the "---" separator.

> Signed-off-by: Jed Brown 
> ---

That is, the commentary would go here in the original message, and then
I won't have to "commit --amend" the commentary away after applying the
patch.

Thanks,

-Carl

PS. Hmm... "notmuch reply" needs to be more clever to avoid duplicate
addresses in the To: and Cc: lines. See above.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-11-23 Thread Jed Brown
On Mon, 23 Nov 2009 10:26:47 -0800, Keith Packard  wrote:

> Remember to split patches which do more than one thing into separate
> commits.

These are variants of the same operation, but I'll split in the future.

> > +  (let ((grouped-query (if (string-match-p 
> > notmuch-search-disjunctive-regexp query) (concat "( " query " )") query)))
> > +(notmuch-search (concat notmuch-search-query-string " and " 
> > grouped-query) notmuch-search-oldest-first)))
> 
> Is there some reason not to just always add the parens?

That's what I did initially, but it's messy to look at in the mode line
after applying successive filters.

> This seems useful; how does it deal with the tag completion stuff?

It doesn't do anything special, but I haven't been following that
carefully.  My thought was that eventually the regular interactive
search and filters, would have semantic completion, e.g. the user enters

  tag:ab

and tags would be completed, but they could also do

  from:long.unwieldy.addr

In filter-by-tag, the natural thing would be to only complete tags, the
user would be on their own to spell out AND, OR, and NOT.  Unfortunately
I'm not familiar enough with elisp to implement this quickly.

A closely related issue is managing the address book.  I guess the usual
advice is to use BBDB.  I don't know if it's better to hook into that or
for Notmuch to have it's own lightweight approach.  I could imagine
harvesting addresses of everyone I've sent mail to and giving me a
semi-automated way to merge addresses that are likely to point to the
same person.


Jed


[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-11-23 Thread Jed Brown
notmuch-search-filter accepts now accepts an arbitrary query and will
group if necessary so that we get

  tag:inbox AND (gravy OR biscuits)

notmuch-search-filter-tag now handles multiple terms.  All terms in the
query except AND and OR are interpreted as tags.

This version has nice regexes and handles NOT.

Signed-off-by: Jed Brown 
---
 notmuch.el |   27 ++-
 1 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 0cabbe2..fdd30ae 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -828,6 +828,10 @@ thread from that buffer can be show when done with this 
one)."
 (defvar notmuch-search-query-string)
 (defvar notmuch-search-oldest-first)

+(defvar notmuch-search-boolean-operator-regexp 
"\\([aA][nN][dD]\\|[oO][rR]\\|[nN][oO][tT]\\)")
+(defvar notmuch-search-valid-term-regexp   "\\([-+_.[:word:]]+\\)")
+(defvar notmuch-search-disjunctive-regexp  "\\<[oO][rR]\\>")
+
 (defun notmuch-search-scroll-up ()
   "Scroll up, moving point to last message in thread if at end."
   (interactive)
@@ -1057,15 +1061,28 @@ search."
 Runs a new search matching only messages that match both the
 current search results AND the additional query string provided."
   (interactive "sFilter search: ")
-  (notmuch-search (concat notmuch-search-query-string " and " query) 
notmuch-search-oldest-first))
+  (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp 
query) (concat "( " query " )") query)))
+(notmuch-search (concat notmuch-search-query-string " and " grouped-query) 
notmuch-search-oldest-first)))

-(defun notmuch-search-filter-by-tag (tag)
-  "Filter the current search results based on a single tag.
+(defun notmuch-search-filter-by-tag (query)
+  "Filter the current search results based on one or more tags.

 Runs a new search matching only messages that match both the
-current search results AND that are tagged with the given tag."
+current search results AND that are tagged with the given
+expression involving tags.  For example, the input
+
+  chicken and (gravy or biscuits)
+
+will filter the current search by
+
+  tag:chicken and ( tag:gravy or tag:biscuits )"
   (interactive "sFilter by tag: ")
-  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) 
notmuch-search-oldest-first))
+  (let ((tagged-query (replace-regexp-in-string 
notmuch-search-valid-term-regexp
+   (lambda (match) ; Prepend 
`tag:' to all except boolean operators
+ (if (string-match-p 
notmuch-search-boolean-operator-regexp match)
+ match (concat "tag:" 
match)))
+   query)))
+(notmuch-search-filter tagged-query)))

 (defun notmuch ()
   "Run notmuch to display all mail with tag of 'inbox'"
-- 
1.6.5.3



[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-11-23 Thread Jed Brown
notmuch-search-filter accepts now accepts an arbitrary query and will
group if necessary so that we get

  tag:inbox AND (gravy OR biscuits)

notmuch-search-filter-tag now handles multiple terms.  All terms in the
query except AND and OR are interpreted as tags.

Signed-off-by: Jed Brown 
---
 notmuch.el |   23 ++-
 1 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 0cabbe2..43e0566 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -1057,15 +1057,28 @@ search."
 Runs a new search matching only messages that match both the
 current search results AND the additional query string provided."
   (interactive "sFilter search: ")
-  (notmuch-search (concat notmuch-search-query-string " and " query) 
notmuch-search-oldest-first))
+  (let ((grouped-query (if (string-match-p "\\<[oO][rR]\\>" query) (concat "( 
" query " )") query)))
+(notmuch-search (concat notmuch-search-query-string " and " grouped-query) 
notmuch-search-oldest-first)))

-(defun notmuch-search-filter-by-tag (tag)
-  "Filter the current search results based on a single tag.
+(defun notmuch-search-filter-by-tag (query)
+  "Filter the current search results based on one or more tags.

 Runs a new search matching only messages that match both the
-current search results AND that are tagged with the given tag."
+current search results AND that are tagged with the given
+expression involving tags.  For example, the input
+
+  chicken and (gravy or biscuits)
+
+will filter the current search by
+
+  tag:chicken and ( tag:gravy or tag:biscuits )"
   (interactive "sFilter by tag: ")
-  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) 
notmuch-search-oldest-first))
+  (let ((tagged-query (replace-regexp-in-string "\\([_\+\-]\\|\\w\\)+"
+   (lambda (match) ; Prepend 
`tag:' to all matches except AND and OR
+ (if (string-match-p 
"\\([aA][nN][dD]\\)\\|\\([oO][rR]\\)" match)
+ match (concat "tag:" 
match)))
+   query)))
+(notmuch-search-filter tagged-query)))

 (defun notmuch ()
   "Run notmuch to display all mail with tag of 'inbox'"
-- 
1.6.5.3



[notmuch] [PATCH] Make search filters handle disjunctive queries.

2009-11-23 Thread Keith Packard
On Mon, 23 Nov 2009 19:07:23 +0100, Jed Brown  wrote:

> notmuch-search-filter accepts now accepts an arbitrary query and will
> group if necessary so that we get
> 
>   tag:inbox AND (gravy OR biscuits)
> 
> notmuch-search-filter-tag now handles multiple terms.  All terms in the
> query except AND and OR are interpreted as tags.

Remember to split patches which do more than one thing into separate
commits.

> +  (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp 
> query) (concat "( " query " )") query)))
> +(notmuch-search (concat notmuch-search-query-string " and " 
> grouped-query) notmuch-search-oldest-first)))

Is there some reason not to just always add the parens?

> +  (let ((tagged-query (replace-regexp-in-string 
> notmuch-search-valid-term-regexp
> + (lambda (match) ; Prepend 
> `tag:' to all except boolean operators
> +   (if (string-match-p 
> notmuch-search-boolean-operator-regexp match)
> +   match (concat "tag:" 
> match)))
> + query)))

This seems useful; how does it deal with the tag completion stuff?

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