---
emacs/notmuch-tag.el | 12 ++++++++++++
test/T315-emacs-tagging.sh | 19 +++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 28a2b596..7ed5c1a5 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -506,6 +506,18 @@ notmuch-after-tag-hook will be run."
(query query))
(run-hooks 'notmuch-after-tag-hook))))
+(defun notmuch-tag-undo ()
+ (interactive)
+ (when (null notmuch-tag-history)
+ (error "no further notmuch undo information"))
+ (let* ((action (pop notmuch-tag-history))
+ (from (plist-get action :from))
+ (to (plist-get action :to))
+ (changes (notmuch-tag-change-list (plist-get action :tag-changes) t))
+ (query (format "lastmod:%d..%d" from to)))
+ (when (<= from to)
+ (notmuch-tag query changes t))))
+
(defun notmuch-tag-change-list (tags &optional reverse)
"Convert TAGS into a list of tag changes.
diff --git a/test/T315-emacs-tagging.sh b/test/T315-emacs-tagging.sh
index e4540a3a..72d8b5b0 100755
--- a/test/T315-emacs-tagging.sh
+++ b/test/T315-emacs-tagging.sh
@@ -116,4 +116,23 @@ output=$(test_emacs "(let ((notmuch-tag-history nil))
count=$(notmuch count "$os_x_darwin_thread")
test_expect_equal "$output" "$count"
+test_begin_subtest "undo with empty history is an error"
+test_emacs "(let ((notmuch-tag-history nil))
+ (test-log-error
+ (notmuch-tag-undo)))
+ "
+cat <<EOF > EXPECTED
+(error no further notmuch undo information)
+EOF
+test_expect_equal_file EXPECTED MESSAGES
+
+test_begin_subtest "undo tagging in search mode"
+test_emacs "(let ((notmuch-tag-history nil))
+ (notmuch-search \"$os_x_darwin_thread\")
+ (notmuch-test-wait)
+ (execute-kbd-macro \"+tag-to-be-undone\")
+ (notmuch-tag-undo))"
+count=$(notmuch count "tag:tag-to-be-undone")
+test_expect_equal "$count" "0"
+
test_done
--
2.34.1
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org