unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v4] Add notmuch-show--build-queries.
@ 2016-10-19 22:08 Matt Armstrong
  2016-10-20 20:19 ` Mark Walters
  2016-10-22 15:52 ` David Bremner
  0 siblings, 2 replies; 3+ messages in thread
From: Matt Armstrong @ 2016-10-19 22:08 UTC (permalink / raw)
  To: notmuch

notmuch-show--build-buffer now queries a list of queries built by the
former.  This simplifies the logic.  It also provides an easy place to
experiment with alternate sets of queries for given notmuch-show-*
variables (e.g. users can use advice-add to do so in a surgical way).
---
 emacs/notmuch-show.el | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 16ff45a..fcf7e6e 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1263,6 +1263,18 @@ matched."
 	(message "No messages matched the query!")
 	nil))))
 
+(defun notmuch-show--build-queries (thread context)
+  "Return a list of queries to try for this search.
+
+THREAD and CONTEXT are both strings, though CONTEXT may be nil.
+When CONTEXT is not nil, the first query is the conjunction of it
+and THREAD.  The next query is THREAD alone, and serves as a
+fallback if the prior matches no messages."
+  (let (queries)
+    (push (list thread) queries)
+    (if context (push (list thread "and (" context ")") queries))
+    queries))
+
 (defun notmuch-show--build-buffer (&optional state)
   "Display messages matching the current buffer context.
 
@@ -1270,25 +1282,20 @@ Apply the previously saved STATE if supplied, otherwise show the
 first relevant message.
 
 If no messages match the query return NIL."
-  (let* ((basic-args (list notmuch-show-thread-id))
-	 (args (if notmuch-show-query-context
-		   (append (list "\'") basic-args
-			   (list "and (" notmuch-show-query-context ")\'"))
-		 (append (list "\'") basic-args (list "\'"))))
-	 (cli-args (cons "--exclude=false"
+  (let* ((cli-args (cons "--exclude=false"
 			 (when notmuch-show-elide-non-matching-messages
 			   (list "--entire-thread=false"))))
-
-	 (forest (or (notmuch-query-get-threads (append cli-args args))
-		     ;; If a query context reduced the number of
-		     ;; results to zero, try again without it.
-		     (and notmuch-show-query-context
-			  (notmuch-query-get-threads (append cli-args basic-args)))))
-
+	 (queries (notmuch-show--build-queries
+		   notmuch-show-thread-id notmuch-show-query-context))
+	 (forest nil)
 	 ;; Must be reset every time we are going to start inserting
 	 ;; messages into the buffer.
 	 (notmuch-show-previous-subject ""))
-
+    ;; Use results from the first query that returns some.
+    (while (and (not forest) queries)
+      (setq forest (notmuch-query-get-threads
+		    (append cli-args (list "'") (car queries) (list "'"))))
+      (setq queries (cdr queries)))
     (when forest
       (notmuch-show-insert-forest forest)
 
-- 
2.8.0.rc3.226.g39d4020

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

* Re: [PATCH v4] Add notmuch-show--build-queries.
  2016-10-19 22:08 [PATCH v4] Add notmuch-show--build-queries Matt Armstrong
@ 2016-10-20 20:19 ` Mark Walters
  2016-10-22 15:52 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Walters @ 2016-10-20 20:19 UTC (permalink / raw)
  To: Matt Armstrong, notmuch


On Wed, 19 Oct 2016, Matt Armstrong <marmstrong@google.com> wrote:
> notmuch-show--build-buffer now queries a list of queries built by the
> former.  This simplifies the logic.  It also provides an easy place to
> experiment with alternate sets of queries for given notmuch-show-*
> variables (e.g. users can use advice-add to do so in a surgical way).
> ---

This version looks good to me +1

Best wishes

Mark


>  emacs/notmuch-show.el | 35 +++++++++++++++++++++--------------
>  1 file changed, 21 insertions(+), 14 deletions(-)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index 16ff45a..fcf7e6e 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -1263,6 +1263,18 @@ matched."
>  	(message "No messages matched the query!")
>  	nil))))
>  
> +(defun notmuch-show--build-queries (thread context)
> +  "Return a list of queries to try for this search.
> +
> +THREAD and CONTEXT are both strings, though CONTEXT may be nil.
> +When CONTEXT is not nil, the first query is the conjunction of it
> +and THREAD.  The next query is THREAD alone, and serves as a
> +fallback if the prior matches no messages."
> +  (let (queries)
> +    (push (list thread) queries)
> +    (if context (push (list thread "and (" context ")") queries))
> +    queries))
> +
>  (defun notmuch-show--build-buffer (&optional state)
>    "Display messages matching the current buffer context.
>  
> @@ -1270,25 +1282,20 @@ Apply the previously saved STATE if supplied, otherwise show the
>  first relevant message.
>  
>  If no messages match the query return NIL."
> -  (let* ((basic-args (list notmuch-show-thread-id))
> -	 (args (if notmuch-show-query-context
> -		   (append (list "\'") basic-args
> -			   (list "and (" notmuch-show-query-context ")\'"))
> -		 (append (list "\'") basic-args (list "\'"))))
> -	 (cli-args (cons "--exclude=false"
> +  (let* ((cli-args (cons "--exclude=false"
>  			 (when notmuch-show-elide-non-matching-messages
>  			   (list "--entire-thread=false"))))
> -
> -	 (forest (or (notmuch-query-get-threads (append cli-args args))
> -		     ;; If a query context reduced the number of
> -		     ;; results to zero, try again without it.
> -		     (and notmuch-show-query-context
> -			  (notmuch-query-get-threads (append cli-args basic-args)))))
> -
> +	 (queries (notmuch-show--build-queries
> +		   notmuch-show-thread-id notmuch-show-query-context))
> +	 (forest nil)
>  	 ;; Must be reset every time we are going to start inserting
>  	 ;; messages into the buffer.
>  	 (notmuch-show-previous-subject ""))
> -
> +    ;; Use results from the first query that returns some.
> +    (while (and (not forest) queries)
> +      (setq forest (notmuch-query-get-threads
> +		    (append cli-args (list "'") (car queries) (list "'"))))
> +      (setq queries (cdr queries)))
>      (when forest
>        (notmuch-show-insert-forest forest)
>  
> -- 
> 2.8.0.rc3.226.g39d4020
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH v4] Add notmuch-show--build-queries.
  2016-10-19 22:08 [PATCH v4] Add notmuch-show--build-queries Matt Armstrong
  2016-10-20 20:19 ` Mark Walters
@ 2016-10-22 15:52 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2016-10-22 15:52 UTC (permalink / raw)
  To: Matt Armstrong, notmuch

Matt Armstrong <marmstrong@google.com> writes:

> notmuch-show--build-buffer now queries a list of queries built by the
> former.  This simplifies the logic.  It also provides an easy place to
> experiment with alternate sets of queries for given notmuch-show-*
> variables (e.g. users can use advice-add to do so in a surgical way).

pushed to master

d

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

end of thread, other threads:[~2016-10-22 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-19 22:08 [PATCH v4] Add notmuch-show--build-queries Matt Armstrong
2016-10-20 20:19 ` Mark Walters
2016-10-22 15:52 ` David Bremner

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