From ef5daae51deb9af00ca908faa621ae3598459987 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Mon, 7 Sep 2015 09:14:33 +0300 Subject: [PATCH] Re: [PATCH v3] emacs: wrap current search in parens when filtering --- 12/ae5ec5f169ef711c1a4e2718a56e542cada16c | 113 ++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 12/ae5ec5f169ef711c1a4e2718a56e542cada16c diff --git a/12/ae5ec5f169ef711c1a4e2718a56e542cada16c b/12/ae5ec5f169ef711c1a4e2718a56e542cada16c new file mode 100644 index 000000000..fc4e50b31 --- /dev/null +++ b/12/ae5ec5f169ef711c1a4e2718a56e542cada16c @@ -0,0 +1,113 @@ +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 499726DE1649 + for ; Sun, 6 Sep 2015 23:16:12 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.801 +X-Spam-Level: +X-Spam-Status: No, score=0.801 tagged_above=-999 required=5 tests=[AWL=0.149, + SPF_NEUTRAL=0.652] 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 4nnT8FnKGt2u for ; + Sun, 6 Sep 2015 23:16:06 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by arlo.cworth.org (Postfix) with ESMTP id BB1006DE1641 + for ; Sun, 6 Sep 2015 23:16:04 -0700 (PDT) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 234CF100033; + Mon, 7 Sep 2015 09:14:34 +0300 (EEST) +From: Tomi Ollila +To: Uli Scholler , notmuch@notmuchmail.org +Subject: Re: [PATCH v3] emacs: wrap current search in parens when filtering +In-Reply-To: <1441574945-28437-1-git-send-email-uli@scholler.net> +References: + <1441574945-28437-1-git-send-email-uli@scholler.net> +User-Agent: Notmuch/0.20.2+68~g0c35549 (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +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: Mon, 07 Sep 2015 06:16:12 -0000 + +On Mon, Sep 07 2015, Uli Scholler wrote: + +> 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"). +> --- + +LGTM. Works fine (the first time I used 'f', which is just too bad ;/) +1 + +Tomi + +> emacs/notmuch.el | 20 +++++++++++++++----- +> 1 file changed, 15 insertions(+), 5 deletions(-) +> +> diff --git a/emacs/notmuch.el b/emacs/notmuch.el +> index 5284e77..463b926 100644 +> --- a/emacs/notmuch.el +> +++ b/emacs/notmuch.el +> @@ -978,18 +978,28 @@ 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-group-disjunctive-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-group-disjunctive-query-string query)) +> + (grouped-original-query (notmuch-group-disjunctive-query-string +> + notmuch-search-query-string))) +> + (notmuch-search (if (string= grouped-original-query "*") +> grouped-query +> - (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first))) +> + (concat grouped-original-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 +> +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2