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 DF0FA429E4D for ; Wed, 23 Nov 2011 13:08:46 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled 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 zk6ktvChI8D4 for ; Wed, 23 Nov 2011 13:08:46 -0800 (PST) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 296DC429E4B for ; Wed, 23 Nov 2011 13:08:46 -0800 (PST) Received: by mail-bw0-f53.google.com with SMTP id q10so2250402bka.26 for ; Wed, 23 Nov 2011 13:08:45 -0800 (PST) Received: by 10.205.139.11 with SMTP id iu11mr174925bkc.82.1322082525492; Wed, 23 Nov 2011 13:08:45 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id q16sm23167024fae.6.2011.11.23.13.08.43 (version=SSLv3 cipher=OTHER); Wed, 23 Nov 2011 13:08:44 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [RFC PATCH 1/2] emacs: allow functions as saved searches Date: Wed, 23 Nov 2011 23:08:36 +0200 Message-Id: X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: In-Reply-To: References: 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: Wed, 23 Nov 2011 21:08:47 -0000 Signed-off-by: Jani Nikula --- emacs/notmuch-hello.el | 9 +++++++-- emacs/notmuch-lib.el | 8 ++++++-- emacs/notmuch.el | 9 +++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 0582cae..ad3ae74 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -274,7 +274,9 @@ 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 (if (functionp (cdr elem)) + (funcall (cdr elem) elem) + (cdr elem))) (formatted-name (format "%s " name))) (widget-insert (format "%8s " (notmuch-hello-nice-number @@ -452,7 +454,10 @@ 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 + (if (functionp (cdr elem)) + (funcall (cdr elem) elem) + (cdr elem)))) 0) collect elem))) (saved-widest (notmuch-hello-longest-label saved-alist)) (alltags-alist (if notmuch-show-all-tags-list (notmuch-hello-generate-tag-alist))) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 0f856bf..2ecb3fc 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -36,8 +36,12 @@ ;; (defcustom notmuch-saved-searches nil - "A list of saved searches to display." - :type '(alist :key-type string :value-type string) + "A list of saved searches to display. + +The list of saved searches is a list of key/value pairs, where +the key is the name of the saved search, and value is either a +query string, or a function that should return a query string." + :type '(alist :key-type string :value-type (choice string function)) :group 'notmuch) (defvar notmuch-folders nil diff --git a/emacs/notmuch.el b/emacs/notmuch.el index c1827cc..62f33e9 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -854,14 +854,19 @@ 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 + (if (functionp (cdr tuple)) + (funcall (cdr tuple) tuple) + (cdr tuple))))) (and (string-match (concat "^" quoted-query) query) (> (length (match-string 0 query)) longest-length))) do (setq longest tuple)) longest)) (saved-search-name (car saved-search)) - (saved-search-query (cdr saved-search))) + (saved-search-query (if (functionp (cdr saved-search)) + (funcall (cdr saved-search) saved-search) + (cdr saved-search)))) (cond ((and saved-search (equal saved-search-query query)) ;; Query is the same as saved search (ignoring case) (concat "*notmuch-saved-search-" saved-search-name "*")) -- 1.7.5.4