[PATCH] emacs: put current query as default value in notmuch-read-query

Mark Walters markwalters1009 at gmail.com
Sat May 3 09:12:59 PDT 2014


This adds the current query as a "default value" to
notmuch-read-qeury. The default value is available via a down-arrow as
opposed to history which is available from the up arrow.

Note if a user presses return in the minibuffer this value is not
returned.

The implementation is simple but notmuch-read-query could via
notmuch-search/notmuch-tree etc from any buffer so it makes sense to
put the logic extracting the current query in notmuch-read-query
rather than in each of the callers.
---

This is another approach to
id:1397713404-3089-1-git-send-email-markwalters1009 at gmail.com which is
closer in spirit to Austin's suggestion in his reply and comments on
irc and is based on Jani's suggestion on irc.

The basic idea is to add the current query to the completing read as a
default-value so it accessible via down-arrow.

The implementation is slightly unnatural as the function calling
notmuch-read-query is normally the function which perform the new
search (ie the new mode) so it does not know how to extract the
current query from the current mode. Thus we put the logic to that in
notmuch-read-query rather than the caller.

The other subtlety is that notmuch-show (and notmuch tree) have a more
complicated form for the query. In notmuch show this is thread-id and
context; notmuch-show tries the query "thread-id and context" and if
that gives no results it drops back to just "thread-id". In this
version we always return "thread-id and context" as the query. This is
not obviously correct, but not obviously wrong either.

An alternative to putting the logic in notmuch-read-query would be to
store the query in a consistently named buffer local variable in all
the modes. If we want to show the actually run query in notmuch-show
above then this is probably the neatest solution.


Best wishes

Mark





 emacs/notmuch.el |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6c0bc1b..1b6bde1 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -860,6 +860,20 @@ (defun notmuch-read-query (prompt)
 			  (concat "tag:" (notmuch-escape-boolean-term tag)))
 			(process-lines notmuch-command "search" "--output=tags" "*")))))
     (let ((keymap (copy-keymap minibuffer-local-map))
+	  (current-query (case major-mode
+			   (notmuch-search-mode notmuch-search-query-string)
+			   (notmuch-show-mode (if notmuch-show-query-context
+						  (concat notmuch-show-thread-id
+							  " and ("
+							  notmuch-show-query-context
+							  ")")
+						notmuch-show-thread-id))
+			   (notmuch-tree-mode (if notmuch-tree-query-context
+						  (concat notmuch-tree-basic-query
+							  " and ("
+							  notmuch-tree-query-context
+							  ")")
+						notmuch-tree-basic-query))))
 	  (minibuffer-completion-table
 	   (completion-table-dynamic
 	    (lambda (string)
@@ -877,7 +891,7 @@ (defun notmuch-read-query (prompt)
       (define-key keymap (kbd "TAB") 'minibuffer-complete)
       (let ((history-delete-duplicates t))
 	(read-from-minibuffer prompt nil keymap nil
-			      'notmuch-search-history nil nil)))))
+			      'notmuch-search-history current-query nil)))))
 
 ;;;###autoload
 (put 'notmuch-search 'notmuch-doc "Search for messages.")
-- 
1.7.10.4



More information about the notmuch mailing list