unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [RFC PATCH v2 7/8] WIP/emacs: keep tag history
Date: Sat, 29 Jan 2022 15:44:39 -0400	[thread overview]
Message-ID: <20220129194439.2790761-8-david@tethera.net> (raw)
In-Reply-To: <20220129194439.2790761-1-david@tethera.net>

---
 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

  parent reply	other threads:[~2022-01-29 19:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-29 19:44 v2 undo tag operations in emacs David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 1/8] test: split variable settings to their own file David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 2/8] test/emacs: split out emacs related tests David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 3/8] WIP enable running test_emacs from performance tests David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 4/8] perf-test: inital emacs tests David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 5/8] cli/tag: add --output={none,lastmod} argument David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 6/8] WIP: support tag --output=lastmod David Bremner
2022-01-29 19:44 ` David Bremner [this message]
2022-01-29 19:44 ` [RFC PATCH v2 8/8] WIP: add notmuch-tag-undo David Bremner
2022-02-02 14:34   ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220129194439.2790761-8-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).