From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 4AX8J3eZ9WFRLQAAgWs5BA (envelope-from ) for ; Sat, 29 Jan 2022 20:45:59 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id qDRiJXeZ9WGpGwEA9RJhRA (envelope-from ) for ; Sat, 29 Jan 2022 20:45:59 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 62B692ED4D for ; Sat, 29 Jan 2022 20:45:55 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id AF8505F743; Sat, 29 Jan 2022 19:45:45 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 084AC5F73C for ; Sat, 29 Jan 2022 19:45:43 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 3EF205FBD4; Sat, 29 Jan 2022 14:45:41 -0500 (EST) Received: (nullmailer pid 2790890 invoked by uid 1000); Sat, 29 Jan 2022 19:45:39 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [RFC PATCH v2 8/8] WIP: add notmuch-tag-undo Date: Sat, 29 Jan 2022 15:44:40 -0400 Message-Id: <20220129194439.2790761-9-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220129194439.2790761-1-david@tethera.net> References: <20220129194439.2790761-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: ADXMPGB2QTVXXYPDM33DNVU4KTUGRERE X-Message-ID-Hash: ADXMPGB2QTVXXYPDM33DNVU4KTUGRERE 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=1643485555; 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=BhF3eb3ZeQXnxhrXj5Z2TC6KmuXYFrS0EOcPAA64+iY=; b=YC1DAIFhm1UI8OI21wxqEQLnieOF0J8KwvJAPTZzmnqkVZLnsFqnBDoDND29R6tgOAKzyO Jk+2Aey/wrYKSkElvCLWRUaR+ppwaDQQZNRZ8GOqF8T5+EXd0ik1AmPRAEYCGV9Bx7NfTS eSSa2U4W0C124Tti6TNfBEygqxO02uOeLwCKyBK2jvkk/OaYLPETUICJ2t5EPN0+NJJW17 YBjorvxnYfkjy3aSARaJ0AjfilTl0FUK3A1KkDypMeaSyzfuPKG0M7DdFXekoW+S3aY88V MD/4+4/G7NCs9Zld/QeqHrHyHS1EN4EbuCS84FLdYhCk1V4QyBHTCct8oq6qQQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1643485555; a=rsa-sha256; cv=none; b=paAgAo4Mm1Sk4uYrC8WyMOB+l0R/zSqjFYChYCHZNUDpSnIxhY9f83NSU6Nney6czkmGUu 8Bit8NYp88xmeCNY5FKa07tz13xXa31FqsFmXv4nzGEFI6mPm5oM2SfhnyFUTsmz3x3qsS upgARzP2rQ3QyYEWEQUf0zTF7mGFN8RBhIsk6tL0bKD3sqvd8w+2yam+EshXD7hSt6zbVR VXyiC3ud3+Uu42f8GpdWWkp8k60alE71n3XxrNKa/We6UHgg3LRfODLCcoqu4BfnFdNZlD /73VfGHisv3+6Ydbu3Xegj1CgSTtZGjUhrcCOPRukrQ3vDg2k9cL39OFW8eWfA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.36 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 62B692ED4D X-Spam-Score: -1.36 X-Migadu-Scanner: scn1.migadu.com X-TUID: wFfGXrOtN9w+ --- 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 < 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