unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter
@ 2011-06-04 12:19 Daniel Schoepe
  2011-06-04 13:14 ` Daniel Schoepe
  2011-06-04 15:32 ` Austin Clements
  0 siblings, 2 replies; 16+ messages in thread
From: Daniel Schoepe @ 2011-06-04 12:19 UTC (permalink / raw)
  To: notmuch

This patch adds completion with <tab> in the minibuffer for
notmuch-search and notmuch-search-filter.
---
 emacs/notmuch.el |   33 +++++++++++++++++++++++++++++++--
 1 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 3311fe8..49a82be 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -882,6 +882,35 @@ characters as well as `_.+-'.
 	   (concat "*notmuch-search-" query "*"))
 	  )))
 
+(defun notmuch-query-completions (compls string)
+  "Return possible completions for STRING.
+
+COMPLS should be a list of possibilities for an individual word."
+  (cond
+   ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
+    (mapcar (lambda (compl)
+	      (concat (match-string-no-properties 1 string) compl))
+	    (all-completions (match-string-no-properties 2 string)
+			     compls)))
+   (t (list string))))
+
+(defun notmuch-read-query (prompt)
+  "Read a notmuch-query from the minibuffer with completion.
+
+PROMPT is the string to prompt with."
+  (let* ((keymap (copy-keymap minibuffer-local-map))
+	 (all-compls (append (list "folder:" "thread:" "id:" "date:" "from:"
+				   "to:" "subject:" "attachment:")
+			     (mapcar (lambda (tag)
+				       (concat "tag:" tag))
+				     (process-lines "notmuch" "search-tags")))
+	 (minibuffer-completion-table (completion-table-dynamic
+				       `(lambda (s) (notmuch-query-completions
+						(quote ,all-compls) s)))))
+    ;; ^ emulate a closure to avoid recomputing the completion list each time
+    (define-key keymap (kbd "<tab>") 'minibuffer-complete)
+    (read-from-minibuffer prompt nil keymap nil minibuffer-history nil nil)))
+
 ;;;###autoload
 (defun notmuch-search (query &optional oldest-first target-thread target-line continuation)
   "Run \"notmuch search\" with the given query string and display results.
@@ -893,7 +922,7 @@ The optional parameters are used as follows:
                  current if it appears in the search results.
   target-line: The line number to move to if the target thread does not
                appear in the search results."
-  (interactive "sNotmuch search: ")
+  (interactive (notmuch-read-query "Notmuch search: "))
   (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))
     (switch-to-buffer buffer)
     (notmuch-search-mode)
@@ -991,7 +1020,7 @@ search."
 
 Runs a new search matching only messages that match both the
 current search results AND the additional query string provided."
-  (interactive "sFilter search: ")
+  (interactive (notmuch-read-query "Filter search: "))
   (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query)
 			   (concat "( " query " )")
 			 query)))
-- 
1.7.5.3

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

end of thread, other threads:[~2011-11-03  1:19 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-04 12:19 [PATCH] emacs: Tab completion for notmuch-search and notmuch-search-filter Daniel Schoepe
2011-06-04 13:14 ` Daniel Schoepe
2011-06-04 15:32 ` Austin Clements
2011-06-04 19:55   ` Daniel Schoepe
2011-06-04 20:39     ` Daniel Schoepe
2011-06-04 21:55     ` Austin Clements
2011-06-04 22:54       ` Daniel Schoepe
2011-06-06 16:32         ` Daniel Schoepe
2011-08-05 15:17           ` Daniel Schoepe
2011-08-05 21:00             ` Jameson Graef Rollins
2011-08-05 21:03               ` Jameson Graef Rollins
2011-08-06  6:09                 ` Jameson Graef Rollins
2011-08-09 17:31                   ` Daniel Schoepe
2011-08-09 21:41                     ` Jameson Graef Rollins
2011-08-09 17:32                   ` Daniel Schoepe
2011-11-03  1:19                     ` 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).