- (if (<= (length query) notmuch-tag-argument-limit)
- (apply 'notmuch-call-notmuch-process "tag"
- (append tag-changes (list "--" query)))
- ;; Use batch tag mode to avoid argument length limitations
- (let ((batch-op (concat (mapconcat #'notmuch-hex-encode tag-changes " ")
- " -- " query)))
- (notmuch-call-notmuch-process :stdin-string batch-op "tag" "--batch")))
- (notmuch-dlet ((tag-changes tag-changes)
- (query query))
- (run-hooks 'notmuch-after-tag-hook))))
+ (with-temp-buffer
+ (insert (concat (mapconcat #'notmuch-hex-encode tag-changes " ") " -- " query))
+ (unless (= 0
+ (notmuch--call-process-region
+ (point-min) (point-max) notmuch-command t t nil "tag" "--batch"))
+ (notmuch-logged-error "notmuch tag failed" (buffer-string))))
+ (unless omit-hist
+ (push (list :query query :tag-changes tag-changes) notmuch-tag-history)))
+ (notmuch-dlet ((tag-changes tag-changes)
+ (query query))
+ (run-hooks 'notmuch-after-tag-hook)))
+
+(defun notmuch-tag-undo ()
+ "Undo the previous tagging operation in the current buffer. Uses
+buffer local variable `notmuch-tag-history' to determine what
+that operation was."
+ (interactive)
+ (when (null notmuch-tag-history)
+ (error "no further notmuch undo information"))
+ (let* ((action (pop notmuch-tag-history))
+ (query (plist-get action :query))
+ (changes (notmuch-tag-change-list (plist-get action :tag-changes) t)))
+ (notmuch-tag query changes t))
+ (notmuch-refresh-this-buffer))