From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id kLUDIIOZ9WFrUAAAgWs5BA (envelope-from ) for ; Sat, 29 Jan 2022 20:46:11 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id yG+wHIOZ9WH3DgEAauVa8A (envelope-from ) for ; Sat, 29 Jan 2022 20:46:11 +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 36A58406FC for ; Sat, 29 Jan 2022 20:46:06 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 7E0745F74E; Sat, 29 Jan 2022 19:45:48 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 4A0755F73D for ; Sat, 29 Jan 2022 19:45:45 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 841145FBD2; Sat, 29 Jan 2022 14:45:44 -0500 (EST) Received: (nullmailer pid 2790885 invoked by uid 1000); Sat, 29 Jan 2022 19:45:39 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [RFC PATCH v2 7/8] WIP/emacs: keep tag history Date: Sat, 29 Jan 2022 15:44:39 -0400 Message-Id: <20220129194439.2790761-8-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: PAO4LWVBOPCWGHUGTEHQYZQCSDO2ZFHY X-Message-ID-Hash: PAO4LWVBOPCWGHUGTEHQYZQCSDO2ZFHY 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=1643485566; 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=TU1pyLDKGdyOsk64i5VpSqxHWelFxSrGn+8xTWu4HGA=; b=CPEyjJfR4mEvBmFz9H+bFzgxaHQ9w6jZSefurCtl7XbYYrqA/GaRtZONqV5ezXkAzZRQdD GlgEpOAfq1ZefQX2UuYXOCnU8U4IgFVDrT2gJtTOtSjwbzjjNHqYBU3zmuDnZ8jKR7tKGJ CIIOsXVPEs0WnA5WWoF7rlnRp99ma6kRzsIWozuqbTpbdRyUk0pesxjHnKo8Hx5SQwF3vw npA3CZKe70r6QYyG64sclp/0CP+wJWxJWRiCENLPc54f5mTe2CXpKG3zCFBQoqo9NGNm0V WEt4My00ZAyLfAmIt5266OR3GXiUUT/sYW0/XiT2rggAdJYZWrJB9b0QCoIw1w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1643485566; a=rsa-sha256; cv=none; b=RlCgsWTNo74gmMUEUXQwQ/kpxCMujxa7uP/zBAugzfhVCfoOCfwTUOnJ2dNSeUj1MOX+lf 6Gnfq6Z8p2WMu+lYVKzrZqgx3WJ5KdrvX1RmxOvINNWoJdOiDNQnRNCsYl/ZgtlAk1eem7 wtd3Sw+8w87C0ohvKv1ZDwmg4rD+EbCtixlEnMo1ttgPw0seLq3NjOmdc1wGp2rbfYamJX wN22TzGrCeUwNGaSGr1jLEM7GHZkBHKSZmL1Zrgd1tBsxXvCfdnf9j/sIdI3wF0K5Npe6w VpjLlx3bGu1caF+4Wgdbf9CruCoYk1XrT8SdD0Ezy6zv1ifLMC5o3vz9H1+YvQ== 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: -2.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: 36A58406FC X-Spam-Score: -2.36 X-Migadu-Scanner: scn0.migadu.com X-TUID: qMJHeuz4GYVc --- 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'." ") +;;; 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