Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 53B156DE1B96 for ; Thu, 3 Sep 2015 15:02:37 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.009 X-Spam-Level: X-Spam-Status: No, score=0.009 tagged_above=-999 required=5 tests=[AWL=-0.001, T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j8vPUvJ_NQpO for ; Thu, 3 Sep 2015 15:02:34 -0700 (PDT) X-Greylist: delayed 441 seconds by postgrey-1.35 at arlo; Thu, 03 Sep 2015 15:02:34 PDT Received: from idun.ftbfs.de (idun.ftbfs.de [78.47.2.106]) by arlo.cworth.org (Postfix) with ESMTP id 7C5576DE1B92 for ; Thu, 3 Sep 2015 15:02:34 -0700 (PDT) Received: from localhost (localidun [10.0.0.76]) by idun.ftbfs.de (Postfix) with ESMTP id 7FABCEC390 for ; Thu, 3 Sep 2015 23:55:09 +0200 (CEST) Received: from localhost ([10.0.0.76]) by localhost (idun.ftbfs.de [10.0.0.76]) (amavisd-new, port 2525) with SMTP id 06987-29 for ; Thu, 3 Sep 2015 23:55:09 +0200 (CEST) Received: from saga.ftbfs.de (unknown [10.0.0.77]) by idun.ftbfs.de (Postfix) with ESMTP id 19D3FEC38A for ; Thu, 3 Sep 2015 23:55:08 +0200 (CEST) Received: by saga.ftbfs.de (Postfix, from userid 10) id AC88B5C8AD; Thu, 3 Sep 2015 23:55:08 +0200 (CEST) Received: by tardis.scholler.priv (Postfix, from userid 1000) id EE92B104; Thu, 3 Sep 2015 23:54:43 +0200 (CEST) From: Uli Scholler To: notmuch@notmuchmail.org Subject: [PATCH v2] emacs: wrap current search in parens when filtering In-Reply-To: References: <1441231034-9413-1-git-send-email-uli@scholler.net> User-Agent: Notmuch/0.18.2 (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) Date: Thu, 03 Sep 2015 23:54:43 +0200 Message-ID: <87io7rxj6k.fsf@tardis.scholler.priv> MIME-Version: 1.0 Content-Type: text/plain X-Virus-Scanned: at idun.ftbfs.de with p-bank undefined X-Mailman-Approved-At: Thu, 03 Sep 2015 22:38:13 -0700 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.18 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, 03 Sep 2015 22:02:37 -0000 Tomi Ollila writes: > But should this do the same "notmuch-search-disjunctive-regexp" check > which is done when building up `grouped-query' ? Here is an improved version of my patch: --- When filtering the current search further with notmuch-search-filter, wrap the current search in parens if necessary. This fixes unexpected behavior when the current search is complex (like "(tag:this and date:one_week_ago..) or tag:that"). --- emacs/notmuch.el | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 5284e77..e5e677f 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -978,18 +978,26 @@ 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-maybe-group-query-string (query-string) + "Group query if it contains a complex expression. + +Enclose QUERY-STRING in parentheses if it matches +`notmuch-search-disjunctive-regexp'." + (if (string-match-p notmuch-search-disjunctive-regexp query-string) + (concat "( " query-string " )") + query-string)) + (defun notmuch-search-filter (query) "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 "*") + (let ((grouped-query (notmuch-maybe-group-query-string query)) + (grouped-search-query (notmuch-maybe-group-query-string notmuch-search-query-string))) + (notmuch-search (if (string= grouped-search-query "*") grouped-query - (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first))) + (concat grouped-search-query " and " grouped-query)) notmuch-search-oldest-first))) (defun notmuch-search-filter-by-tag (tag) "Filter the current search results based on a single tag. -- 2.1.4