From f47eeac0b0186c3559eb559c4f0bee0e1fac1961 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Mon, 23 Jun 2014 22:06:46 +0100 Subject: [PATCH] emacs: set default in notmuch-read-query 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 be called via notmuch-search/notmuch-tree etc from any buffer so it makes sense to put the decision of how to extract the current query in notmuch-read-query rather than in each of the callers. --- emacs/notmuch-show.el | 9 +++++++++ emacs/notmuch-tree.el | 9 +++++++++ emacs/notmuch.el | 10 +++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index b8e24bc7..2c6c89e9 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -1203,6 +1203,15 @@ This includes: - the current message." (list (notmuch-show-get-message-id) (notmuch-show-get-message-ids-for-open-messages))) +(defun notmuch-show-get-query () + "Return the current query in this show buffer" + (if notmuch-show-query-context + (concat notmuch-show-thread-id + " and (" + notmuch-show-query-context + ")") + notmuch-show-thread-id)) + (defun notmuch-show-apply-state (state) "Apply STATE to the current buffer. diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index 7d5f4750..e9249da1 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -897,6 +897,15 @@ the same as for the function notmuch-tree." (set-process-filter proc 'notmuch-tree-process-filter) (set-process-query-on-exit-flag proc nil)))) +(defun notmuch-tree-get-query () + "Return the current query in this tree buffer" + (if notmuch-tree-query-context + (concat notmuch-tree-basic-query + " and (" + notmuch-tree-query-context + ")") + notmuch-tree-basic-query)) + (defun notmuch-tree (&optional query query-context target buffer-name open-target) "Display threads matching QUERY in Tree View. diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 2a9876fd..b44a907a 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -863,6 +863,10 @@ PROMPT is the string to prompt with." (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-get-query)) + (notmuch-show-mode (notmuch-show-get-query)) + (notmuch-tree-mode (notmuch-tree-get-query)))) (minibuffer-completion-table (completion-table-dynamic (lambda (string) @@ -880,7 +884,11 @@ PROMPT is the string to prompt with." (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))))) + +(defun notmuch-search-get-query () + "Return the current query in this search buffer" + notmuch-search-query-string) ;;;###autoload (put 'notmuch-search 'notmuch-doc "Search for messages.") -- 2.26.2