]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: set default in notmuch-read-query
authorMark Walters <markwalters1009@gmail.com>
Mon, 23 Jun 2014 21:06:46 +0000 (22:06 +0100)
committerDavid Bremner <david@tethera.net>
Tue, 15 Jul 2014 23:32:49 +0000 (20:32 -0300)
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
emacs/notmuch-tree.el
emacs/notmuch.el

index b8e24bc7816f1b7c68926ea03bf2dc12b36d54d9..2c6c89e9ecdd3f64966c46e2155b4f1518f80d48 100644 (file)
@@ -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.
 
index 7d5f475080cbae5d6708206173b75884af3cdd86..e9249da11c290cbd8625ece623fa29884b36d655 100644 (file)
@@ -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.
 
index 2a9876fddbeb69ce482cc4b7cfd75288dabfcd24..b44a907a74c7eb7d8ea4320176417a3534d3d55f 100644 (file)
@@ -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.")