Add a (probably incomplete) function to validate a tag specified by
the user. Use the function to avoid adding invalid tags.
---
 emacs/notmuch.el |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 3d82f0d..b003cd6 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -72,12 +72,19 @@ For example:
   :type '(alist :key-type (string) :value-type (string))
   :group 'notmuch)

+(defun notmuch-valid-tag (tag)
+  (not (string= "" tag)))
+
 (defun notmuch-select-tag-with-completion (prompt &rest search-terms)
-  (let ((tag-list
-        (with-output-to-string
-          (with-current-buffer standard-output
-            (apply 'call-process notmuch-command nil t nil "search-tags" 
search-terms)))))
-    (completing-read prompt (split-string tag-list "\n+" t) nil nil nil)))
+  (let* ((tag-list
+         (with-output-to-string
+           (with-current-buffer standard-output
+             (apply 'call-process notmuch-command nil t nil "search-tags" 
search-terms))))
+        (tag (completing-read prompt (split-string tag-list "\n+" t)
+                              nil nil nil)))
+    (if (notmuch-valid-tag tag)
+       tag
+      (error "Invalid tag"))))

 (defun notmuch-foreach-mime-part (function mm-handle)
   (cond ((stringp (car mm-handle))
-- 
1.7.2.3

  • "empty" tag Sebastian Spaeth
    • [PATCH] emacs: Avoid attempts to add invalid tags. David Edmondson

Reply via email to