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 B2AED431FAE for ; Mon, 23 Nov 2009 03:49:23 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 2Zkpyb4bmIID for ; Mon, 23 Nov 2009 03:49:23 -0800 (PST) Received: from mail-bw0-f224.google.com (mail-bw0-f224.google.com [209.85.218.224]) by olra.theworths.org (Postfix) with ESMTP id 5D75D431FBC for ; Mon, 23 Nov 2009 03:49:23 -0800 (PST) Received: by bwz24 with SMTP id 24so3822957bwz.30 for ; Mon, 23 Nov 2009 03:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references; bh=iuKdFrIKdLQ/hBFi8k/ISM1H4H6uBpGjdpo3hB/jKPM=; b=yC989HGVj05xnVXme6xOzARMVDfzhptG3RlqQGynz6eUWjio5QCTARE9XK6dYiyz7u KyE8ihHEvThdXssZhTq8iFGfXeVbLYHhfxlMO8c4JrMbrjt/Vvibugc87TuujGGwrGAv cS9O10Vzwb5nhsOGy57rW/MZ6EzN9ZSMPzAIA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=K+5M1JlWNNPU9mFsr/JMlqDayw/sOi33sSdZbsHDDf+6KspAaC4vcik9al+wK4DzeN BCvRKwWQH7cDWQOOgp+xPnw/abPHnlfCzQOmNZLDyLy5ZxntRJ6wKSJkAgrNM8AvJrRN 18eqJG/HqPo/ukvEOGSv+6k/iUTtbYTFr85bA= Received: by 10.204.33.140 with SMTP id h12mr4523547bkd.167.1258976961606; Mon, 23 Nov 2009 03:49:21 -0800 (PST) Received: from localhost.localdomain (vawpc43.ethz.ch [129.132.59.11]) by mx.google.com with ESMTPS id 12sm5582609fks.9.2009.11.23.03.49.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 23 Nov 2009 03:49:20 -0800 (PST) Sender: Jed Brown From: Jed Brown To: notmuch@notmuchmail.org, cworth@cworth.org Date: Mon, 23 Nov 2009 12:49:26 +0100 Message-Id: <1258976966-22407-1-git-send-email-jed@59A2.org> X-Mailer: git-send-email 1.6.5.3 In-Reply-To: <87k4xhg8hq.fsf@yoom.home.cworth.org> References: <87k4xhg8hq.fsf@yoom.home.cworth.org> Subject: [notmuch] [PATCH] Make search filters handle disjunctive queries. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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, 23 Nov 2009 11:49:23 -0000 notmuch-search-filter accepts now accepts an arbitrary query and will group if necessary so that we get tag:inbox AND (gravy OR biscuits) notmuch-search-filter-tag now handles multiple terms. All terms in the query except AND and OR are interpreted as tags. Signed-off-by: Jed Brown --- notmuch.el | 23 ++++++++++++++++++----- 1 files changed, 18 insertions(+), 5 deletions(-) diff --git a/notmuch.el b/notmuch.el index 0cabbe2..43e0566 100644 --- a/notmuch.el +++ b/notmuch.el @@ -1057,15 +1057,28 @@ search." Runs a new search matching only messages that match both the current search results AND the additional query string provided." (interactive "sFilter search: ") - (notmuch-search (concat notmuch-search-query-string " and " query) notmuch-search-oldest-first)) + (let ((grouped-query (if (string-match-p "\\<[oO][rR]\\>" query) (concat "( " query " )") query))) + (notmuch-search (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. +(defun notmuch-search-filter-by-tag (query) + "Filter the current search results based on one or more tags. Runs a new search matching only messages that match both the -current search results AND that are tagged with the given tag." +current search results AND that are tagged with the given +expression involving tags. For example, the input + + chicken and (gravy or biscuits) + +will filter the current search by + + tag:chicken and ( tag:gravy or tag:biscuits )" (interactive "sFilter by tag: ") - (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first)) + (let ((tagged-query (replace-regexp-in-string "\\([_\+\-]\\|\\w\\)+" + (lambda (match) ; Prepend `tag:' to all matches except AND and OR + (if (string-match-p "\\([aA][nN][dD]\\)\\|\\([oO][rR]\\)" match) + match (concat "tag:" match))) + query))) + (notmuch-search-filter tagged-query))) (defun notmuch () "Run notmuch to display all mail with tag of 'inbox'" -- 1.6.5.3