unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* notmuch-emacs: Add option to set -exclude=false in notmuch search/tree
@ 2021-10-25 11:14 Mohsin Kaleem
  2021-10-25 15:18 ` David Bremner
  2021-10-27 10:52 ` Gregor Zattler
  0 siblings, 2 replies; 4+ messages in thread
From: Mohsin Kaleem @ 2021-10-25 11:14 UTC (permalink / raw)
  To: notmuch


At the moment we always use the default value of exclude in calls to
notmuch search and notmuch tree. If any of the searched mail is tagged
with somethinh that is excluded it isn't shown and if we'd like to check
whether this is the case we have to do an exhaustive search over all of
our hidden tags to check whether the mail got ommited because it was
tagged as such.

I suggest we add a new option `notmuch-search-exclude`, which is used to
set the default value of the exclude flag in both notmuch-search and
notmuch-tree mode, and also to add a new command `notmuch-toggle-exclude`
which toggles the value of `notmuch-search-exclude` for the current
search.

-- 
Mohsin Kaleem

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: notmuch-emacs: Add option to set -exclude=false in notmuch search/tree
  2021-10-25 11:14 notmuch-emacs: Add option to set -exclude=false in notmuch search/tree Mohsin Kaleem
@ 2021-10-25 15:18 ` David Bremner
  2021-11-27 19:28   ` Mohsin Kaleem
  2021-10-27 10:52 ` Gregor Zattler
  1 sibling, 1 reply; 4+ messages in thread
From: David Bremner @ 2021-10-25 15:18 UTC (permalink / raw)
  To: Mohsin Kaleem, notmuch

Mohsin Kaleem <mohkale@kisara.moe> writes:
>
> I suggest we add a new option `notmuch-search-exclude`, which is used to
> set the default value of the exclude flag in both notmuch-search and
> notmuch-tree mode, and also to add a new command `notmuch-toggle-exclude`
> which toggles the value of `notmuch-search-exclude` for the current
> search.

Your request has been added to

     https://nmbug.notmuchmail.org/status/#Wish-list

Unfortunately that list seems to grow rather than shrink over time...

d

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: notmuch-emacs: Add option to set -exclude=false in notmuch search/tree
  2021-10-25 11:14 notmuch-emacs: Add option to set -exclude=false in notmuch search/tree Mohsin Kaleem
  2021-10-25 15:18 ` David Bremner
@ 2021-10-27 10:52 ` Gregor Zattler
  1 sibling, 0 replies; 4+ messages in thread
From: Gregor Zattler @ 2021-10-27 10:52 UTC (permalink / raw)
  To: notmuch

Hi Mohsin, notmuch users,
* Mohsin Kaleem <mohkale@kisara.moe> [2021-10-25; 12:14]:
> I suggest we add a new option `notmuch-search-exclude`, which is used to
> set the default value of the exclude flag in both notmuch-search and
> notmuch-tree mode, and also to add a new command `notmuch-toggle-exclude`
> which toggles the value of `notmuch-search-exclude` for the current
> search.

in absence of these options I have

query.all=(is:spam OR NOT is:spam) AND (is:deleted OR NOT is:deleted)
search.exclude_tags=deleted;spam;

configured for notmuch.  Therefore I'am able to do searches
like

notmuch count -- 'query:all AND path:spam-old/**'

This also works in notmuch-emacs.


It's usefulness hinges on having only a static set of a few
excluded tags.

Ciao; Gregor
--
 -... --- .-. . -.. ..--.. ...-.-

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: notmuch-emacs: Add option to set -exclude=false in notmuch search/tree
  2021-10-25 15:18 ` David Bremner
@ 2021-11-27 19:28   ` Mohsin Kaleem
  0 siblings, 0 replies; 4+ messages in thread
From: Mohsin Kaleem @ 2021-11-27 19:28 UTC (permalink / raw)
  To: David Bremner, notmuch

[-- Attachment #1: Type: text/plain, Size: 1167 bytes --]

David Bremner <david@tethera.net> writes:

> Unfortunately that list seems to grow rather than shrink over time...

Hopefully it won't grow any larger due to this issue :-).

I've implemented this in the patch attached to this email. The new
option is notmuch-search-exclude, it defaults to true. There are new
commands to toggle the value of this variable for the current search and
these are bound to "i" in the respective mode maps.

I've also changed whether or not notmuch-search-oldest-first and
notmuch-search-exclude are persisted across some commands. For example
switching from a regular search buffer to a tree buffer with
notmuch-tree-from-search-current-query will make sure the value of both
these variables is the same in both buffers. Similarly filtering an
existing search such as notmuch-search-filter will also persist them,
but starting a new search with notmuch-search will reset to the global
default value of either of them.

There were quite a lot of functions that I've modified or altered in
some way with this PR. I've tested the ones I'm familliar with and
everythings working the way I expect. If you have any issues please let
me know.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-emacs-add-new-option-notmuch-search-exclude.patch --]
[-- Type: text/x-patch, Size: 14352 bytes --]

From 9b11223c0162f8736dd27d6f1db3fadbd3b027e2 Mon Sep 17 00:00:00 2001
From: Mohsin Kaleem <mohkale@kisara.moe>
Date: Sat, 27 Nov 2021 18:58:43 +0000
Subject: [PATCH] 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      | 47 ++++++++++++++++++++++++++++++++++---------
 4 files changed, 84 insertions(+), 24 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 45817e13..a0b780fd 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 7fa73d40..7e85dc51 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 fa061693..b2e61e36 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."
@@ -978,14 +987,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
@@ -1000,9 +1010,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))))
@@ -1016,6 +1027,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))
@@ -1029,6 +1041,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
@@ -1050,11 +1065,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.
 
@@ -1083,7 +1108,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.
@@ -1094,7 +1120,8 @@ 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."
-- 
2.33.1


[-- Attachment #3: Type: text/plain, Size: 19 bytes --]


-- 
Mohsin Kaleem

[-- Attachment #4: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-27 19:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-25 11:14 notmuch-emacs: Add option to set -exclude=false in notmuch search/tree Mohsin Kaleem
2021-10-25 15:18 ` David Bremner
2021-11-27 19:28   ` Mohsin Kaleem
2021-10-27 10:52 ` Gregor Zattler

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).