--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 5A449431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 17 Apr 2014 12:02:41 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[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 HKLiy9cSAu+c for <notmuch@notmuchmail.org>;\r
+ Thu, 17 Apr 2014 12:02:35 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (dmz-mailsec-scanner-2.mit.edu\r
+ [18.9.25.13])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id DD284431FAE\r
+ for <notmuch@notmuchmail.org>; Thu, 17 Apr 2014 12:02:34 -0700 (PDT)\r
+X-AuditID: 1209190d-f79776d000000ce9-69-535021c35ac3\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 60.77.03305.3C120535; Thu, 17 Apr 2014 14:47:31 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s3HIlTUi010524; \r
+ Thu, 17 Apr 2014 14:47:30 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s3HIlRSJ024875\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+ Thu, 17 Apr 2014 14:47:28 -0400\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1WarLE-0001GG-Vi; Thu, 17 Apr 2014 14:47:23 -0400\r
+Date: Thu, 17 Apr 2014 14:47:19 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH] emacs: search: edit current query\r
+Message-ID: <20140417184718.GB3943@mit.edu>\r
+References: <1397713404-3089-1-git-send-email-markwalters1009@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <1397713404-3089-1-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmpkleLIzCtJLcpLzFFi42IRYrdT0T2sGBBscP2chMXquTwW12/OZHZg\r
+ 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mk5e+8pe8Ful4uiuTUwNjGtluxg5OSQETCQu\r
+ Xz3NDGGLSVy4t54NxBYSmM0ksfCeQhcjF5C9kVHia983ZgjnNJPE9xnLGCGcJYwS0+ZcB2tn\r
+ EVCVeLn4FwuIzSagIbFt/3JGEFtEQEfi9qEF7CA2s4C0xLffzUxdjBwcwgJmEnPvlIOEeQW0\r
+ JZ5u3cQEsdlD4sH8WWwQcUGJkzOfsEC0aknc+PcSrBVkzPJ/HCBhTgFPiWlf1oC1igqoSEw5\r
+ uY1tAqPQLCTds5B0z0LoXsDIvIpRNiW3Sjc3MTOnODVZtzg5MS8vtUjXSC83s0QvNaV0EyMo\r
+ pDkleXcwvjuodIhRgINRiYf3wlf/YCHWxLLiytxDjJIcTEqivDPkAoKF+JLyUyozEosz4otK\r
+ c1KLDzFKcDArifDWKQDleFMSK6tSi/JhUtIcLErivG+trYKFBNITS1KzU1MLUotgsjIcHEoS\r
+ vEdBGgWLUtNTK9Iyc0oQ0kwcnCDDeYCGt4MNLy5IzC3OTIfIn2JUlBLnvQKSEABJZJTmwfXC\r
+ Us4rRnGgV4R554FU8QDTFVz3K6DBTECDD4X7ggwuSURISTUwGmzZe3aP8bXSSUkLwp4VLGCQ\r
+ brh8oabw1Gb9ukNS876WbYpp6rg5I+f+Z5EK5ZVKxZev73i3d/NHjb6pkWYp99nqNkQFl79b\r
+ a776vlre29bXZaJhs83/bdng6iKYY58otWRex48JXdxb51slif57s/e6rvbbM6z95xRWOH3Z\r
+ v+z2QgazzJY/LUosxRmJhlrMRcWJACs1DP4UAwAA\r
+Cc: notmuch@notmuchmail.org\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: Thu, 17 Apr 2014 19:02:41 -0000\r
+\r
+You can *almost* do this already with the search minibuffer history.\r
+As far as I can tell, the only thing missing is modifying a search\r
+that started as a saved search. We could fix that by simply adding\r
+saved searches to this history (and possibly filtering saved searches\r
+out for the hello "recent searches" widget).\r
+\r
+Quoth Mark Walters on Apr 17 at 6:43 am:\r
+> This adds an option to edit the current query. It is bound to\r
+> prefix-key f as it is a sort of inverse operation to filtering.\r
+> ---\r
+> rlb asked for the option to modify the existing search query on\r
+> irc. This implements that for the search view.\r
+> \r
+> Best wishes\r
+> \r
+> Mark \r
+> \r
+> \r
+> \r
+> \r
+> \r
+> emacs/notmuch.el | 37 ++++++++++++++++++++++++++-----------\r
+> 1 file changed, 26 insertions(+), 11 deletions(-)\r
+> \r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index 6c0bc1b..b4408f1 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -848,7 +848,7 @@ See `notmuch-tag' for information on the format of TAG-CHANGES."\r
+> (concat "*notmuch-search-" query "*"))\r
+> )))\r
+> \r
+> -(defun notmuch-read-query (prompt)\r
+> +(defun notmuch-read-query (prompt &optional initial-contents)\r
+> "Read a notmuch-query from the minibuffer with completion.\r
+> \r
+> PROMPT is the string to prompt with."\r
+> @@ -876,7 +876,7 @@ PROMPT is the string to prompt with."\r
+> ;; this was simpler than convincing completing-read to accept spaces:\r
+> (define-key keymap (kbd "TAB") 'minibuffer-complete)\r
+> (let ((history-delete-duplicates t))\r
+> - (read-from-minibuffer prompt nil keymap nil\r
+> + (read-from-minibuffer prompt initial-contents keymap nil\r
+> 'notmuch-search-history nil nil)))))\r
+> \r
+> ;;;###autoload\r
+> @@ -963,18 +963,33 @@ default sort order is defined by `notmuch-search-oldest-first'."\r
+> (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first))\r
+> (notmuch-search-refresh-view))\r
+> \r
+> -(defun notmuch-search-filter (query)\r
+> +(put 'notmuch-search-filter 'notmuch-doc\r
+> + "Filter the current search results based on an additional query string.")\r
+\r
+Since this is purely user-facing, you could drop the word "string".\r
+\r
+> +(put 'notmuch-search-filter 'notmuch-prefix-doc\r
+> + "Edit the current search query.")\r
+> +(defun notmuch-search-filter (modify query)\r
+\r
+This could easily be kept backwards compatible by changing this to\r
+something like (query &optional replace).\r
+\r
+> "Filter the current search results based on an additional query string.\r
+> \r
+> Runs a new search matching only messages that match both the\r
+> -current search results AND the additional query string provided."\r
+> - (interactive (list (notmuch-read-query "Filter search: ")))\r
+> - (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query)\r
+> - (concat "( " query " )")\r
+> - query)))\r
+> - (notmuch-search (if (string= notmuch-search-query-string "*")\r
+> - grouped-query\r
+> - (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first)))\r
+> +current search results AND the additional query string provided.\r
+> +\r
+> +If called with a prefix-arg then present the user with the\r
+> +existing query string to allow the user to edit it."\r
+\r
+The documentation doesn't say how the Lisp-oriented interface to this\r
+works. How about\r
+\r
+ "Runs a new search based on the current search query.\r
+\r
+If REPLACE is non-nil, starts a search for QUERY. If REPLACE is nil\r
+or omitted, starts a search for the current buffer's query \"and\"\r
+QUERY. In both cases, this uses the same options as the current\r
+search buffer.\r
+\r
+If called interactively with a prefix argument, prompts the user to\r
+edit the current query. Otherwise, prompts for a filter query."\r
+\r
+> + (interactive (let ((query-string (if current-prefix-arg\r
+> + "Modify Search: "\r
+> + "Filter Search: "))\r
+> + (initial-contents (if current-prefix-arg\r
+> + notmuch-search-query-string\r
+> + nil)))\r
+> + (list current-prefix-arg (notmuch-read-query query-string initial-contents))))\r
+> + (if modify\r
+> + (notmuch-search query notmuch-search-oldest-first)\r
+> + (let ((grouped-query (if (string-match-p notmuch-search-disjunctive-regexp query)\r
+\r
+I can think of so many ways to break this heuristic... But that's not\r
+really this patch's concern.\r
+\r
+> + (concat "( " query " )")\r
+> + query)))\r
+> + (notmuch-search (if (string= notmuch-search-query-string "*")\r
+> + grouped-query\r
+> + (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first))))\r
+> \r
+> (defun notmuch-search-filter-by-tag (tag)\r
+> "Filter the current search results based on a single tag.\r