[WIP PATCH] emacs: query: completion for from: in searches

Mark Walters markwalters1009 at gmail.com
Fri Aug 12 13:04:02 PDT 2016


This is a first attempt at tab completion for from: searches
---

This sort of works (well it works but maybe in unexpected ways!)

At the moment it completes to any word (as delimited by whitespace) in
any address stored in the address hashmap. It does not trigger the
address harvesting itself -- you either need to call
notmuch-address-harvest-trigger manually, or use address completion
when sending a mail first, and the harvest needs to finish before this
will work.

Since the hashmap does some address deduplication this will not give
perfect completion (there may be names in your database it won't
complete to). Also completion is case-sensitive.

Getting a perfect solution may be more effort than its worth -- this
will probably demonstrate whether something like this suffices.

Best wishes

Mark 

emacs/notmuch.el | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 8acdef3..532f7b3 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -888,10 +888,20 @@ PROMPT is the string to prompt with."
 	       ;; this ugly regexp is used to get the last word of the input
 	       ;; possibly preceded by a '('
 	       ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
-		(mapcar (lambda (compl)
-			  (concat (match-string-no-properties 1 string) compl))
-			(all-completions (match-string-no-properties 2 string)
-					 completions)))
+		(let ((last-word (match-string-no-properties 2 string))
+		      (start-string (match-string-no-properties 1 string)))
+		  (if (and notmuch-address-full-harvest-finished
+			   (string-match "^from:\\(.*\\)" last-word))
+		      (let ((from-completions (notmuch-address-matching (match-string 1 last-word))))
+			(apply #'append
+			       (mapcar (lambda (name-addr)
+					 (mapcar (lambda (compl)
+						   (concat start-string "from:" compl))
+						 (split-string name-addr "[ <>]" t)))
+				       from-completions)))
+		    (mapcar (lambda (compl)
+			      (concat start-string compl))
+			    (all-completions last-word completions)))))
 	       (t (list string)))))))
       ;; this was simpler than convincing completing-read to accept spaces:
       (define-key keymap (kbd "TAB") 'minibuffer-complete)
-- 
2.1.4



More information about the notmuch mailing list