From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.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 gEqFKC/TOWJy0wAAgWs5BA (envelope-from ) for ; Tue, 22 Mar 2022 14:46:23 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id oFY9IS/TOWJV/wAAG6o9tA (envelope-from ) for ; Tue, 22 Mar 2022 14:46:23 +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) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B5BCA328C6 for ; Tue, 22 Mar 2022 14:46:22 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 39C805F71F; Tue, 22 Mar 2022 13:37:50 +0000 (UTC) X-Greylist: delayed 590 seconds by postgrey-1.36 at yantan; Tue, 22 Mar 2022 13:37:47 UTC Received: from mail.kisara.moe (119.ip-51-38-65.eu [51.38.65.119]) by mail.notmuchmail.org (Postfix) with ESMTPS id 919DA5F700 for ; Tue, 22 Mar 2022 13:37:47 +0000 (UTC) Received: from mk-macbook (unknown [89.238.132.37]) by mail.kisara.moe (Postfix) with ESMTPSA id 8ADB9A18B1; Tue, 22 Mar 2022 14:27:56 +0100 (CET) From: Mohsin Kaleem To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH] emacs: add new option notmuch-search-exclude In-Reply-To: <8735mij0yo.fsf@tethera.net> References: <20211128200207.3455217-1-mohkale@kisara.moe> <8735mij0yo.fsf@tethera.net> Date: Tue, 22 Mar 2022 13:27:53 +0000 Message-ID: <87pmme86cm.fsf@kisara.moe> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Message-ID-Hash: TK4RE27C4JVXDR7IPLIIKSLWB74NY6IF X-Message-ID-Hash: TK4RE27C4JVXDR7IPLIIKSLWB74NY6IF X-MailFrom: mohkale@kisara.moe X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0 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: X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1647956783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=jB06ldmeWxkpA0BRbLEptBcIhIuMBBaxro96pPAtXqM=; b=SbWcmqHPhHdFmu5IVcTkZxZxc8A5NwAuvFK5L37pJgC8kgp9klERwDury9o/cMSfJsmiUJ 4JlLcRLFy/xnXsBZX+RVrBUFl+1CIzgotJnUNCNWIn/MqCwh/eeKXQdC3cFbTJnU4hWP6q kBLoQmD1tukFi4Ay4iJh5GGdl9jy+IHfBnazINhU+rJ4GIOTT/Wm4q/2stbsvxt06O9U5z bFJRDR36l90t2sjTBz0B13zovz8h8MwXF0Zl/jK61WJBB8t+SFF2E3q9XwExG80c+wiFPf TAbp4SVsdnd9RhZZ7QBOIdxKmKBIA+723OGB3sDu6cDkN9ox1VyqP3WX8cq9Dg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1647956783; a=rsa-sha256; cv=none; b=q2t7Mt+A5EULW35yESaxci+tjHh3Hwd2UJmAbWUP0/eXpKSQx0ywiWgGZNTnfbIhNrsJgB CeQg6sQLNTZSl0A0UtMPJ+Ws2Ztij/JboiJBqw4xP/1talYMFdDGJL0HxC/5HfflEdK1p5 hw5vCqyznAVf8lIPXkrYw9lL8Q0PqR36wxd91UJjkeoUVWyCpjF+L3wgHC81adnkOyt/yc B7CUvBKr0SCDzqj6NWYk1uwyT4tWuA+tYQlZcZOIEvMGQwMqzjVlbxwx+W3hV13X6yy6jc USHnqCgRH8NMtRYTCg/JH/4SDQOFoNWQpKsfnxsBchluR4tmzCMzuQHEw4lLkw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kisara.moe (policy=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: 2.51 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kisara.moe (policy=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: B5BCA328C6 X-Spam-Score: 2.51 X-Migadu-Scanner: scn0.migadu.com X-TUID: vyH6upL9yl6z --=-=-= Content-Type: text/plain David Bremner writes: > Can you update the file devel/emacs-keybindings.org so we don't lose > track of the bindings. Also, per the contributing guide [1], please > add some brief documentation to the emacs docs in > doc/notmuch-emacs.rst Done. > Also, we need at least one new test (ideally one per mode). There should > be some tests you can crib from in T310-emacs.sh and T450-emacs-show.sh. I'm more than happy to add some new tests but at least for me the test suite appears to be failing on the master branch. I think it'd be easier to wait until the existing tests are fixed before adding or changing new ones. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-emacs-add-new-option-notmuch-search-exclude.patch >From 1872120821ccad5d23ab48d128d8d77efd85055d Mon Sep 17 00:00:00 2001 From: Mohsin Kaleem Date: Sat, 27 Nov 2021 18:58:43 +0000 Subject: [PATCH 1/2] emacs: add new option notmuch-search-exclude The new notmuch-search-exclude option allows users to configure whether to show or hide excluded messages (as determined by search.exclude_tags in the local config file). It defaults to true for now to maintain backwards-compatibility with how notmuch-{search,tree} already worked. New commands notmuch-search-toggle-exclude and notmuch-tree-toggle-exclude have also been added that toggle the value of notmuch-search-exclude for the search in the current search or tree buffer. It's bound to "i" in the respective keymaps for these modes. Lastly I've amended some calls to notmuch-tree and notmuch-unthreaded which didn't pass through the buffer local value of notmuch-search-oldest-first (and now notmuch-search-exclude). Examples of where I've done this + include notmuch-jump-search + notmuch-tree-from-search-current-query + notmuch-unthreaded-from-search-current-query + notmuch-tree-from-search-thread If there was a reasoning behind these not persisting the value of these variables then we should revert it before merging and discuss whether it's worth persisting notmuch-search-exclude. [1]: id:87ilxlxsng.fsf@kisara.moe --- emacs/notmuch-jump.el | 11 ++++++---- emacs/notmuch-lib.el | 10 +++++++++ emacs/notmuch-tree.el | 40 ++++++++++++++++++++++++--------- emacs/notmuch.el | 51 +++++++++++++++++++++++++++++++++---------- 4 files changed, 87 insertions(+), 25 deletions(-) diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el index 6a276928..e98c9c1d 100644 --- a/emacs/notmuch-jump.el +++ b/emacs/notmuch-jump.el @@ -50,15 +50,18 @@ fast way to jump to a saved search from anywhere in Notmuch." (cl-case (plist-get saved-search :sort-order) (newest-first nil) (oldest-first t) - (otherwise (default-value 'notmuch-search-oldest-first))))) + (otherwise (default-value 'notmuch-search-oldest-first)))) + (exclude (default-value 'notmuch-search-exclude))) (push (list key name (cond ((eq (plist-get saved-search :search-type) 'tree) - (lambda () (notmuch-tree query))) + (lambda () (notmuch-tree query nil nil nil nil nil nil + oldest-first exclude))) ((eq (plist-get saved-search :search-type) 'unthreaded) - (lambda () (notmuch-unthreaded query))) + (lambda () (notmuch-unthreaded query nil nil nil nil + oldest-first exclude))) (t - (lambda () (notmuch-search query oldest-first))))) + (lambda () (notmuch-search query oldest-first exclude))))) action-map))))) (setq action-map (nreverse action-map)) (if action-map diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 6fc71cc7..9a0e470e 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -105,6 +105,16 @@ search." :group 'notmuch-search) (make-variable-buffer-local 'notmuch-search-oldest-first) +(defcustom notmuch-search-exclude t + "Hide mail tagged with a excluded tag. + +Excluded tags are defined in the users configuration file under +the search section. When this variable is true, any mail with +such a tag will not be shown in the search output." + :type 'boolean + :group 'notmuch-search) +(make-variable-buffer-local 'notmuch-search-exclude) + (defcustom notmuch-poll-script nil "[Deprecated] Command to run to incorporate new mail into the notmuch database. diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index 303c6fad..e4d9ae44 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -363,6 +363,7 @@ then NAME behaves like CMD." (define-key map [remap notmuch-jump-search] 'notmuch-tree-jump-search) (define-key map "o" 'notmuch-tree-toggle-order) + (define-key map "i" 'notmuch-tree-toggle-exclude) (define-key map "S" 'notmuch-search-from-tree-current-query) (define-key map "U" 'notmuch-unthreaded-from-tree-current-query) (define-key map "Z" 'notmuch-tree-from-unthreaded-current-query) @@ -578,7 +579,9 @@ NOT change the database." "Call notmuch search with the current query." (interactive) (notmuch-tree-close-message-window) - (notmuch-search (notmuch-tree-get-query))) + (notmuch-search (notmuch-tree-get-query) + notmuch-search-oldest-first + notmuch-search-exclude)) (defun notmuch-tree-message-window-kill-hook () "Close the message pane when exiting the show buffer." @@ -791,7 +794,8 @@ nil otherwise." target nil unthreaded - notmuch-search-oldest-first))) + notmuch-search-oldest-first + notmuch-search-exclude))) (defun notmuch-tree-thread-top () (when (notmuch-tree-get-message-properties) @@ -1108,7 +1112,8 @@ Complete list of currently available key bindings: results-buf))))) (defun notmuch-tree-worker (basic-query &optional query-context target - open-target unthreaded oldest-first) + open-target unthreaded oldest-first + exclude) "Insert the tree view of the search in the current buffer. This is is a helper function for notmuch-tree. The arguments are @@ -1117,6 +1122,7 @@ the same as for the function notmuch-tree." (notmuch-tree-mode) (add-hook 'post-command-hook #'notmuch-tree-command-hook t t) (setq notmuch-search-oldest-first oldest-first) + (setq notmuch-search-exclude exclude) (setq notmuch-tree-unthreaded unthreaded) (setq notmuch-tree-basic-query basic-query) (setq notmuch-tree-query-context (if (or (string= query-context "") @@ -1136,14 +1142,15 @@ the same as for the function notmuch-tree." (and query-context (concat " and (" query-context ")")))) (sort-arg (if oldest-first "--sort=oldest-first" "--sort=newest-first")) - (message-arg (if unthreaded "--unthreaded" "--entire-thread"))) + (message-arg (if unthreaded "--unthreaded" "--entire-thread")) + (exclude-arg (if exclude "--exclude=true" "--exclude=false"))) (when (equal (car (notmuch--process-lines notmuch-command "count" search-args)) "0") (setq search-args basic-query)) (notmuch-tag-clear-cache) (let ((proc (notmuch-start-notmuch "notmuch-tree" (current-buffer) #'notmuch-tree-process-sentinel "show" "--body=false" "--format=sexp" "--format-version=5" - sort-arg message-arg search-args)) + sort-arg message-arg exclude-arg search-args)) ;; Use a scratch buffer to accumulate partial output. ;; This buffer will be killed by the sentinel, which ;; should be called no matter how the process dies. @@ -1170,8 +1177,18 @@ default sort order is defined by `notmuch-search-oldest-first'." (setq notmuch-search-oldest-first (not notmuch-search-oldest-first)) (notmuch-tree-refresh-view)) +(defun notmuch-tree-toggle-exclude () + "Toggle whether to hide excluded messages. + +This command toggles whether to hide excluded messages for the current +search. The default value for this is defined by `notmuch-search-exclude'." + (interactive) + (setq notmuch-search-exclude (not notmuch-search-exclude)) + (notmuch-tree-refresh-view)) + (defun notmuch-tree (&optional query query-context target buffer-name - open-target unthreaded parent-buffer oldest-first) + open-target unthreaded parent-buffer + oldest-first exclude) "Display threads matching QUERY in tree view. The arguments are: @@ -1200,17 +1217,19 @@ The arguments are: (pop-to-buffer-same-window buffer)) ;; Don't track undo information for this buffer (setq buffer-undo-list t) - (notmuch-tree-worker query query-context target open-target unthreaded oldest-first) + (notmuch-tree-worker query query-context target open-target + unthreaded oldest-first exclude) (setq notmuch-tree-parent-buffer parent-buffer) (setq truncate-lines t)) (defun notmuch-unthreaded (&optional query query-context target buffer-name - open-target) + open-target oldest-first exclude) "Display threads matching QUERY in unthreaded view. See function NOTMUCH-TREE for documentation of the arguments" (interactive) - (notmuch-tree query query-context target buffer-name open-target t)) + (notmuch-tree query query-context target buffer-name open-target + t nil oldest-first exclude)) (defun notmuch-tree-filter (query) "Filter or LIMIT the current search results based on an additional query string. @@ -1244,7 +1263,8 @@ search results and that are also tagged with the given TAG." nil notmuch-tree-unthreaded nil - notmuch-search-oldest-first))) + notmuch-search-oldest-first + notmuch-search-exclude))) ;;; _ diff --git a/emacs/notmuch.el b/emacs/notmuch.el index c9cf80dc..a42cb576 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -178,6 +178,7 @@ there will be called at other points of notmuch execution." (define-key map "r" 'notmuch-search-reply-to-thread-sender) (define-key map "R" 'notmuch-search-reply-to-thread) (define-key map "o" 'notmuch-search-toggle-order) + (define-key map "i" 'notmuch-search-toggle-exclude) (define-key map "c" 'notmuch-search-stash-map) (define-key map "t" 'notmuch-search-filter-by-tag) (define-key map "l" 'notmuch-search-filter) @@ -537,12 +538,18 @@ thread." (defun notmuch-tree-from-search-current-query () "Tree view of current query." (interactive) - (notmuch-tree notmuch-search-query-string)) + (notmuch-tree notmuch-search-query-string + nil nil nil nil nil nil + notmuch-search-oldest-first + notmuch-search-exclude)) (defun notmuch-unthreaded-from-search-current-query () "Unthreaded view of current query." (interactive) - (notmuch-unthreaded notmuch-search-query-string)) + (notmuch-unthreaded notmuch-search-query-string + nil nil nil nil + notmuch-search-oldest-first + notmuch-search-exclude)) (defun notmuch-tree-from-search-thread () "Show the selected thread with notmuch-tree." @@ -551,7 +558,9 @@ thread." notmuch-search-query-string nil (notmuch-prettify-subject (notmuch-search-find-subject)) - t nil (current-buffer))) + t nil (current-buffer) + notmuch-search-oldest-first + notmuch-search-exclude)) (defun notmuch-search-reply-to-thread (&optional prompt-for-sender) "Begin composing a reply-all to the entire current thread in a new buffer." @@ -1021,14 +1030,15 @@ PROMPT is the string to prompt with." (put 'notmuch-search 'notmuch-doc "Search for messages.") ;;;###autoload -(defun notmuch-search (&optional query oldest-first target-thread target-line - no-display) +(defun notmuch-search (&optional query oldest-first exclude target-thread + target-line no-display) "Display threads matching QUERY in a notmuch-search buffer. If QUERY is nil, it is read interactively from the minibuffer. Other optional parameters are used as follows: OLDEST-FIRST: A Boolean controlling the sort order of returned threads + EXCLUDE: A boolean controlling whether to omit threads with excluded tags. TARGET-THREAD: A thread ID (without the thread: prefix) that will be made current if it appears in the search results. TARGET-LINE: The line number to move to if the target thread does not @@ -1043,9 +1053,10 @@ the configured default sort order." (list ;; Prompt for a query nil - ;; Use the default search order (if we're doing a search from a - ;; search buffer, ignore any buffer-local overrides) - (default-value 'notmuch-search-oldest-first))) + ;; Use the default search order and exclude value (if we're doing a + ;; search from a search buffer, ignore any buffer-local overrides) + (default-value 'notmuch-search-oldest-first) + (default-value 'notmuch-search-exclude))) (let* ((query (or query (notmuch-read-query "Notmuch search: "))) (buffer (get-buffer-create (notmuch-search-buffer-title query)))) @@ -1059,6 +1070,7 @@ the configured default sort order." (setq notmuch-search-oldest-first oldest-first) (setq notmuch-search-target-thread target-thread) (setq notmuch-search-target-line target-line) + (setq notmuch-search-exclude exclude) (notmuch-tag-clear-cache) (when (get-buffer-process buffer) (error "notmuch search process already running for query `%s'" query)) @@ -1072,6 +1084,9 @@ the configured default sort order." (if oldest-first "--sort=oldest-first" "--sort=newest-first") + (if exclude + "--exclude=true" + "--exclude=false") query))) ;; Use a scratch buffer to accumulate partial output. ;; This buffer will be killed by the sentinel, which @@ -1092,11 +1107,21 @@ same relative position within the new buffer." (interactive) (notmuch-search notmuch-search-query-string notmuch-search-oldest-first + notmuch-search-exclude (notmuch-search-find-thread-id 'bare) (line-number-at-pos) t) (goto-char (point-min))) +(defun notmuch-search-toggle-exclude () + "Toggle whether to hide excluded messages. + +This command toggles whether to hide excluded messages for the current +search. The default value for this is defined by `notmuch-search-exclude'." + (interactive) + (setq notmuch-search-exclude (not notmuch-search-exclude)) + (notmuch-search-refresh-view)) + (defun notmuch-search-toggle-order () "Toggle the current search order. @@ -1125,7 +1150,8 @@ current search results AND the additional query string provided." (notmuch-search (if (string= grouped-original-query "*") grouped-query (concat grouped-original-query " and " grouped-query)) - notmuch-search-oldest-first))) + notmuch-search-oldest-first + notmuch-search-exclude))) (defun notmuch-search-filter-by-tag (tag) "Filter the current search results based on a single TAG. @@ -1136,13 +1162,16 @@ search results and that are also tagged with the given TAG." (list (notmuch-select-tag-with-completion "Filter by tag: " notmuch-search-query-string))) (notmuch-search (concat notmuch-search-query-string " and tag:" tag) - notmuch-search-oldest-first)) + notmuch-search-oldest-first + notmuch-search-exclude)) (defun notmuch-search-by-tag (tag) "Display threads matching TAG in a notmuch-search buffer." (interactive (list (notmuch-select-tag-with-completion "Notmuch search tag: "))) - (notmuch-search (concat "tag:" tag))) + (notmuch-search (concat "tag:" tag) + (default-value 'notmuch-search-oldest-first) + (default-value 'notmuch-search-exclude))) ;;;###autoload (defun notmuch () -- 2.35.1 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-docs-Update-with-notmuch-toggle-exclude.patch >From 57c13040b305d26f80321c2b435b950ee5a16a4a Mon Sep 17 00:00:00 2001 From: Mohsin Kaleem Date: Tue, 22 Mar 2022 13:04:14 +0000 Subject: [PATCH 2/2] docs: Update with notmuch-*-toggle-exclude --- devel/emacs-keybindings.org | 2 +- doc/notmuch-emacs.rst | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/devel/emacs-keybindings.org b/devel/emacs-keybindings.org index 00977bc3..d0ec2633 100644 --- a/devel/emacs-keybindings.org +++ b/devel/emacs-keybindings.org @@ -9,7 +9,7 @@ | f | | notmuch-show-forward-message | notmuch-show-forward-message | | g | | | | | h | | notmuch-show-toggle-visibility-headers | | -| i | | | | +| i | notmuch-search-toggle-exclude | | notmuch-tree-toggle-exclude | | j | notmuch-jump-search | notmuch-jump-search | notmuch-jump-search | | k | notmuch-tag-jump | notmuch-tag-jump | notmuch-tag-jump | | l | notmuch-search-filter | notmuch-show-filter-thread | notmuch-tree-filter | diff --git a/doc/notmuch-emacs.rst b/doc/notmuch-emacs.rst index 41f62390..dacc5b60 100644 --- a/doc/notmuch-emacs.rst +++ b/doc/notmuch-emacs.rst @@ -162,6 +162,9 @@ menu of results that the user can explore further by pressing ``g`` ``=`` Refresh the buffer +``i`` + Toggle whether to show messages with excluded tags in search results. + ``?`` Display full set of key bindings @@ -321,6 +324,8 @@ tags. ``t`` ``notmuch-tree-filter-by-tag`` Filter the current search results based on an additional tag +``i`` + Toggle whether to show messages with excluded tags in search results. ``g`` ``=`` Refresh the buffer -- 2.35.1 --=-=-= Content-Type: text/plain -- Mohsin Kaleem --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --=-=-=--