unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/5] emacs: make tab completion use visible tags
@ 2012-11-30  8:21 Mark Walters
  2012-11-30  8:21 ` [PATCH 1/5] emacs: move tag.el utility functions from lists to strings Mark Walters
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Mark Walters @ 2012-11-30  8:21 UTC (permalink / raw)
  To: notmuch

Currently when doing tab completion emacs queries the database and
completes to any tag when adding but only completes to tags that are
present in the message/thread/region when removing. However, since it
queries the database it does this based on the current tags in the
database not the current tags shown in the search view.

This means that tag completion is not predictable and this seems
undesirable. This series modifies it so that the tag caller can
specify the possible completions (typically based on the tags that it
believes are present). This means that the user know that -un<tab>
will complete to -unread if he can see unread in the messages
tags. (unread is a common stale tag as when you quit from a show
buffer back to the search buffer the unread has often been removed).

One side effect is that it solves the `large search' problem when
doing tag completion on the very large queries that will be generated
by the move to tagging by message-id rather than thread-id.
id:1353763256-32336-1-git-send-email-markwalters1009@gmail.com
(The tagging can use the batch tagging when that goes in).

I think this makes the user interface more predictable/consistent but
whether it is worth the change is less clear.

Best wishes

Mark

markwalters1009 (5):
  emacs: move tag.el utility functions from lists to strings
  emacs: allow the tag caller to specify possible completions.
  emacs: notmuch.el remove duplicate tags from get-tags-region
  emacs: make search tag completion use the tags it believes are there
  emacs: show tag completion

 emacs/notmuch-show.el |   32 +++++++++++++++++++++++++-------
 emacs/notmuch-tag.el  |   38 +++++++++++++++++++++++++++-----------
 emacs/notmuch.el      |   10 ++++++----
 3 files changed, 58 insertions(+), 22 deletions(-)

-- 
1.7.9.1

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

* [PATCH 1/5] emacs: move tag.el utility functions from lists to strings
  2012-11-30  8:21 [PATCH 0/5] emacs: make tab completion use visible tags Mark Walters
@ 2012-11-30  8:21 ` Mark Walters
  2012-11-30  8:21 ` [PATCH 2/5] emacs: allow the tag caller to specify possible completions Mark Walters
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-11-30  8:21 UTC (permalink / raw)
  To: notmuch

From: markwalters1009 <markwalters1009@gmail.com>

The query for most of the notmuch-tag.el utility functions was a list
(or multiple arguments) (but not for the main calling point:
notmuch-tag). This patch moves them all to take the query as a string
instead. This makes it easier to add extra parameters in the next
patch.
---
 emacs/notmuch-tag.el |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 4fce3a9..1f3d8cf 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -55,26 +55,26 @@ the messages that were tagged"
 `notmuch-read-tag-changes' function.")
 
 (defun notmuch-tag-completions (&optional search-terms)
-  (if (null search-terms)
-      (setq search-terms (list "*")))
+  (unless search-terms
+    (setq search-terms "*"))
   (split-string
    (with-output-to-string
      (with-current-buffer standard-output
-       (apply 'call-process notmuch-command nil t
+       (funcall 'call-process notmuch-command nil t
 	      nil "search" "--output=tags" "--exclude=false" search-terms)))
    "\n+" t))
 
-(defun notmuch-select-tag-with-completion (prompt &rest search-terms)
+(defun notmuch-select-tag-with-completion (prompt &optional search-terms)
   (let ((tag-list (notmuch-tag-completions search-terms)))
     (completing-read prompt tag-list nil nil nil 'notmuch-select-tag-history)))
 
-(defun notmuch-read-tag-changes (&optional initial-input &rest search-terms)
+(defun notmuch-read-tag-changes (&optional initial-input search-terms)
   (let* ((all-tag-list (notmuch-tag-completions))
 	 (add-tag-list (mapcar (apply-partially 'concat "+") all-tag-list))
 	 (remove-tag-list (mapcar (apply-partially 'concat "-")
-				  (if (null search-terms)
-				      all-tag-list
-				    (notmuch-tag-completions search-terms))))
+				  (if search-terms
+				      (notmuch-tag-completions search-terms)
+				    all-tag-list)))
 	 (tag-list (append add-tag-list remove-tag-list))
 	 (crm-separator " ")
 	 ;; By default, space is bound to "complete word" function.
-- 
1.7.9.1

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

* [PATCH 2/5] emacs: allow the tag caller to specify possible completions.
  2012-11-30  8:21 [PATCH 0/5] emacs: make tab completion use visible tags Mark Walters
  2012-11-30  8:21 ` [PATCH 1/5] emacs: move tag.el utility functions from lists to strings Mark Walters
