[WIP PATCH] emacs: add "--" to finish notmuch command line args before search terms

Tomi Ollila tomi.ollila at iki.fi
Sat Sep 17 02:16:12 PDT 2016


I don't (yet) know how complete this is (Someone's "workflow" it may break)
but tests pass...
---

This is related to id:m2lgyr378r.fsf at guru.guru-group.fi -- notmuch cli supports
"--" to separate options from rest of the command line universally. The change
here would complete the particular need I presented in that email -- but
it might not be complete solution...

 emacs/notmuch-address.el |  2 +-
 emacs/notmuch-mua.el     |  2 +-
 emacs/notmuch-query.el   | 13 ++-----------
 emacs/notmuch-show.el    |  4 ++--
 emacs/notmuch-tree.el    |  2 +-
 emacs/notmuch.el         |  2 +-
 6 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 10eaab1..2ea1c62 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -277,7 +277,7 @@ (defun notmuch-address-harvest (&optional addr-prefix synchronous callback)
 	 (args `("address" "--format=sexp" "--format-version=2"
 		 ,(if sent "--output=recipients" "--output=sender")
 		 "--deduplicate=address"
-		 ,query)))
+		 "--" ,query)))
     (if synchronous
 	(mapc #'notmuch-address-harvest-addr
 				   (apply 'notmuch-call-notmuch-sexp args))
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index fadf20f..115c23f 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -183,7 +183,7 @@ (defun notmuch-mua-reply (query-string &optional sender reply-all)
     (if reply-all
 	(setq args (append args '("--reply-to=all")))
       (setq args (append args '("--reply-to=sender"))))
-    (setq args (append args (list query-string)))
+    (setq args (append args (list "--" query-string)))
 
     ;; Get the reply object as SEXP, and parse it into an elisp object.
     (setq reply (apply #'notmuch-call-notmuch-sexp args))
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index 436ad16..fec97ec 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -23,7 +23,7 @@
 
 (require 'notmuch-lib)
 
-(defun notmuch-query-get-threads (search-terms)
+(defun notmuch-query-get-threads (cli-args search-terms)
   "Return a list of threads of messages matching SEARCH-TERMS.
 
 A thread is a forest or list of trees. A tree is a two element
@@ -33,7 +33,7 @@ (defun notmuch-query-get-threads (search-terms)
   (let ((args '("show" "--format=sexp" "--format-version=1")))
     (if notmuch-show-process-crypto
 	(setq args (append args '("--decrypt"))))
-    (setq args (append args search-terms))
+    (setq args (append args cli-args '("--") search-terms))
     (apply #'notmuch-call-notmuch-sexp args)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -66,15 +66,6 @@ (defun notmuch-query-map-tree (fn tree)
 See the function notmuch-query-get-threads for more information."
   (cons (funcall fn (car tree)) (notmuch-query-map-forest fn (cadr tree))))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Predefined queries
-
-(defun notmuch-query-get-message-ids (&rest search-terms)
-  "Return a list of message-ids of messages that match SEARCH-TERMS"
-  (notmuch-query-map-threads
-   (lambda (msg) (plist-get msg :id))
-   (notmuch-query-get-threads search-terms)))
-
 (provide 'notmuch-query)
 
 ;;; notmuch-query.el ends here
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 5a585f3..8aada01 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1274,11 +1274,11 @@ (defun notmuch-show--build-buffer (&optional state)
 			 (when notmuch-show-elide-non-matching-messages
 			   (list "--entire-thread=false"))))
 
-	 (forest (or (notmuch-query-get-threads (append cli-args args))
+	 (forest (or (notmuch-query-get-threads 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)))))
+			  (notmuch-query-get-threads cli-args basic-args))))
 
 	 ;; Must be reset every time we are going to start inserting
 	 ;; messages into the buffer.
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index d864e6d..49baee6 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -890,7 +890,7 @@ (defun notmuch-tree-worker (basic-query &optional query-context target open-targ
     (let ((proc (notmuch-start-notmuch
 		 "notmuch-tree" (current-buffer) #'notmuch-tree-process-sentinel
 		 "show" "--body=false" "--format=sexp"
-		 message-arg search-args))
+		 message-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.
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 8e14692..4f0b7ed 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -971,7 +971,7 @@ (defun notmuch-search (&optional query oldest-first target-thread target-line)
 		     (if oldest-first
 			 "--sort=oldest-first"
 		       "--sort=newest-first")
-		     query))
+		     "--" query))
 	      ;; 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.
-- 
2.7.4



More information about the notmuch mailing list