From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [RFC PATCH v2 8/8] WIP: add notmuch-tag-undo
Date: Sat, 29 Jan 2022 15:44:40 -0400 [thread overview]
Message-ID: <20220129194439.2790761-9-david@tethera.net> (raw)
In-Reply-To: <20220129194439.2790761-1-david@tethera.net>
---
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
next prev parent reply other threads:[~2022-01-29 19:45 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 ` [RFC PATCH v2 7/8] WIP/emacs: keep tag history David Bremner
2022-01-29 19:44 ` David Bremner [this message]
2022-02-02 14:34 ` [RFC PATCH v2 8/8] WIP: add notmuch-tag-undo 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-9-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).