From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id mIDsMZUYCGI/zAAAgWs5BA (envelope-from ) for ; Sat, 12 Feb 2022 21:29:09 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id IHlBL5UYCGKXyQAA9RJhRA (envelope-from ) for ; Sat, 12 Feb 2022 21:29:09 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7A27F2BE66 for ; Sat, 12 Feb 2022 21:29:09 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 72E785F743; Sat, 12 Feb 2022 20:28:57 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 44F325F6B5 for ; Sat, 12 Feb 2022 20:28:54 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id B6B715FBD2; Sat, 12 Feb 2022 15:28:53 -0500 (EST) Received: (nullmailer pid 2577366 invoked by uid 1000); Sat, 12 Feb 2022 20:27:56 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH v4 08/11] emacs: add notmuch-tag-undo Date: Sat, 12 Feb 2022 16:27:39 -0400 Message-Id: <20220212202742.2577237-9-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220212202742.2577237-1-david@tethera.net> References: <20220212202742.2577237-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: R77VYJU47AWDW6DEQV64YR7NCFO2K4Q3 X-Message-ID-Hash: R77VYJU47AWDW6DEQV64YR7NCFO2K4Q3 X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644697749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=IV5xgn77lVt64r4oPxzueZdbghbf5AmF/NKqa9tKdx0=; b=Mq+Oqw2eVkvcGEXamvbBLOsOdWmo8R4Y2KRdqzKoPDsyaclt5D+J23o6nZy1oUraWOVE/E 4ezgqKnuJwAanm05QiHWKYQavToyLfZ+zY2U+qt7ywJ+TK9+9oEEYNNNSz7rwxOtAP+am/ GLWvTUev7GQtGAkOqHcHv7sXvszmT/UqGq5PoncfxWF2N50QB3ifrq/pOqUxuoeuZPkFKH wWgQ8g0D+TvC5zMDj33vwHST9QJI/VMwzIYQpEEhwNUs+UPqTbhgHCqEmhkeJoBMs9YQtZ qCDM9JHew7G8cQKDQ18XccKLcKq9TbF3vbpWaza3uLunv5VpiJbIwYlhoFUO9A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644697749; a=rsa-sha256; cv=none; b=DvZe9jt+g4tS9KOt0Jgrg8Q1MvDQS1obEh5XKpFvkOJPcVQ4RDnCh5EP1yWj/SfgUjA4fs aIP8WesL1Pd089dsxY45w80vNdIa0IgYuPbPYq0QVEnJ+0yUlR0FKNb2NeVNNLElq3PzZ+ 9DllAi6cC9NEtfQ9ockGX6VZAgguA4EQjQDPSl+3sal0jzpOxKl7xQyyMaqVCXvGAR069w 0ySngQ9Pq2CXVrxW18GkX5xHxwjKXge3H1AYrqefsd3sHcCvU7xPk2uxowNnA4gpjDUXb+ Gq1Goy0b06ar9TzL/2O03KlOId/gw3ZxphunYM617KJEsyuMjOVzci8iNXxBdw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.34 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 7A27F2BE66 X-Spam-Score: -1.34 X-Migadu-Scanner: scn1.migadu.com X-TUID: Goz+DNGM+ZD9 Keybindings are deferred to a future commit. --- doc/notmuch-emacs.rst | 15 ++++++++++++ emacs/notmuch-tag.el | 14 +++++++++++ test/T315-emacs-tagging.sh | 50 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/doc/notmuch-emacs.rst b/doc/notmuch-emacs.rst index f2667de1..991539bf 100644 --- a/doc/notmuch-emacs.rst +++ b/doc/notmuch-emacs.rst @@ -383,6 +383,21 @@ operations specified in ``notmuch-tagging-keys``; i.e. each |docstring::notmuch-tagging-keys| +.. _notmuch-tag-undo: + +notmuch-tag-undo +---------------- + +Each notmuch buffer supporting tagging operations (i.e buffers in +:any:`notmuch-show`, :any:`notmuch-search`, :any:`notmuch-tree`, and +:any:`notmuch-unthreaded` mode) keeps a local stack of tagging +operations. These can be undone via ``notmuch-tag-undo``. By default +this is bound to the usual Emacs keys for undo. + +:index:`notmuch-tag-undo` + + |docstring::notmuch-tag-undo| + Buffer navigation ================= diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el index 4c974679..95977881 100644 --- a/emacs/notmuch-tag.el +++ b/emacs/notmuch-tag.el @@ -278,6 +278,7 @@ This can be used with `notmuch-tag-format-image-data'." ;;; track history of tag operations (defvar-local notmuch-tag-history nil "Buffer local history of `notmuch-tag' function.") +(put 'notmuch-tag-history 'permanent-local t) ;;; Format Handling @@ -502,6 +503,19 @@ notmuch-after-tag-hook will be run." (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)) + (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 02fd3d27..fbaf5f22 100755 --- a/test/T315-emacs-tagging.sh +++ b/test/T315-emacs-tagging.sh @@ -103,5 +103,55 @@ 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 "undo with empty history is an error" +test_emacs "(let ((notmuch-tag-history nil)) + (test-log-error + (notmuch-tag-undo))) + " +cat < EXPECTED +(error no further notmuch undo information) +EOF +test_expect_equal_file EXPECTED MESSAGES + +for mode in search show tree unthreaded; do + test_begin_subtest "undo tagging in $mode mode" + test_emacs "(let ((notmuch-tag-history nil)) + (notmuch-$mode \"$os_x_darwin_thread\") + (notmuch-test-wait) + (execute-kbd-macro \"+tag-to-be-undone-$mode\") + (notmuch-tag-undo) + (notmuch-test-wait))" + count=$(notmuch count "tag:tag-to-be-undone-$mode") + test_expect_equal "$count" "0" + + test_begin_subtest "undo tagging in $mode mode (multiple operations)" + test_emacs "(let ((notmuch-tag-history nil)) + (notmuch-$mode \"$os_x_darwin_thread\") + (notmuch-test-wait) + (execute-kbd-macro \"+one-$mode\") + (execute-kbd-macro \"+two-$mode\") + (notmuch-tag-undo) + (notmuch-test-wait) + (execute-kbd-macro \"+three-$mode\"))" + output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) + notmuch tag "-one-$mode" "-three-$mode" $os_x_darwin_thread + test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox one-$mode three-$mode unread)" + + test_begin_subtest "undo tagging in $mode mode (multiple undo)" + test_emacs "(let ((notmuch-tag-history nil)) + (notmuch-$mode \"$os_x_darwin_thread\") + (notmuch-test-wait) + (execute-kbd-macro \"+one-$mode\") + (execute-kbd-macro \"+two-$mode\") + (notmuch-tag-undo) + (notmuch-test-wait) + (notmuch-tag-undo) + (notmuch-test-wait) + (execute-kbd-macro \"+three-$mode\"))" + output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) + notmuch tag "-one-$mode" "-three-$mode" $os_x_darwin_thread + test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox three-$mode unread)" +done + test_done -- 2.34.1