@ 2012-11-30  8:21 ` Mark Walters
  2012-11-30  8:21 ` [PATCH 3/5] emacs: notmuch.el remove duplicate tags from get-tags-region Mark Walters
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-11-30  8:21 UTC (permalink / raw)
  To: notmuch

From: markwalters1009 <markwalters1009@gmail.com>

Previously notmuch tag would always query the database for possible
tag completions (allowing all tags for + but only tags present in the
messages being tagged for -). This allows the caller so specify these
completion lists.
---
 emacs/notmuch-tag.el |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 1f3d8cf..c8508d1 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -68,13 +68,18 @@ the messages that were tagged"
   (let ((tag-list (notmuch-tag-completions search-terms)))
     (completing-read prompt tag-list nil nil nil 'notmuch-select-tag-history)))
 
-(defun notmuch-read-tag-changes (&optional initial-input search-terms)
+(defun notmuch-read-tag-changes (&optional initial-input
+					   search-terms
+					   negative-completions
+					   positive-completions)
   (let* ((all-tag-list (notmuch-tag-completions))
-	 (add-tag-list (mapcar (apply-partially 'concat "+") all-tag-list))
+	 (add-tag-list (mapcar (apply-partially 'concat "+")
+			       (or positive-completions all-tag-list)))
 	 (remove-tag-list (mapcar (apply-partially 'concat "-")
-				  (if search-terms
-				      (notmuch-tag-completions search-terms)
-				    all-tag-list)))
+				  (or negative-completions
+				      (if search-terms
+					  (notmuch-tag-completions search-terms)
+					all-tag-list))))
 	 (tag-list (append add-tag-list remove-tag-list))
 	 (crm-separator " ")
 	 ;; By default, space is bound to "complete word" function.
@@ -108,7 +113,7 @@ from TAGS if present."
 	   (error "Changed tag must be of the form `+this_tag' or `-that_tag'")))))
     (sort result-tags 'string<)))
 
-(defun notmuch-tag (query &optional tag-changes)
+(defun notmuch-tag (query &optional tag-changes negative-completions positive-completions)
   "Add/remove tags in TAG-CHANGES to messages matching QUERY.
 
 QUERY should be a string containing the search-terms.
@@ -119,6 +124,14 @@ interpreted as a single tag change.  If TAG-CHANGES is the string
 \"-\" or \"+\", or null, then the user is prompted to enter the
 tag changes.
 
+NEGATIVE-COMPLETIONS and POSITIVE-COMPLETIONS should be lists of
+tags that should be used for tab-completion for
+removal (i.e. after a \"-\") and addition (i.e. after a
+\"+\") repectively. If either of these is nil the possible
+completions will be read from the notmuch database. This does not
+stop the removal or addition of a tag; it just changes which tags
+can be tag-completed.
+
 Note: Other code should always use this function alter tags of
 messages instead of running (notmuch-call-notmuch-process \"tag\" ..)
 directly, so that hooks specified in notmuch-before-tag-hook and
@@ -126,7 +139,10 @@ notmuch-after-tag-hook will be run."
   ;; Perform some validation
   (if (string-or-null-p tag-changes)
       (if (or (string= tag-changes "-") (string= tag-changes "+") (null tag-changes))
-	  (setq tag-changes (notmuch-read-tag-changes tag-changes query))
+	  (setq tag-changes (notmuch-read-tag-changes tag-changes
+						      query
+						      negative-completions
+						      positive-completions))
 	(setq tag-changes (list tag-changes))))
   (mapc (lambda (tag-change)
 	  (unless (string-match-p "^[-+]\\S-+$" tag-change)
-- 
1.7.9.1

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

* [PATCH 3/5] emacs: notmuch.el remove duplicate tags from get-tags-region
  2012-11-30  8:21 [PATCH 0/5] emacs: make tab completion use visible tags Mark Walters
  2012-11-30  8:21 ` [PATCH 1/5] emacs: move tag.el utility functions from lists to strings Mark Walters
  2012-11-30  8:21 ` [PATCH 2/5] emacs: allow the tag caller to specify possible completions Mark Walters
@ 2012-11-30  8:21 ` Mark Walters
  2012-11-30  8:21 ` [PATCH 4/5] emacs: make search tag completion use the tags it believes are there Mark Walters
  2012-11-30  8:21 ` [PATCH 5/5] emacs: show tag completion Mark Walters
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-11-30  8:21 UTC (permalink / raw)
  To: notmuch

From: markwalters1009 <markwalters1009@gmail.com>

get-tags-region used to return a list of all tags of all messages with
tags appearing multiple times. This changes it to return a list where
each tag appears at most once. As far as I can see there were no
callers of the old function (but this series adds one!).
---
 emacs/notmuch.el |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index f9454d8..4e6bbcf 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -558,10 +558,11 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
   (plist-get (notmuch-search-get-result pos) :tags))
 
 (defun notmuch-search-get-tags-region (beg end)
-  (let (output)
+  (let ((output '()))
     (notmuch-search-foreach-result beg end
       (lambda (pos)
-	(setq output (append output (notmuch-search-get-tags pos)))))
+	(mapc (lambda (tag) (add-to-list 'output tag))
+	      (notmuch-search-get-tags pos))))
     output))
 
 (defun notmuch-search-tag-region (beg end &optional tag-changes)
-- 
1.7.9.1

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

* [PATCH 4/5] emacs: make search tag completion use the tags it believes are there
  2012-11-30  8:21 [PATCH 0/5] emacs: make tab completion use visible tags Mark Walters
                   ` (2 preceding siblings ...)
  2012-11-30  8:21 ` [PATCH 3/5] emacs: notmuch.el remove duplicate tags from get-tags-region Mark Walters
@ 2012-11-30  8:21 ` Mark Walters
  2012-11-30  8:21 ` [PATCH 5/5] emacs: show tag completion Mark Walters
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-11-30  8:21 UTC (permalink / raw)
  To: notmuch

From: markwalters1009 <markwalters1009@gmail.com>

Tagging from search mode now passes the tags it believes are present
to the completion function. This means that the user interface is more
consistent: tag-completion will complete to any tag the user can see
(even if it is no longer present).
---
 emacs/notmuch.el |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 4e6bbcf..4ffa803 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -567,8 +567,9 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
 
 (defun notmuch-search-tag-region (beg end &optional tag-changes)
   "Change tags for threads in the given region."
-  (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))
-    (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))
+  (let ((search-string (notmuch-search-find-thread-id-region-search beg end))
+	(current-tags (notmuch-search-get-tags-region beg end)))
+    (setq tag-changes (funcall 'notmuch-tag search-string tag-changes current-tags))
     (notmuch-search-foreach-result beg end
       (lambda (pos)
 	(notmuch-search-set-tags
-- 
1.7.9.1

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

* [PATCH 5/5] emacs: show tag completion
  2012-11-30  8:21 [PATCH 0/5] emacs: make tab completion use visible tags Mark Walters
                   ` (3 preceding siblings ...)
  2012-11-30  8:21 ` [PATCH 4/5] emacs: make search tag completion use the tags it believes are there Mark Walters
@ 2012-11-30  8:21 ` Mark Walters
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-11-30  8:21 UTC (permalink / raw)
  To: notmuch

From: markwalters1009 <markwalters1009@gmail.com>

This makes tagging in show mode pass the list of tags that it believes
occur to the tag completion function. This means that tag-completion
will complete to any tag that the user can see (even if it is no
longer present).
---
The function to get all tags for a thread was taken from Damien's
notmuch-labeler series.

 emacs/notmuch-show.el |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 489e32c..c2fef7b 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1439,6 +1439,16 @@ current thread."
   "Return the tags of the current message."
   (notmuch-show-get-prop :tags))
 
+(defun notmuch-show-thread-tags ()
+  "Return the list of tags for the current thread."
+  (let ((tags (list)))
+    (notmuch-show-mapc (lambda ()
+			 (mapcar (lambda (elt)
+				   ;; Avoid adding duplicate tags
+				   (add-to-list 'tags elt))
+				 (notmuch-show-get-tags))))
+    tags))
+
 (defun notmuch-show-message-visible-p ()
   "Is the current message visible?"
   (notmuch-show-get-prop :message-visible))
@@ -1730,9 +1740,13 @@ TAG-CHANGES is a list of tag operations for `notmuch-tag'."
 
 See `notmuch-tag' for information on the format of TAG-CHANGES."
   (interactive)
-  (setq tag-changes (funcall 'notmuch-tag (notmuch-show-get-message-id) tag-changes))
-  (let* ((current-tags (notmuch-show-get-tags))
-	 (new-tags (notmuch-update-tags current-tags tag-changes)))
+  (let ((current-tags (notmuch-show-get-tags))
+	(new-tags))
+    (setq tag-changes (funcall 'notmuch-tag
+			       (notmuch-show-get-message-id)
+			       tag-changes
+			       current-tags))
+    (setq new-tags (notmuch-update-tags current-tags tag-changes))
     (unless (equal current-tags new-tags)
       (notmuch-show-set-tags new-tags))))
 
@@ -1741,13 +1755,17 @@ See `notmuch-tag' for information on the format of TAG-CHANGES."
 
 See `notmuch-tag' for information on the format of TAG-CHANGES."
   (interactive)
-  (setq tag-changes (funcall 'notmuch-tag (notmuch-show-get-messages-ids-search) tag-changes))
-  (notmuch-show-mapc
-   (lambda ()
+  (let ((existing-tags (notmuch-show-thread-tags)))
+    (setq tag-changes (funcall 'notmuch-tag
+			       (notmuch-show-get-messages-ids-search)
+			       tag-changes
+			       existing-tags))
+    (notmuch-show-mapc
+     (lambda ()
      (let* ((current-tags (notmuch-show-get-tags))
 	    (new-tags (notmuch-update-tags current-tags tag-changes)))
        (unless (equal current-tags new-tags)
-	 (notmuch-show-set-tags new-tags))))))
+	 (notmuch-show-set-tags new-tags)))))))
 
 (defun notmuch-show-add-tag ()
   "Same as `notmuch-show-tag' but sets initial input to '+'."
-- 
1.7.9.1

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

end of thread, other threads:[~2012-11-30  8:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-30  8:21 [PATCH 0/5] emacs: make tab completion use visible tags Mark Walters
2012-11-30  8:21 ` [PATCH 1/5] emacs: move tag.el utility functions from lists to strings Mark Walters
2012-11-30  8:21 ` [PATCH 2/5] emacs: allow the tag caller to specify possible completions Mark Walters
2012-11-30  8:21 ` [PATCH 3/5] emacs: notmuch.el remove duplicate tags from get-tags-region Mark Walters
2012-11-30  8:21 ` [PATCH 4/5] emacs: make search tag completion use the tags it believes are there Mark Walters
2012-11-30  8:21 ` [PATCH 5/5] emacs: show tag completion Mark Walters

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