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