]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: make sure tagging on an empty query is harmless
authorMark Walters <markwalters1009@gmail.com>
Wed, 21 May 2014 09:58:50 +0000 (10:58 +0100)
committerDavid Bremner <david@tethera.net>
Tue, 27 May 2014 23:40:04 +0000 (20:40 -0300)
Currently notmuch-tag throws a "wrong-type-argument stringp nil" if
passed a nil query-string. Catch this and provide a more useful error
message. This fixes a case in notmuch-tree (if you try to tag when at
the end of the buffer).

Secondly, as pointed out by David (dme)
`notmuch-search-find-stable-query-region' can return the query string
() if there are no messages in the region. This gets passed to notmuch
tag, and due to interactions in the optimize_query code in
notmuch-tag.c becomes, in the case tag-change is -inbox, "( () ) and
(tag:inbox)". This query matches some strange collection of messages
which then get archived. This should probably be fixed, but in any
case make `notmuch-search-find-stable-query-region' return a nil
query-string in this case.

This avoids data-loss (random tag removal) in this case.

emacs/notmuch-tag.el
emacs/notmuch.el

index 07c260ebbd07e13e23ce6524d1a5fdc9368ca481..f54aa9d69ef8d440a2e81756fd570ab32a96a2d8 100644 (file)
@@ -387,6 +387,8 @@ notmuch-after-tag-hook will be run."
          (unless (string-match-p "^[-+]\\S-+$" tag-change)
            (error "Tag must be of the form `+this_tag' or `-that_tag'")))
        tag-changes)
+  (unless query
+    (error "Nothing to tag!"))
   (unless (null tag-changes)
     (run-hooks 'notmuch-before-tag-hook)
     (if (<= (length query) notmuch-tag-argument-limit)
index 6c0bc1bcae0ed9e3f423e9ccdb860484b4e18111..1adea9c2c7d6fccf9e863d026745971185c3859b 100644 (file)
@@ -428,14 +428,16 @@ matched and unmatched messages in the current thread."
   "Return the stable query for the current region.
 
 If ONLY-MATCHED is non-nil, include only matched messages.  If it
-is nil, include both matched and unmatched messages."
+is nil, include both matched and unmatched messages. If there are
+no messages in the region then return nil."
   (let ((query-list nil) (all (not only-matched)))
     (dolist (queries (notmuch-search-properties-in-region :query beg end))
       (when (first queries)
        (push (first queries) query-list))
       (when (and all (second queries))
        (push (second queries) query-list)))
-    (concat "(" (mapconcat 'identity query-list ") or (") ")")))
+    (when query-list
+      (concat "(" (mapconcat 'identity query-list ") or (") ")"))))
 
 (defun notmuch-search-find-authors ()
   "Return the authors for the current thread"