--- /dev/null
+Return-Path: <uli@scholler.net>\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 0B12A6DE0FF8\r
+ for <notmuch@notmuchmail.org>; Wed, 2 Sep 2015 15:07:37 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ 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 qtExqUGSYogw for <notmuch@notmuchmail.org>;\r
+ Wed, 2 Sep 2015 15:07:34 -0700 (PDT)\r
+X-Greylist: delayed 501 seconds by postgrey-1.35 at arlo;\r
+ Wed, 02 Sep 2015 15:07:34 PDT\r
+Received: from idun.ftbfs.de (idun.ftbfs.de [78.47.2.106])\r
+ by arlo.cworth.org (Postfix) with ESMTP id AFD2F6DE0FB1\r
+ for <notmuch@notmuchmail.org>; Wed, 2 Sep 2015 15:07:34 -0700 (PDT)\r
+Received: from localhost (localidun [10.0.0.76])\r
+ by idun.ftbfs.de (Postfix) with ESMTP id B16B9EC379\r
+ for <notmuch@notmuchmail.org>; Wed, 2 Sep 2015 23:59:09 +0200 (CEST)\r
+Received: from localhost ([10.0.0.76])\r
+ by localhost (idun.ftbfs.de [10.0.0.76]) (amavisd-new, port 2525)\r
+ with SMTP id 14779-18 for <notmuch@notmuchmail.org>;\r
+ Wed, 2 Sep 2015 23:58:10 +0200 (CEST)\r
+Received: from saga.ftbfs.de (unknown [10.0.0.77])\r
+ by idun.ftbfs.de (Postfix) with ESMTP id EB221EC377;\r
+ Wed, 2 Sep 2015 23:58:07 +0200 (CEST)\r
+Received: by saga.ftbfs.de (Postfix, from userid 10)\r
+ id 365231AC0A5; Wed, 2 Sep 2015 23:58:07 +0200 (CEST)\r
+Received: by tardis.scholler.priv (Postfix, from userid 1000)\r
+ id 3019B104; Wed, 2 Sep 2015 23:57:29 +0200 (CEST)\r
+From: Uli Scholler <uli@scholler.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: wrap current search in parens when filtering\r
+Date: Wed, 2 Sep 2015 23:57:14 +0200\r
+Message-Id: <1441231034-9413-1-git-send-email-uli@scholler.net>\r
+X-Mailer: git-send-email 2.1.4\r
+X-Virus-Scanned: at idun.ftbfs.de with p-bank undefined\r
+X-Mailman-Approved-At: Thu, 03 Sep 2015 00:24:54 -0700\r
+Cc: Uli Scholler <uli@scholler.net>\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: Wed, 02 Sep 2015 22:07:37 -0000\r
+\r
+When filtering the current search further with notmuch-search-filter,\r
+wrap the current search in parens.\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
+ emacs/notmuch.el | 2 +-\r
+ 1 file changed, 1 insertion(+), 1 deletion(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 5284e77..a98ec96 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -989,7 +989,7 @@ current search results AND the additional query string provided."\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
++ (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
+-- \r
+2.1.4\r
+\r
+\r