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 19FDC431FBF for ; Mon, 23 Nov 2009 10:07:12 -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 kWMPwgP64IOM for ; Mon, 23 Nov 2009 10:07:11 -0800 (PST) Received: from mail-bw0-f210.google.com (mail-bw0-f210.google.com [209.85.218.210]) by olra.theworths.org (Postfix) with ESMTP id E73D7431FAE for ; Mon, 23 Nov 2009 10:07:10 -0800 (PST) Received: by bwz2 with SMTP id 2so5521364bwz.0 for ; Mon, 23 Nov 2009 10:07:10 -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=wS1uR8Jzdr43cW2h/O5cK1D7IcDlwzYrpX1lxKOpacs=; b=G14ZeXGQRamEZuTBuqLCDRbRaOBcdBXjewGh+oiXntOSsK3B4k/sVdl55Xa4jJGaVo CZGbXFmACmLqLLTHkPy34SLE9i9g8flr61JLDYHqeRZjQhwuNWHTHQUjbZa/3SwmBGR5 2S3744/ux7TVms/qdXflBD9YpATa6MWIQW9q8= 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=cQ3DRQouHVdr3lDoCP5pn6zQ3Tpd0enj3K0NWGiU4gGUl8x32XL+vJDIxkcsHVV0TM HcoXdNl861xZhRn+ms4CY6Qwj1xrday9aP7UH9UinV2yzX9PJZTWD8vPm5+yiKvU+jpV ZCsSulM+59hKdlqoNNfPfEk4kbX/fp4jo1ZHU= Received: by 10.204.49.68 with SMTP id u4mr5108142bkf.42.1258999629698; Mon, 23 Nov 2009 10:07:09 -0800 (PST) Received: from localhost.localdomain (vawpc43.ethz.ch [129.132.59.11]) by mx.google.com with ESMTPS id 9sm6053600fks.52.2009.11.23.10.07.08 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 23 Nov 2009 10:07:08 -0800 (PST) Sender: Jed Brown From: Jed Brown To: notmuch@notmuchmail.org, cworth@cworth.org Date: Mon, 23 Nov 2009 19:07:23 +0100 Message-Id: <1258999643-30742-1-git-send-email-jed@59A2.org> X-Mailer: git-send-email 1.6.5.3 In-Reply-To: <1258976966-22407-1-git-send-email-jed@59A2.org> References: <1258976966-22407-1-git-send-email-jed@59A2.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 18:07:12 -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. This version has nice regexes and handles NOT. Signed-off-by: Jed Brown --- notmuch.el | 27 ++++++++++++++++++++++----- 1 files changed, 22 insertions(+), 5 deletions(-) diff --git a/notmuch.el b/notmuch.el index 0cabbe2..fdd30ae 100644 --- a/notmuch.el +++ b/notmuch.el @@ -828,6 +828,10 @@ thread from that buffer can be show when done with this one)." (defvar notmuch-search-query-string) (defvar notmuch-search-oldest-first) +(defvar notmuch-search-boolean-operator-regexp "\\([aA][nN][dD]\\|[oO][rR]\\|[nN][oO][tT]\\)") +(defvar notmuch-search-valid-term-regexp "\\([-+_.[:word:]]+\\)") +(defvar notmuch-search-disjunctive-regexp "\\<[oO][rR]\\>") + (defun notmuch-search-scroll-up () "Scroll up, moving point to last message in thread if at end." (interactive) @@ -1057,15 +1061,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 notmuch-search-disjunctive-regexp 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 notmuch-search-valid-term-regexp + (lambda (match) ; Prepend `tag:' to all except boolean operators + (if (string-match-p notmuch-search-boolean-operator-regexp 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