aboutsummaryrefslogtreecommitdiff
path: root/emacs
diff options
context:
space:
mode:
authorMohsin Kaleem <mohkale@kisara.moe>2024-03-10 18:57:41 +0000
committerDavid Bremner <david@tethera.net>2024-04-06 15:03:45 -0300
commitcd89065dc36e36b22a2a53832d2cac9b06fba41c (patch)
treea3d2bf48a7d9b647bea2b5d6be1c3ab7d91936af /emacs
parentde234097048c82be74dfb8ec265ac03704308a90 (diff)
emacs: Add new option notmuch-search-hide-excluded
The new notmuch-search-hide-excluded option allows users to configure whether to show or hide excluded messages (as determined by search.exclude_tags in the local notmuch config file). It defaults to true for now to maintain backwards-compatibility with how notmuch-{search,tree} already worked. New commands notmuch-search-toggle-hide-excluded and notmuch-tree-toggle-exclude have also been added. They toggle the value of notmuch-search-hide-excluded 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 A new test file for Emacs has been added which covers the usage of the new `notmuch-search-hide-excluded' option and interactively hiding or showing mail with excluded tags. These test cover the basic usage of the `notmuch-search-toggle-hide-excluded' command in notmuch-search, notmuch-tree and notmuch-unthreaded searches. These tests also cover the persistence of the current value of the hide-excluded mail option as a user switches from between these different search commands. [1]: id:87ilxlxsng.fsf@kisara.moe Amended-by: db, fix indentation in T461-emacs-search-exclude.sh
Diffstat (limited to 'emacs')
-rw-r--r--emacs/notmuch-hello.el40
-rw-r--r--emacs/notmuch-jump.el14
-rw-r--r--emacs/notmuch-lib.el10
-rw-r--r--emacs/notmuch-tree.el60
-rw-r--r--emacs/notmuch.el52
5 files changed, 134 insertions, 42 deletions
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 47ece536..b6d1e2ae 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -33,10 +33,11 @@
(declare-function notmuch-poll "notmuch-lib" ())
(declare-function notmuch-tree "notmuch-tree"
(&optional query query-context target buffer-name
- open-target unthreaded parent-buffer oldest-first))
+ open-target unthreaded parent-buffer
+ oldest-first hide-excluded))
(declare-function notmuch-unthreaded "notmuch-tree"
(&optional query query-context target buffer-name
- open-target))
+ open-target oldest-first hide-excluded))
;;; Options
@@ -143,6 +144,10 @@ a plist. Supported properties are
:sort-order Specify the sort order to be used for the search.
Possible values are `oldest-first', `newest-first'
or nil. Nil means use the default sort order.
+ :excluded Whether to show mail with excluded tags in the
+ search. Possible values are `hide', `show',
+ or nil. Nil means use the default value of
+ `notmuch-search-hide-excluded'.
:search-type Specify whether to run the search in search-mode,
tree mode or unthreaded mode. Set to `tree' to
specify tree mode, \\='unthreaded to specify
@@ -484,19 +489,19 @@ diagonal."
append (notmuch-hello-reflect-generate-row ncols nrows row list))))
(defun notmuch-hello-widget-search (widget &rest _ignore)
- (cl-case (widget-get widget :notmuch-search-type)
- (tree
- (let ((n (notmuch-search-format-buffer-name (widget-value widget) "tree" t)))
- (notmuch-tree (widget-get widget :notmuch-search-terms)
- nil nil n nil nil nil
- (widget-get widget :notmuch-search-oldest-first))))
- (unthreaded
- (let ((n (notmuch-search-format-buffer-name (widget-value widget)
- "unthreaded" t)))
- (notmuch-unthreaded (widget-get widget :notmuch-search-terms) nil nil n)))
- (t
- (notmuch-search (widget-get widget :notmuch-search-terms)
- (widget-get widget :notmuch-search-oldest-first)))))
+ (let ((search-terms (widget-get widget :notmuch-search-terms))
+ (oldest-first (widget-get widget :notmuch-search-oldest-first))
+ (exclude (widget-get widget :notmuch-search-hide-excluded)))
+ (cl-case (widget-get widget :notmuch-search-type)
+ (tree
+ (let ((n (notmuch-search-format-buffer-name (widget-value widget) "tree" t)))
+ (notmuch-tree search-terms nil nil n nil nil nil oldest-first exclude)))
+ (unthreaded
+ (let ((n (notmuch-search-format-buffer-name (widget-value widget)
+ "unthreaded" t)))
+ (notmuch-unthreaded search-terms nil nil n nil oldest-first exclude)))
+ (t
+ (notmuch-search search-terms oldest-first exclude)))))
(defun notmuch-saved-search-count (search)
(car (notmuch--process-lines notmuch-command "count" search)))
@@ -643,6 +648,10 @@ with `notmuch-hello-query-counts'."
(newest-first nil)
(oldest-first t)
(otherwise notmuch-search-oldest-first)))
+ (exclude (cl-case (plist-get elem :excluded)
+ (hide t)
+ (show nil)
+ (otherwise notmuch-search-hide-excluded)))
(search-type (plist-get elem :search-type))
(msg-count (plist-get elem :count)))
(widget-insert (format "%8s "
@@ -652,6 +661,7 @@ with `notmuch-hello-query-counts'."
:notmuch-search-terms query
:notmuch-search-oldest-first oldest-first
:notmuch-search-type search-type
+ :notmuch-search-hide-excluded exclude
name)
(setq column-indent
(1+ (max 0 (- column-width (length name)))))))
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 6a276928..3161ed95 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -50,15 +50,21 @@ 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 (cl-case (plist-get saved-search :excluded)
+ (hide t)
+ (show nil)
+ (otherwise notmuch-search-hide-excluded))))
(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 14469a90..bf9c4a53 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-hide-excluded 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-hide-excluded)
+
(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 718a3879..faec89c4 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -374,6 +374,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-hide-excluded)
(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-hide-excluded))
(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-hide-excluded)))
(defun notmuch-tree-thread-top ()
(when (notmuch-tree-get-message-properties)
@@ -1133,7 +1137,8 @@ object, and with the tree results buffer as the current buffer.")
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
@@ -1142,6 +1147,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-hide-excluded exclude)
(setq notmuch-tree-unthreaded unthreaded)
(setq notmuch-tree-basic-query basic-query)
(setq notmuch-tree-query-context (if (or (string= query-context "")
@@ -1161,14 +1167,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.
@@ -1195,9 +1202,19 @@ 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-hide-excluded ()
+ "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-hide-excluded'."
+ (interactive)
+ (setq notmuch-search-hide-excluded (not notmuch-search-hide-excluded))
+ (notmuch-tree-refresh-view))
+
;;;###autoload
(defun notmuch-tree (&optional query query-context target buffer-name
- open-target unthreaded parent-buffer oldest-first)
+ open-target unthreaded parent-buffer
+ oldest-first hide-excluded)
"Display threads matching QUERY in tree view.
The arguments are:
@@ -1212,7 +1229,15 @@ The arguments are:
it is nil \"*notmuch-tree\" followed by QUERY is used.
OPEN-TARGET: If TRUE open the target message in the message pane.
UNTHREADED: If TRUE only show matching messages in an unthreaded view."
- (interactive)
+ (interactive
+ (list
+ ;; Prompt for a query
+ nil
+ ;; Fill other args with nil.
+ nil nil nil nil nil nil
+ ;; Populate these from the default value of these options.
+ (default-value 'notmuch-search-oldest-first)
+ (default-value 'notmuch-search-hide-excluded)))
(unless query
(setq query (notmuch-read-query (concat "Notmuch "
(if unthreaded "unthreaded " "tree ")
@@ -1226,17 +1251,27 @@ 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 hide-excluded)
(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 hide-excluded)
"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))
+ (interactive
+ (list
+ ;; Prompt for a query
+ nil
+ ;; Fill other args with nil.
+ nil nil nil nil
+ ;; Populate these from the default value of these options.
+ (default-value 'notmuch-search-oldest-first)
+ (default-value 'notmuch-search-hide-excluded)))
+ (notmuch-tree query query-context target buffer-name open-target
+ t nil oldest-first hide-excluded))
(defun notmuch-tree-filter (query)
"Filter or LIMIT the current search results based on an additional query string.
@@ -1270,7 +1305,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-hide-excluded)))
(defun notmuch-tree-edit-search (query)
"Edit the current search"
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6eef4af1..2a73ffa5 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-hide-excluded)
(define-key map "c" 'notmuch-search-stash-map)
(define-key map "t" 'notmuch-search-filter-by-tag)
(define-key map "l" 'notmuch-search-filter)
@@ -550,12 +551,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-hide-excluded))
(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-hide-excluded))
(defun notmuch-tree-from-search-thread ()
"Show the selected thread with notmuch-tree."
@@ -564,7 +571,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-hide-excluded))
(defun notmuch-search-reply-to-thread (&optional prompt-for-sender)
"Begin composing a reply-all to the entire current thread in a new buffer."
@@ -1035,14 +1044,16 @@ 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 hide-excluded 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
+ HIDE-EXCLUDED: 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
@@ -1057,9 +1068,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-hide-excluded)))
(let* ((query (or query (notmuch-read-query "Notmuch search: ")))
(buffer (get-buffer-create (notmuch-search-buffer-title query))))
@@ -1073,6 +1085,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-hide-excluded hide-excluded)
(notmuch-tag-clear-cache)
(when (get-buffer-process buffer)
(error "notmuch search process already running for query `%s'" query))
@@ -1086,6 +1099,9 @@ the configured default sort order."
(if oldest-first
"--sort=oldest-first"
"--sort=newest-first")
+ (if hide-excluded
+ "--exclude=true"
+ "--exclude=false")
query)))
;; Use a scratch buffer to accumulate partial output.
;; This buffer will be killed by the sentinel, which
@@ -1106,11 +1122,21 @@ same relative position within the new buffer."
(interactive)
(notmuch-search notmuch-search-query-string
notmuch-search-oldest-first
+ notmuch-search-hide-excluded
(notmuch-search-find-thread-id 'bare)
(line-number-at-pos)
t)
(goto-char (point-min)))
+(defun notmuch-search-toggle-hide-excluded ()
+ "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-hide-excluded'."
+ (interactive)
+ (setq notmuch-search-hide-excluded (not notmuch-search-hide-excluded))
+ (notmuch-search-refresh-view))
+
(defun notmuch-search-toggle-order ()
"Toggle the current search order.
@@ -1139,7 +1165,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-hide-excluded)))
(defun notmuch-search-filter-by-tag (tag)
"Filter the current search results based on a single TAG.
@@ -1150,13 +1177,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-hide-excluded))
(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-hide-excluded)))
(defun notmuch-search-edit-search (query)
"Edit the current search"