]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch.el
emacs: accept empty tag list in `notmuch-tag'
[notmuch] / emacs / notmuch.el
index 1b472dd2305fd026027a496b326b704667b34829..0ffdf9cb460e4cfed6221b1dcf8bba819cd07747 100644 (file)
@@ -76,6 +76,14 @@ For example:
 (defvar notmuch-query-history nil
   "Variable to store minibuffer history for notmuch queries")
 
+(defvar notmuch-select-tag-history nil
+  "Variable to store minibuffer history for
+`notmuch-select-tag-with-completion' function.")
+
+(defvar notmuch-read-tag-changes-history nil
+  "Variable to store minibuffer history for
+`notmuch-read-tag-changes' function.")
+
 (defun notmuch-tag-completions (&optional search-terms)
   (split-string
    (with-output-to-string
@@ -86,7 +94,7 @@ For example:
 
 (defun notmuch-select-tag-with-completion (prompt &rest search-terms)
   (let ((tag-list (notmuch-tag-completions search-terms)))
-    (completing-read prompt tag-list)))
+    (completing-read prompt tag-list nil nil nil 'notmuch-select-tag-history)))
 
 (defun notmuch-read-tag-changes (&optional initial-input &rest search-terms)
   (let* ((all-tag-list (notmuch-tag-completions))
@@ -106,7 +114,8 @@ For example:
            (define-key map " " 'self-insert-command)
            map)))
     (delete "" (completing-read-multiple "Tags (+add -drop): "
-               tag-list nil nil initial-input))))
+               tag-list nil nil initial-input
+               'notmuch-read-tag-changes-history))))
 
 (defun notmuch-update-tags (tags tag-changes)
   "Return a copy of TAGS with additions and removals from TAG-CHANGES.
@@ -270,7 +279,7 @@ For a mouse binding, return nil."
     (define-key map "t" 'notmuch-search-filter-by-tag)
     (define-key map "f" 'notmuch-search-filter)
     (define-key map [mouse-1] 'notmuch-search-show-thread)
-    (define-key map "*" 'notmuch-search-operate-all)
+    (define-key map "*" 'notmuch-search-tag-all)
     (define-key map "a" 'notmuch-search-archive-thread)
     (define-key map "-" 'notmuch-search-remove-tag)
     (define-key map "+" 'notmuch-search-add-tag)
@@ -419,7 +428,7 @@ any tags).
 Pressing \\[notmuch-search-show-thread] on any line displays that thread. The '\\[notmuch-search-add-tag]' and '\\[notmuch-search-remove-tag]'
 keys can be used to add or remove tags from a thread. The '\\[notmuch-search-archive-thread]' key
 is a convenience for archiving a thread (removing the \"inbox\"
-tag). The '\\[notmuch-search-operate-all]' key can be used to add or remove a tag from all
+tag). The '\\[notmuch-search-tag-all]' key can be used to add or remove a tag from all
 threads in the current buffer.
 
 Other useful commands are '\\[notmuch-search-filter]' for filtering the current search
@@ -539,15 +548,15 @@ messages instead of running (notmuch-call-notmuch-process \"tag\" ..)
 directly, so that hooks specified in notmuch-before-tag-hook and
 notmuch-after-tag-hook will be run."
   ;; Perform some validation
-  (when (null tags) (error "No tags given"))
   (mapc (lambda (tag)
-         (unless (string-match-p "^[-+][-+_.[:word:]]+$" tag)
+         (unless (string-match-p "^[-+]\\S-+$" tag)
            (error "Tag must be of the form `+this_tag' or `-that_tag'")))
        tags)
-  (run-hooks 'notmuch-before-tag-hook)
-  (apply 'notmuch-call-notmuch-process
-        (append (list "tag") tags (list "--" query)))
-  (run-hooks 'notmuch-after-tag-hook))
+  (unless (null tags)
+    (run-hooks 'notmuch-before-tag-hook)
+    (apply 'notmuch-call-notmuch-process "tag"
+          (append tags (list "--" query)))
+    (run-hooks 'notmuch-after-tag-hook)))
 
 (defcustom notmuch-before-tag-hook nil
   "Hooks that are run before tags of a message are modified.
@@ -876,7 +885,7 @@ non-authors is found, assume that all of the authors match."
              (goto-char found-target)))
       (delete-process proc))))
 
-(defun notmuch-search-operate-all (&rest actions)
+(defun notmuch-search-tag-all (&rest actions)
   "Add/remove tags from all matching messages.
 
 This command adds or removes tags from all messages matching the