[notmuch] [PATCH v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-04-13 Thread Jesse Rosenthal
Sorry -- just got back into town from some business travel. I'll be
working on it this afternoon, and will let you know by this evening
where I get with it.

Best,
Jesse

On Tue, 13 Apr 2010 10:55:55 -0700, Carl Worth  wrote:
> On Fri, 09 Apr 2010 10:11:00 -0400, Jesse Rosenthal  
> wrote:
> > I'll play with both and see which is clearer.
> 
> Any progress here, Jesse?
> 
> I'd like to release notmuch 0.2 soon and would prefer not to revert this
> feature, (but I also don't really want to ship it with this known bug).
> 
> -Carl
Non-text part: application/pgp-signature


Re: [notmuch] [PATCH v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-04-13 Thread Jesse Rosenthal
Sorry -- just got back into town from some business travel. I'll be
working on it this afternoon, and will let you know by this evening
where I get with it.

Best,
Jesse

On Tue, 13 Apr 2010 10:55:55 -0700, Carl Worth  wrote:
> On Fri, 09 Apr 2010 10:11:00 -0400, Jesse Rosenthal  
> wrote:
> > I'll play with both and see which is clearer.
> 
> Any progress here, Jesse?
> 
> I'd like to release notmuch 0.2 soon and would prefer not to revert this
> feature, (but I also don't really want to ship it with this known bug).
> 
> -Carl
Non-text part: application/pgp-signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] [PATCH v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-04-13 Thread Carl Worth
On Fri, 09 Apr 2010 10:11:00 -0400, Jesse Rosenthal  wrote:
> I'll play with both and see which is clearer.

Any progress here, Jesse?

I'd like to release notmuch 0.2 soon and would prefer not to revert this
feature, (but I also don't really want to ship it with this known bug).

-Carl


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


[notmuch] [PATCH v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-04-13 Thread Carl Worth
On Fri, 09 Apr 2010 10:11:00 -0400, Jesse Rosenthal  
wrote:
> I'll play with both and see which is clearer.

Any progress here, Jesse?

I'd like to release notmuch 0.2 soon and would prefer not to revert this
feature, (but I also don't really want to ship it with this known bug).

-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 v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-04-09 Thread Jesse Rosenthal
On Wed, 07 Apr 2010 14:10:38 -0700, Carl Worth  wrote:
> On Tue, 16 Feb 2010 19:07:40 -0500, Jesse Rosenthal  
> wrote:
> I think this feature is very useful, and that the region is definitely
> an appropriate way to implement it, (doing region-based operations is
> very natural for emacs users). Mutt-style marking could be implemented
> as well, but that would be separate I think.

Great -- never sure if my intuitive use corresponds with that of others.

> I also don't like the duplication of code in
> notmuch-search-add-tag-thread and notmuch-search-add-tag-region, (and
> the same in the remove case). Fortunately, I think this easy to avoid by
> simply making notmuch-search-add-tag-thread call:
> 
>(notmuch-search-add-tag-region tag (point) (point))
> 
> and the same in the remove case.

Good idea.

> 
> But I haven't pushed this patch yet for a flaw in the case of selecting
> beyond the last thread, (such as selecting to the line that includes the
> "End of search results). If I try an operation on that line, it will act
> like it works, (it displays the new tags by all threads), but then a
> refresh makes them all disappear again. Presumably the "notmuch tag"
> command is failing, this isn't being noticed, and the code marches on to
> update the representation of the tags.

Good point, and shouldn't be too hard to fix. It seems like it could be
done either (a) at the lisp level (filtering out the blank entries), or
(b) at the literal buffer level (having a step that sets point-max for
the region appropriately). The choice (a) seems clearer in an abstract
way, but has the downside of needing to be repeated twice (both for
database tagging, and for rewriting the tags on the screen). I'll play
with both and see which is clearer.

Best,
Jesse


Re: [notmuch] [PATCH v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-04-09 Thread Jesse Rosenthal
On Wed, 07 Apr 2010 14:10:38 -0700, Carl Worth  wrote:
> On Tue, 16 Feb 2010 19:07:40 -0500, Jesse Rosenthal  
> wrote:
> I think this feature is very useful, and that the region is definitely
> an appropriate way to implement it, (doing region-based operations is
> very natural for emacs users). Mutt-style marking could be implemented
> as well, but that would be separate I think.

Great -- never sure if my intuitive use corresponds with that of others.

> I also don't like the duplication of code in
> notmuch-search-add-tag-thread and notmuch-search-add-tag-region, (and
> the same in the remove case). Fortunately, I think this easy to avoid by
> simply making notmuch-search-add-tag-thread call:
> 
>(notmuch-search-add-tag-region tag (point) (point))
> 
> and the same in the remove case.

Good idea.

> 
> But I haven't pushed this patch yet for a flaw in the case of selecting
> beyond the last thread, (such as selecting to the line that includes the
> "End of search results). If I try an operation on that line, it will act
> like it works, (it displays the new tags by all threads), but then a
> refresh makes them all disappear again. Presumably the "notmuch tag"
> command is failing, this isn't being noticed, and the code marches on to
> update the representation of the tags.

Good point, and shouldn't be too hard to fix. It seems like it could be
done either (a) at the lisp level (filtering out the blank entries), or
(b) at the literal buffer level (having a step that sets point-max for
the region appropriately). The choice (a) seems clearer in an abstract
way, but has the downside of needing to be repeated twice (both for
database tagging, and for rewriting the tags on the screen). I'll play
with both and see which is clearer.

Best,
Jesse
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] [PATCH v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-04-07 Thread Carl Worth
On Tue, 16 Feb 2010 19:07:40 -0500, Jesse Rosenthal  wrote:
> This patch adds `-region' versions of the `notmuch-search-' commands to find
> properties. It also splits up  `notmuch-add/remove-tags' into both a
> `-thread' and a `-region' version. (This makes us modify
> `notmuch-search-archive-thread' to use the
> `notmuch-search-remove-tag-thread' function, instead of
> `notmuch-search-remove-tag', for consistency.) The add/remove-tag command
> called by pressing `+' or `-' will then choose accordingly, based on whether
> region is active.
> 
> This version fixes a couple of errors in the first version, which led to
> incorrect marking of some tags in the search view (though the actual
> tagging was still correct). It's also based on current master.
> 
> I'm not sure any more if region selection is actually the correct way to
> do this, or if a mutt-style message-marking method would be better. But
> I didn't want a buggy incorrect version out there.

I think this feature is very useful, and that the region is definitely
an appropriate way to implement it, (doing region-based operations is
very natural for emacs users). Mutt-style marking could be implemented
as well, but that would be separate I think.

I tested this patch a bit and added one small cleanup to the
documentation (see below).

I also don't like the duplication of code in
notmuch-search-add-tag-thread and notmuch-search-add-tag-region, (and
the same in the remove case). Fortunately, I think this easy to avoid by
simply making notmuch-search-add-tag-thread call:

   (notmuch-search-add-tag-region tag (point) (point))

and the same in the remove case.

But I haven't pushed this patch yet for a flaw in the case of selecting
beyond the last thread, (such as selecting to the line that includes the
"End of search results). If I try an operation on that line, it will act
like it works, (it displays the new tags by all threads), but then a
refresh makes them all disappear again. Presumably the "notmuch tag"
command is failing, this isn't being noticed, and the code marches on to
update the representation of the tags.

And presumably the notmuch tag is failing because no thread ID is found
for the last line, so the mapconcat call is sticking an extra " or "
onto the end of the search string. And Xapian doesn't like that:

$ notmuch search tag:inbox or
A Xapian exception occurred performing query: Syntax:  OR 

Query string was: tag:inbox or

Things behave even worse if I make the region be the entire buffer,
(including the last blank line). Then the commands hang. I got nervous
that this was then adding "or or" and trying to add/remove a tag to
every message containing the word "or". But I haven't looked closely.

If we can fix this bug, then I'd like to apply this patch. I'd even like
to fix the "*" binding to be implemented in terms of something like
these functions so that we could get visual updates of the tag state
From that command. (But that will take some reworking of the interface
as the current implementation can't support multiple tags added/removed
as * current expects).

I'd appreciate any help fixing up the patch.

-Carl

From fec5622add1a4e9f305c16e96143439ee22a5c58 Mon Sep 17 00:00:00 2001
From: Carl Worth 
Date: Wed, 7 Apr 2010 13:15:27 -0700
Subject: [PATCH] emacs: Correct the documentation for notmuch-search-add-tag 
(and -remove-tag)

These commands act on all messages in the thread, not simply those
that match the search. (There are use case for both behaviors, but the
documentation must match the behavior that's actually implemented).
---
 emacs/notmuch.el |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 64f3e3d..517c53a 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -532,12 +532,11 @@ and will also appear in a buffer named \"*Notmuch 
errors*\"."
  (notmuch-search-set-tags (delete tag (notmuch-search-get-tags)))
  (forward-line))
 
-
 (defun notmuch-search-add-tag (tag)
   "Add a tag to the currently selected thread or region.
 
-The tag is added to messages in the currently selected thread or
-region which match the current search terms."
+The tag is added to all messages in the currently selected thread
+or threads in the current region."
   (interactive
(list (notmuch-select-tag-with-completion "Tag to add: ")))
   (save-excursion
@@ -550,8 +549,8 @@ region which match the current search terms."
 (defun notmuch-search-remove-tag (tag)
   "Remove a tag from the currently selected thread or region.
 
-The tag is removed from all messages in the currently selected thread
-or region which match the current search terms."
+The tag is removed from all messages in the currently selected
+thread or threads in the current region."
   (interactive
(list (notmuch-select-tag-with-completion
  "Tag to remove: "
-- 
1.7.0



pgp41vW41l44Q.pgp
Description: PGP signature
_

[notmuch] [PATCH v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-04-07 Thread Carl Worth
On Tue, 16 Feb 2010 19:07:40 -0500, Jesse Rosenthal  
wrote:
> This patch adds `-region' versions of the `notmuch-search-' commands to find
> properties. It also splits up  `notmuch-add/remove-tags' into both a
> `-thread' and a `-region' version. (This makes us modify
> `notmuch-search-archive-thread' to use the
> `notmuch-search-remove-tag-thread' function, instead of
> `notmuch-search-remove-tag', for consistency.) The add/remove-tag command
> called by pressing `+' or `-' will then choose accordingly, based on whether
> region is active.
> 
> This version fixes a couple of errors in the first version, which led to
> incorrect marking of some tags in the search view (though the actual
> tagging was still correct). It's also based on current master.
> 
> I'm not sure any more if region selection is actually the correct way to
> do this, or if a mutt-style message-marking method would be better. But
> I didn't want a buggy incorrect version out there.

I think this feature is very useful, and that the region is definitely
an appropriate way to implement it, (doing region-based operations is
very natural for emacs users). Mutt-style marking could be implemented
as well, but that would be separate I think.

I tested this patch a bit and added one small cleanup to the
documentation (see below).

I also don't like the duplication of code in
notmuch-search-add-tag-thread and notmuch-search-add-tag-region, (and
the same in the remove case). Fortunately, I think this easy to avoid by
simply making notmuch-search-add-tag-thread call:

   (notmuch-search-add-tag-region tag (point) (point))

and the same in the remove case.

But I haven't pushed this patch yet for a flaw in the case of selecting
beyond the last thread, (such as selecting to the line that includes the
"End of search results). If I try an operation on that line, it will act
like it works, (it displays the new tags by all threads), but then a
refresh makes them all disappear again. Presumably the "notmuch tag"
command is failing, this isn't being noticed, and the code marches on to
update the representation of the tags.

And presumably the notmuch tag is failing because no thread ID is found
for the last line, so the mapconcat call is sticking an extra " or "
onto the end of the search string. And Xapian doesn't like that:

$ notmuch search tag:inbox or
A Xapian exception occurred performing query: Syntax:  OR 

Query string was: tag:inbox or

Things behave even worse if I make the region be the entire buffer,
(including the last blank line). Then the commands hang. I got nervous
that this was then adding "or or" and trying to add/remove a tag to
every message containing the word "or". But I haven't looked closely.

If we can fix this bug, then I'd like to apply this patch. I'd even like
to fix the "*" binding to be implemented in terms of something like
these functions so that we could get visual updates of the tag state


[notmuch] [PATCH v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-02-16 Thread Jesse Rosenthal
This patch adds `-region' versions of the `notmuch-search-' commands to find
properties. It also splits up  `notmuch-add/remove-tags' into both a
`-thread' and a `-region' version. (This makes us modify
`notmuch-search-archive-thread' to use the
`notmuch-search-remove-tag-thread' function, instead of
`notmuch-search-remove-tag', for consistency.) The add/remove-tag command
called by pressing `+' or `-' will then choose accordingly, based on whether
region is active.

This version fixes a couple of errors in the first version, which led to
incorrect marking of some tags in the search view (though the actual
tagging was still correct). It's also based on current master.

I'm not sure any more if region selection is actually the correct way to
do this, or if a mutt-style message-marking method would be better. But
I didn't want a buggy incorrect version out there.
---
 notmuch.el |   98 +---
 1 files changed, 87 insertions(+), 11 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 0f4ea10..7d9a82f 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -1227,18 +1227,41 @@ Complete list of currently available key bindings:
   (set (make-local-variable 'font-lock-defaults)
  '(notmuch-search-font-lock-keywords t)))

+(defun notmuch-search-properties-in-region (property beg end)
+  (save-excursion
+(let ((output nil)
+ (last-line (line-number-at-pos end)))
+  (goto-char beg)
+  (beginning-of-line)
+  (while (<= (line-number-at-pos) last-line)
+   (setq output (cons (get-text-property (point) property) output))
+   (forward-line 1))
+  output)))
+
 (defun notmuch-search-find-thread-id ()
   "Return the thread for the current thread"
   (get-text-property (point) 'notmuch-search-thread-id))

+(defun notmuch-search-find-thread-id-region (beg end)
+  "Return a list of threads for the current region"
+  (notmuch-search-properties-in-region 'notmuch-search-thread-id beg end))
+
 (defun notmuch-search-find-authors ()
   "Return the authors for the current thread"
   (get-text-property (point) 'notmuch-search-authors))

+(defun notmuch-search-find-authors-region (beg end)
+  "Return a list of authors for the current region"
+  (notmuch-search-properties-in-region 'notmuch-search-authors beg end))
+
 (defun notmuch-search-find-subject ()
   "Return the subject for the current thread"
   (get-text-property (point) 'notmuch-search-subject))

+(defun notmuch-search-find-subject-region (beg end)
+  "Return a list of authors for the current region"
+  (notmuch-search-properties-in-region 'notmuch-search-subject beg end))
+
 (defun notmuch-search-show-thread ()
   "Display the currently selected thread."
   (interactive)
@@ -1292,32 +1315,85 @@ and will also appear in a buffer named \"*Notmuch 
errors*\"."
   (let ((end (- (point) 1)))
(split-string (buffer-substring beg end))

+(defun notmuch-search-get-tags-region (beg end)
+  (save-excursion
+(let ((output nil)
+ (last-line (line-number-at-pos end)))
+  (goto-char beg)
+  (while (<= (line-number-at-pos) last-line)
+   (setq output (append output (notmuch-search-get-tags)))
+   (forward-line 1))
+  output)))
+
+(defun notmuch-search-add-tag-thread (tag)
+  (notmuch-call-notmuch-process "tag" (concat "+" tag) 
(notmuch-search-find-thread-id))
+  (notmuch-search-set-tags (delete-dups (sort (cons tag 
(notmuch-search-get-tags)) 'string<
+
+(defun notmuch-search-add-tag-region (tag beg end)
+  (let ((search-id-string (mapconcat 'identity 
(notmuch-search-find-thread-id-region beg end) " or ")))
+(notmuch-call-notmuch-process "tag" (concat "+" tag) search-id-string)
+(save-excursion
+  (let ((last-line (line-number-at-pos end)))
+   (goto-char beg)
+   (while (<= (line-number-at-pos) last-line)
+ (notmuch-search-set-tags (delete-dups (sort (cons tag 
(notmuch-search-get-tags)) 'string<)))
+ (forward-line))
+
+(defun notmuch-search-remove-tag-thread (tag)
+  (notmuch-call-notmuch-process "tag" (concat "-" tag) 
(notmuch-search-find-thread-id))
+  (notmuch-search-set-tags (delete tag (notmuch-search-get-tags
+
+(defun notmuch-search-remove-tag-region (tag beg end)
+  (let ((search-id-string (mapconcat 'identity 
(notmuch-search-find-thread-id-region beg end) " or ")))
+(notmuch-call-notmuch-process "tag" (concat "-" tag) search-id-string)
+(save-excursion
+  (let ((last-line (line-number-at-pos end)))
+   (goto-char beg)
+   (while (<= (line-number-at-pos) last-line)
+ (notmuch-search-set-tags (delete tag (notmuch-search-get-tags)))
+ (forward-line))
+
+
 (defun notmuch-search-add-tag (tag)
-  "Add a tag to the currently selected thread.
+  "Add a tag to the currently selected thread or region.

-The tag is added to messages in the currently selected thread
-which match the current search terms."
+The tag is added to messages in the currently selected thre

[notmuch] [PATCH v2] notmuch.el: add functionality in notmuch search mode to add or remove tags by region

2010-02-16 Thread Jesse Rosenthal
This patch adds `-region' versions of the `notmuch-search-' commands to find
properties. It also splits up  `notmuch-add/remove-tags' into both a
`-thread' and a `-region' version. (This makes us modify
`notmuch-search-archive-thread' to use the
`notmuch-search-remove-tag-thread' function, instead of
`notmuch-search-remove-tag', for consistency.) The add/remove-tag command
called by pressing `+' or `-' will then choose accordingly, based on whether
region is active.

This version fixes a couple of errors in the first version, which led to
incorrect marking of some tags in the search view (though the actual
tagging was still correct). It's also based on current master.

I'm not sure any more if region selection is actually the correct way to
do this, or if a mutt-style message-marking method would be better. But
I didn't want a buggy incorrect version out there.
---
 notmuch.el |   98 +---
 1 files changed, 87 insertions(+), 11 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 0f4ea10..7d9a82f 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -1227,18 +1227,41 @@ Complete list of currently available key bindings:
   (set (make-local-variable 'font-lock-defaults)
  '(notmuch-search-font-lock-keywords t)))
 
+(defun notmuch-search-properties-in-region (property beg end)
+  (save-excursion
+(let ((output nil)
+ (last-line (line-number-at-pos end)))
+  (goto-char beg)
+  (beginning-of-line)
+  (while (<= (line-number-at-pos) last-line)
+   (setq output (cons (get-text-property (point) property) output))
+   (forward-line 1))
+  output)))
+
 (defun notmuch-search-find-thread-id ()
   "Return the thread for the current thread"
   (get-text-property (point) 'notmuch-search-thread-id))
 
+(defun notmuch-search-find-thread-id-region (beg end)
+  "Return a list of threads for the current region"
+  (notmuch-search-properties-in-region 'notmuch-search-thread-id beg end))
+
 (defun notmuch-search-find-authors ()
   "Return the authors for the current thread"
   (get-text-property (point) 'notmuch-search-authors))
 
+(defun notmuch-search-find-authors-region (beg end)
+  "Return a list of authors for the current region"
+  (notmuch-search-properties-in-region 'notmuch-search-authors beg end))
+
 (defun notmuch-search-find-subject ()
   "Return the subject for the current thread"
   (get-text-property (point) 'notmuch-search-subject))
 
+(defun notmuch-search-find-subject-region (beg end)
+  "Return a list of authors for the current region"
+  (notmuch-search-properties-in-region 'notmuch-search-subject beg end))
+
 (defun notmuch-search-show-thread ()
   "Display the currently selected thread."
   (interactive)
@@ -1292,32 +1315,85 @@ and will also appear in a buffer named \"*Notmuch 
errors*\"."
   (let ((end (- (point) 1)))
(split-string (buffer-substring beg end))
 
+(defun notmuch-search-get-tags-region (beg end)
+  (save-excursion
+(let ((output nil)
+ (last-line (line-number-at-pos end)))
+  (goto-char beg)
+  (while (<= (line-number-at-pos) last-line)
+   (setq output (append output (notmuch-search-get-tags)))
+   (forward-line 1))
+  output)))
+
+(defun notmuch-search-add-tag-thread (tag)
+  (notmuch-call-notmuch-process "tag" (concat "+" tag) 
(notmuch-search-find-thread-id))
+  (notmuch-search-set-tags (delete-dups (sort (cons tag 
(notmuch-search-get-tags)) 'string<
+
+(defun notmuch-search-add-tag-region (tag beg end)
+  (let ((search-id-string (mapconcat 'identity 
(notmuch-search-find-thread-id-region beg end) " or ")))
+(notmuch-call-notmuch-process "tag" (concat "+" tag) search-id-string)
+(save-excursion
+  (let ((last-line (line-number-at-pos end)))
+   (goto-char beg)
+   (while (<= (line-number-at-pos) last-line)
+ (notmuch-search-set-tags (delete-dups (sort (cons tag 
(notmuch-search-get-tags)) 'string<)))
+ (forward-line))
+
+(defun notmuch-search-remove-tag-thread (tag)
+  (notmuch-call-notmuch-process "tag" (concat "-" tag) 
(notmuch-search-find-thread-id))
+  (notmuch-search-set-tags (delete tag (notmuch-search-get-tags
+
+(defun notmuch-search-remove-tag-region (tag beg end)
+  (let ((search-id-string (mapconcat 'identity 
(notmuch-search-find-thread-id-region beg end) " or ")))
+(notmuch-call-notmuch-process "tag" (concat "-" tag) search-id-string)
+(save-excursion
+  (let ((last-line (line-number-at-pos end)))
+   (goto-char beg)
+   (while (<= (line-number-at-pos) last-line)
+ (notmuch-search-set-tags (delete tag (notmuch-search-get-tags)))
+ (forward-line))
+
+
 (defun notmuch-search-add-tag (tag)
-  "Add a tag to the currently selected thread.
+  "Add a tag to the currently selected thread or region.
 
-The tag is added to messages in the currently selected thread
-which match the current search terms."
+The tag is added to messages in the currently selecte