--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 499726DE1649\r
+ for <notmuch@notmuchmail.org>; Sun, 6 Sep 2015 23:16:12 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.801\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.801 tagged_above=-999 required=5 tests=[AWL=0.149, \r
+ SPF_NEUTRAL=0.652] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 4nnT8FnKGt2u for <notmuch@notmuchmail.org>;\r
+ Sun, 6 Sep 2015 23:16:06 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by arlo.cworth.org (Postfix) with ESMTP id BB1006DE1641\r
+ for <notmuch@notmuchmail.org>; Sun, 6 Sep 2015 23:16:04 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 234CF100033;\r
+ Mon, 7 Sep 2015 09:14:34 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Uli Scholler <uli@scholler.net>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3] emacs: wrap current search in parens when filtering\r
+In-Reply-To: <1441574945-28437-1-git-send-email-uli@scholler.net>\r
+References: <m2mvwz29dg.fsf@guru.guru-group.fi>\r
+ <1441574945-28437-1-git-send-email-uli@scholler.net>\r
+User-Agent: Notmuch/0.20.2+68~g0c35549 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Mon, 07 Sep 2015 09:14:33 +0300\r
+Message-ID: <m2r3maiwmu.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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: Mon, 07 Sep 2015 06:16:12 -0000\r
+\r
+On Mon, Sep 07 2015, Uli Scholler <uli@scholler.net> wrote:\r
+\r
+> When filtering the current search further with notmuch-search-filter,\r
+> wrap the current search in parens (if necessary).\r
+>\r
+> This fixes unexpected behavior when the current search is\r
+> complex (like "(tag:this and date:one_week_ago..) or tag:that").\r
+> ---\r
+\r
+LGTM. Works fine (the first time I used 'f', which is just too bad ;/) +1\r
+\r
+Tomi\r
+\r
+> emacs/notmuch.el | 20 +++++++++++++++-----\r
+> 1 file changed, 15 insertions(+), 5 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index 5284e77..463b926 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -978,18 +978,28 @@ 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-group-disjunctive-query-string (query-string)\r
+> + "Group query if it contains a complex expression.\r
+> +\r
+> +Enclose QUERY-STRING in parentheses if it matches\r
+> +`notmuch-search-disjunctive-regexp'."\r
+> + (if (string-match-p notmuch-search-disjunctive-regexp query-string)\r
+> + (concat "( " query-string " )")\r
+> + query-string))\r
+> +\r
+> (defun notmuch-search-filter (query)\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
+> + (let ((grouped-query (notmuch-group-disjunctive-query-string query))\r
+> + (grouped-original-query (notmuch-group-disjunctive-query-string\r
+> + notmuch-search-query-string)))\r
+> + (notmuch-search (if (string= grouped-original-query "*")\r
+> grouped-query\r
+> - (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first)))\r
+> + (concat grouped-original-query " and " grouped-query))\r
+> + 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
+> -- \r
+> 2.1.4\r
+>\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r