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 AC93140DF1C for ; Fri, 19 Nov 2010 10:41:34 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.346 X-Spam-Level: X-Spam-Status: No, score=-0.346 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1.553, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=no 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 npB9mRO5Ggyq for ; Fri, 19 Nov 2010 10:41:24 -0800 (PST) Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com [209.85.161.53]) by olra.theworths.org (Postfix) with ESMTP id 43ECD40DF18 for ; Fri, 19 Nov 2010 10:41:24 -0800 (PST) Received: by fxm10 with SMTP id 10so57396fxm.26 for ; Fri, 19 Nov 2010 10:41:23 -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=ix5jdOaj4b2te6RO/lnNc2oy99I/wD9zMXgTzMFizD0=; b=ekvUijRGBHXDlzRvU8KlVgfztRUlS3f56KW4BnCVJhAKA5sLpK1IzyaoiXYuEs1xd7 BZsey+ESv0qsN6xA0Vl9HCtuDWFjye6FGLdD1+41R3xmGONi1F0qNCpCSNObTHkHOx5O M5xf1wap9VC/bMrDX2He+oNRgilRQrbH4LppQ= 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=hlMWKiLBKithKvMcqNj1Mi7BY/vyXz+OQcfICM5j07q+OTuADLk6BGbRzUsmB6Mec+ lZMM0+skYi5dKYtGanEwqKmphMV6zz5lmR7S/SJLz/0gyhOnbBtnwm/OuDX7SGkHA2U+ 2idX7i49+SWfedOZIen2DA1RLf07hFvaPRZTI= Received: by 10.223.125.132 with SMTP id y4mr493347far.148.1290192083418; Fri, 19 Nov 2010 10:41:23 -0800 (PST) Received: from localhost.localdomain (vawpc43.ethz.ch [129.132.59.11]) by mx.google.com with ESMTPS id n3sm626630faa.5.2010.11.19.10.41.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 19 Nov 2010 10:41:22 -0800 (PST) Sender: Jed Brown From: Jed Brown To: dme@dme.org, notmuch@notmuchmail.org Subject: [PATCH] Support function values in notmuch-saved-searches so that searches can be generated dynamically Date: Fri, 19 Nov 2010 19:42:49 +0100 Message-Id: <1290192169-2486-1-git-send-email-jed@59A2.org> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1290188979-7596-1-git-send-email-dme@dme.org> References: <1290188979-7596-1-git-send-email-dme@dme.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Fri, 19 Nov 2010 18:41:34 -0000 This permits saved searches like "today". --- This is similar functionality to David's patch, but uses an accessor so that queries are always evaluated dynamically. emacs/notmuch-hello.el | 4 ++-- emacs/notmuch-lib.el | 11 ++++++++++- emacs/notmuch.el | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index e58dd24..15eaafb 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -234,7 +234,7 @@ should be. Returns a cons cell `(tags-per-line width)'." ;; (not elem) indicates an empty slot in the matrix. (when elem (let* ((name (car elem)) - (query (cdr elem)) + (query (notmuch-saved-search-get-query elem)) (formatted-name (format "%s " name))) (widget-insert (format "%8s " (notmuch-hello-nice-number @@ -393,7 +393,7 @@ Complete list of currently available key bindings: (if notmuch-show-empty-saved-searches notmuch-saved-searches (loop for elem in notmuch-saved-searches - if (> (string-to-number (notmuch-saved-search-count (cdr elem))) 0) + if (> (string-to-number (notmuch-saved-search-count (notmuch-saved-search-get-query elem))) 0) collect elem))) (saved-widest (notmuch-hello-longest-label saved-alist)) (alltags-alist (if notmuch-show-all-tags-list diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index dd180ee..3fcb837 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -37,7 +37,9 @@ (defcustom notmuch-saved-searches nil "A list of saved searches to display." - :type '(alist :key-type string :value-type string) + :type '(alist :key-type (string :tag "Name") + :value-type (choice (string :tag "Search") + (function :tag "Function"))) :group 'notmuch) (defvar notmuch-folders nil @@ -56,6 +58,13 @@ the user hasn't set this variable with the old or new value." '(("inbox" . "tag:inbox") ("unread" . "tag:unread"))))) +(defun notmuch-saved-search-get-query (tuple) + "Get the query string for a saved tuple." + (let ((q (cdr tuple))) + (if (stringp q) + q + (funcall q)))) + (defun notmuch-version () "Return a string with the notmuch version number." (let ((long-string diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 5933747..5864b21 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -763,7 +763,7 @@ characters as well as `_.+-'. (let (longest (longest-length 0)) (loop for tuple in notmuch-saved-searches - if (let ((quoted-query (regexp-quote (cdr tuple)))) + if (let ((quoted-query (regexp-quote (notmuch-saved-search-get-query tuple)))) (and (string-match (concat "^" quoted-query) query) (> (length (match-string 0 query)) longest-length))) -- 1.7.3.2