From: markwalters1009 <[email protected]>

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

Reply via email to