---
emacs/notmuch-tag.el | 30 ++++++++++++++++++++++--------
test/T315-emacs-tagging.sh | 12 ++++++++++++
2 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 8af09e68..28a2b596 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -275,6 +275,10 @@ This can be used with `notmuch-tag-format-image-data'."
</g>
</svg>")
+;;; track history of tag operations
+(defvar-local notmuch-tag-history nil
+ "Global history of `notmuch-tag' function.")
+
;;; Format Handling
(defvar notmuch-tag--format-cache (make-hash-table :test 'equal)
@@ -460,7 +464,7 @@ from TAGS if present."
This limits the length of arguments passed to the notmuch CLI to
avoid system argument length limits and performance problems.")
-(defun notmuch-tag (query tag-changes)
+(defun notmuch-tag (query tag-changes &optional omit-hist)
"Add/remove tags in TAG-CHANGES to messages matching QUERY.
QUERY should be a string containing the search-terms.
@@ -481,13 +485,23 @@ notmuch-after-tag-hook will be run."
(notmuch-dlet ((tag-changes tag-changes)
(query query))
(run-hooks 'notmuch-before-tag-hook))
- (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")))
+ (let ((parent-buffer (current-buffer))
+ (batch-mode (> (length query) notmuch-tag-argument-limit)))
+ (with-temp-buffer
+ (when batch-mode
+ (insert (concat (mapconcat #'notmuch-hex-encode tag-changes " ") " -- " query)))
+ (apply #'notmuch--call-process-region
+ (point-min) (point-max)
+ notmuch-command t t nil "tag" "--output=lastmod"
+ (if batch-mode '("--batch")
+ (append tag-changes (list "--" query))))
+ (unless omit-hist
+ (goto-char (point-min))
+ (let ((uuid (read (current-buffer)))
+ (from (read (current-buffer)))
+ (to (read (current-buffer))))
+ (with-current-buffer parent-buffer
+ (push (list :uuid uuid :from from :to to :tag-changes tag-changes) notmuch-tag-history))))))
(notmuch-dlet ((tag-changes tag-changes)
(query query))
(run-hooks 'notmuch-after-tag-hook))))
diff --git a/test/T315-emacs-tagging.sh b/test/T315-emacs-tagging.sh
index 02fd3d27..e4540a3a 100755
--- a/test/T315-emacs-tagging.sh
+++ b/test/T315-emacs-tagging.sh
@@ -103,5 +103,17 @@ test_emacs '(notmuch-search "subject:\"search race test\" -subject:two")
output=$(notmuch search --output=messages 'tag:search-global-race-tag')
test_expect_equal "$output" "id:$gen_msg_id_1"
+test_begin_subtest "history interval matches size of thread"
+output=$(test_emacs "(let ((notmuch-tag-history nil))
+ (notmuch-search \"$os_x_darwin_thread\")
+ (notmuch-test-wait)
+ (execute-kbd-macro \"+tag-for-history\")
+ (let* ((plist (car notmuch-tag-history))
+ (from (plist-get plist :from))
+ (to (plist-get plist :to)))
+ (+ 1 (- to from))))
+ ")
+count=$(notmuch count "$os_x_darwin_thread")
+test_expect_equal "$output" "$count"
test_done
--
2.34.1
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org