From: Mohsin Kaleem <mohkale@kisara.moe>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Cc: Mohsin Kaleem <mohkale@kisara.moe>
Subject: [PATCH 1/9] emacs: add new option notmuch-search-exclude
Date: Sun, 7 Aug 2022 15:57:25 +0100 [thread overview]
Message-ID: <20220807145733.129867-1-mohkale@kisara.moe> (raw)
In-Reply-To: <87v8re66mg.fsf@tethera.net>
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 84ba8c5e..96795054 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 f63ac9a5..9ed8a3d9 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -375,6 +375,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)
@@ -590,7 +591,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."
@@ -803,7 +806,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)
@@ -1120,7 +1124,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
@@ -1129,6 +1134,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 "")
@@ -1148,14 +1154,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.
@@ -1182,8 +1189,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:
@@ -1212,17 +1229,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.
@@ -1256,7 +1275,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 5cb7acd2..0158e20a 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -187,6 +187,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)
@@ -549,12 +550,18 @@ Return non-nil on success."
(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."
@@ -563,7 +570,9 @@ Return non-nil on success."
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."
@@ -1033,14 +1042,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
@@ -1055,9 +1065,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))))
@@ -1071,6 +1082,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))
@@ -1084,6 +1096,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
@@ -1104,11 +1119,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.
@@ -1137,7 +1162,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.
@@ -1148,13 +1174,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.37.1
next prev parent reply other threads:[~2022-08-07 14:58 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-28 20:02 [PATCH] emacs: add new option notmuch-search-exclude Mohsin Kaleem
2021-12-24 0:33 ` David Bremner
2022-03-22 13:27 ` Mohsin Kaleem
2022-03-22 19:21 ` David Bremner
2022-03-22 19:38 ` Mohsin Kaleem
2022-03-22 19:59 ` David Bremner
2022-03-22 20:07 ` Mohsin Kaleem
2022-03-22 20:19 ` David Bremner
2022-03-22 20:27 ` Mohsin Kaleem
2022-03-25 19:36 ` David Bremner
2022-07-24 20:59 ` Mohsin Kaleem
2022-07-30 14:02 ` David Bremner
2022-08-07 14:57 ` Mohsin Kaleem [this message]
2022-08-07 14:57 ` [PATCH 2/9] docs: Update with notmuch-*-toggle-exclude Mohsin Kaleem
2022-08-12 10:42 ` David Bremner
2022-08-07 14:57 ` [PATCH 3/9] test: Fix Search handles subprocess error exit codes Mohsin Kaleem
2022-08-07 14:57 ` [PATCH 4/9] feat: Allow :exclude configuration in notmuch-hello Mohsin Kaleem
2022-08-12 10:46 ` David Bremner
2022-08-07 14:57 ` [PATCH 5/9] feat: Add more interactive specs Mohsin Kaleem
2022-08-12 10:48 ` David Bremner
2022-08-07 14:57 ` [PATCH 6/9] test: Add test cases for new exclude option Mohsin Kaleem
2022-08-08 18:56 ` Tomi Ollila
2022-08-08 19:20 ` Mohsin Kaleem
2022-08-12 10:49 ` David Bremner
2022-08-07 14:57 ` [PATCH 7/9] test: Fix Navigation of notmuch-hello to search results Mohsin Kaleem
2022-08-12 10:51 ` David Bremner
2022-08-07 14:57 ` [PATCH 8/9] review: Rename variables to better express intention Mohsin Kaleem
2022-08-12 10:55 ` David Bremner
2022-08-07 14:57 ` [PATCH 9/9] build: Fix declare-function calls for updated functions Mohsin Kaleem
2022-08-07 15:00 ` [PATCH] emacs: add new option notmuch-search-exclude Mohsin Kaleem
2022-08-12 11:12 ` David Bremner
2022-08-12 11:18 ` David Bremner
2023-04-16 13:18 ` [PATCH v2 0/3] emacs: Add new option notmuch-search-hide-excluded mohkale
2023-04-16 13:18 ` [PATCH v2 1/3] " mohkale
2023-05-03 19:59 ` David Bremner
2023-05-05 11:43 ` Mohsin Kaleem
2023-05-07 12:27 ` David Bremner
2023-05-07 13:19 ` David Bremner
2023-04-16 13:18 ` [PATCH v2 2/3] emacs: Allow notmuch-saved-searches to hide excluded messages mohkale
2023-05-07 13:39 ` David Bremner
2024-03-10 18:48 ` Mohsin Kaleem
2023-05-07 20:13 ` David Bremner
2023-04-16 13:18 ` [PATCH v2 3/3] test/emacs: Add test cases for notmuch-search-hide-excluded mohkale
2023-05-07 20:19 ` David Bremner
2024-03-10 18:57 ` [PATCH v3] emacs: Add new option notmuch-search-hide-excluded mohkale
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=20220807145733.129867-1-mohkale@kisara.moe \
--to=mohkale@kisara.moe \
--cc=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).