[PATCH 2/3] emacs/show: add parameter notmuch-show-single-message

Subject: [PATCH 2/3] emacs/show: add parameter notmuch-show-single-message

Date: Sat, 26 Jun 2021 09:04:27 -0300

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner

This dynamically bound variable can be set when the caller of
notmuch-show guarantees that exactly one message will match the
query. It avoids transporting and parsing the complete thread
 emacs/notmuch-show.el | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 939f8913..9a95eb34 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -179,6 +179,8 @@ indentation."
 (defvar-local notmuch-show-indent-content t)
+(defvar-local notmuch-show-single-message nil)
 (defvar notmuch-show-attachment-debug nil
   "If t log stdout and stderr from attachment handlers.
@@ -1315,9 +1317,10 @@ Apply the previously saved STATE if supplied, otherwise show the
 first relevant message.
 If no messages match the query return NIL."
-  (let* ((cli-args (cons "--exclude=false"
-			 (and notmuch-show-elide-non-matching-messages
-			      (list "--entire-thread=false"))))
+  (let* ((cli-args (list "--exclude=false"))
+	 (cli-args (if notmuch-show-elide-non-matching-messages (cons "--entire-thread=false" cli-args) cli-args))
+	 ;; "part 0 is the whole message (headers and body)" notmuch-show(1)
+	 (cli-args (if notmuch-show-single-message (cons "--part=0" cli-args) cli-args))
 	 (queries (notmuch-show--build-queries
 		   notmuch-show-thread-id notmuch-show-query-context))
 	 (forest nil)
@@ -1328,6 +1331,8 @@ If no messages match the query return NIL."
     (while (and (not forest) queries)
       (setq forest (notmuch-query-get-threads
 		    (append cli-args (list "'") (car queries) (list "'"))))
+      (when (and forest notmuch-show-single-message)
+	(setq forest (list (list (list forest)))))
       (setq queries (cdr queries)))
     (when forest
       (notmuch-show-insert-forest forest)
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org