+(defun notmuch-search-call-notmuch-process (&rest args)
+ (let ((error-buffer (get-buffer-create "*Notmuch errors*")))
+ (with-current-buffer error-buffer
+ (erase-buffer))
+ (if (eq (apply 'call-process "notmuch" nil error-buffer nil args) 0)
+ (point)
+ (progn
+ (with-current-buffer error-buffer
+ (let ((beg (point-min))
+ (end (- (point-max) 1)))
+ (error (buffer-substring beg end))
+ ))))))
+
+(defun notmuch-search-add-tag (tag)
+ (interactive "sTag to add: ")
+ (notmuch-search-call-notmuch-process "tag" (concat "+" tag) (concat "thread:" (notmuch-search-find-thread-id))))
+
+(defun notmuch-search-remove-tag (tag)
+ (interactive "sTag to remove: ")
+ (notmuch-search-call-notmuch-process "tag" (concat "-" tag) (concat "thread:" (notmuch-search-find-thread-id))))
+