--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 084F7431FDA\r
+ for <notmuch@notmuchmail.org>; Sat, 3 May 2014 09:13:11 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.7\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.7 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ FREEMAIL_REPLY=2.499, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id twkGEGoGPltL for <notmuch@notmuchmail.org>;\r
+ Sat, 3 May 2014 09:13:07 -0700 (PDT)\r
+Received: from mail-we0-f172.google.com (mail-we0-f172.google.com\r
+ [74.125.82.172]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id C2C2C431FAF\r
+ for <notmuch@notmuchmail.org>; Sat, 3 May 2014 09:13:06 -0700 (PDT)\r
+Received: by mail-we0-f172.google.com with SMTP id k48so73715wev.17\r
+ for <notmuch@notmuchmail.org>; Sat, 03 May 2014 09:13:05 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id;\r
+ bh=G1eEnXDYcUy+DtIGQ4urUkYTQML/9hoYfaPfam08HA8=;\r
+ b=OcK5zMWn8bDEx+2LblWRMsZvQDjpoPt98ctyIlOeoM0fqm4h5JsBX7lpBwNNfRymQz\r
+ iGCTkxo9jFe3XHCHX06ug2GNPmhUAGgnZG2R4e2UV5j7na/K5C+9R0FbECKrdkrE+P90\r
+ 6NcTx/NbXJsnLFUZktV4tIX5y18sSIQ0He+PCITvvmI+yzaVdzpOQDjW9yIxwflzDQuu\r
+ /KY4MPcS2V+D88q8Ix77aGN5FCCizO174hq3ExRxLs+dwTkgJomSN3xw31pbzkN5GECY\r
+ N4xomtVFBaLWVqtAHH+nZl4VYZTLv9n1ieKQyMQ8N3sEwuEki7KIupVfBUtKd4ADKflt\r
+ facQ==\r
+X-Received: by 10.194.189.116 with SMTP id gh20mr19383394wjc.41.1399133585456;\r
+ Sat, 03 May 2014 09:13:05 -0700 (PDT)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by mx.google.com with ESMTPSA id n5sm4987717wiz.1.2014.05.03.09.13.04\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sat, 03 May 2014 09:13:04 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: put current query as default value in\r
+ notmuch-read-query\r
+Date: Sat, 3 May 2014 17:12:59 +0100\r
+Message-Id: <1399133579-9106-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 03 May 2014 16:13:11 -0000\r
+\r
+This adds the current query as a "default value" to\r
+notmuch-read-qeury. The default value is available via a down-arrow as\r
+opposed to history which is available from the up arrow.\r
+\r
+Note if a user presses return in the minibuffer this value is not\r
+returned.\r
+\r
+The implementation is simple but notmuch-read-query could via\r
+notmuch-search/notmuch-tree etc from any buffer so it makes sense to\r
+put the logic extracting the current query in notmuch-read-query\r
+rather than in each of the callers.\r
+---\r
+\r
+This is another approach to\r
+id:1397713404-3089-1-git-send-email-markwalters1009@gmail.com which is\r
+closer in spirit to Austin's suggestion in his reply and comments on\r
+irc and is based on Jani's suggestion on irc.\r
+\r
+The basic idea is to add the current query to the completing read as a\r
+default-value so it accessible via down-arrow.\r
+\r
+The implementation is slightly unnatural as the function calling\r
+notmuch-read-query is normally the function which perform the new\r
+search (ie the new mode) so it does not know how to extract the\r
+current query from the current mode. Thus we put the logic to that in\r
+notmuch-read-query rather than the caller.\r
+\r
+The other subtlety is that notmuch-show (and notmuch tree) have a more\r
+complicated form for the query. In notmuch show this is thread-id and\r
+context; notmuch-show tries the query "thread-id and context" and if\r
+that gives no results it drops back to just "thread-id". In this\r
+version we always return "thread-id and context" as the query. This is\r
+not obviously correct, but not obviously wrong either.\r
+\r
+An alternative to putting the logic in notmuch-read-query would be to\r
+store the query in a consistently named buffer local variable in all\r
+the modes. If we want to show the actually run query in notmuch-show\r
+above then this is probably the neatest solution.\r
+\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+\r
+\r
+\r
+ emacs/notmuch.el | 16 +++++++++++++++-\r
+ 1 file changed, 15 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 6c0bc1b..1b6bde1 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -860,6 +860,20 @@ (defun notmuch-read-query (prompt)\r
+ (concat "tag:" (notmuch-escape-boolean-term tag)))\r
+ (process-lines notmuch-command "search" "--output=tags" "*")))))\r
+ (let ((keymap (copy-keymap minibuffer-local-map))\r
++ (current-query (case major-mode\r
++ (notmuch-search-mode notmuch-search-query-string)\r
++ (notmuch-show-mode (if notmuch-show-query-context\r
++ (concat notmuch-show-thread-id\r
++ " and ("\r
++ notmuch-show-query-context\r
++ ")")\r
++ notmuch-show-thread-id))\r
++ (notmuch-tree-mode (if notmuch-tree-query-context\r
++ (concat notmuch-tree-basic-query\r
++ " and ("\r
++ notmuch-tree-query-context\r
++ ")")\r
++ notmuch-tree-basic-query))))\r
+ (minibuffer-completion-table\r
+ (completion-table-dynamic\r
+ (lambda (string)\r
+@@ -877,7 +891,7 @@ (defun notmuch-read-query (prompt)\r
+ (define-key keymap (kbd "TAB") 'minibuffer-complete)\r
+ (let ((history-delete-duplicates t))\r
+ (read-from-minibuffer prompt nil keymap nil\r
+- 'notmuch-search-history nil nil)))))\r
++ 'notmuch-search-history current-query nil)))))\r
+ \r
+ ;;;###autoload\r
+ (put 'notmuch-search 'notmuch-doc "Search for messages.")\r
+-- \r
+1.7.10.4\r
+\r