[RFC PATCH 1/2] emacs: allow functions as saved searches
authorJani Nikula <jani@nikula.org>
Wed, 23 Nov 2011 21:08:36 +0000 (23:08 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:40:22 +0000 (09:40 -0800)
12/ba0bc7561da0708409ef78a959fb4d0da0ce66 [new file with mode: 0644]

diff --git a/12/ba0bc7561da0708409ef78a959fb4d0da0ce66 b/12/ba0bc7561da0708409ef78a959fb4d0da0ce66
new file mode 100644 (file)
index 0000000..27e9e03
--- /dev/null
@@ -0,0 +1,137 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id DF0FA429E4D\r
+       for <notmuch@notmuchmail.org>; Wed, 23 Nov 2011 13:08:46 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id zk6ktvChI8D4 for <notmuch@notmuchmail.org>;\r
+       Wed, 23 Nov 2011 13:08:46 -0800 (PST)\r
+Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 296DC429E4B\r
+       for <notmuch@notmuchmail.org>; Wed, 23 Nov 2011 13:08:46 -0800 (PST)\r
+Received: by mail-bw0-f53.google.com with SMTP id q10so2250402bka.26\r
+       for <notmuch@notmuchmail.org>; Wed, 23 Nov 2011 13:08:45 -0800 (PST)\r
+Received: by 10.205.139.11 with SMTP id iu11mr174925bkc.82.1322082525492;\r
+       Wed, 23 Nov 2011 13:08:45 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id q16sm23167024fae.6.2011.11.23.13.08.43\r
+       (version=SSLv3 cipher=OTHER); Wed, 23 Nov 2011 13:08:44 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 1/2] emacs: allow functions as saved searches\r
+Date: Wed, 23 Nov 2011 23:08:36 +0200\r
+Message-Id:\r
+ <bbb67d241bf5f8575545ecdd2c3cd6cfed3244e8.1322080622.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1322080622.git.jani@nikula.org>\r
+References: <cover.1322080622.git.jani@nikula.org>\r
+In-Reply-To: <cover.1322080622.git.jani@nikula.org>\r
+References: <cover.1322080622.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 23 Nov 2011 21:08:47 -0000\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ emacs/notmuch-hello.el |    9 +++++++--\r
+ emacs/notmuch-lib.el   |    8 ++++++--\r
+ emacs/notmuch.el       |    9 +++++++--\r
+ 3 files changed, 20 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 0582cae..ad3ae74 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -274,7 +274,9 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
+           ;; (not elem) indicates an empty slot in the matrix.\r
+           (when elem\r
+             (let* ((name (car elem))\r
+-                   (query (cdr elem))\r
++                   (query (if (functionp (cdr elem))\r
++                              (funcall (cdr elem) elem)\r
++                              (cdr elem)))\r
+                    (formatted-name (format "%s " name)))\r
+               (widget-insert (format "%8s "\r
+                                      (notmuch-hello-nice-number\r
+@@ -452,7 +454,10 @@ Complete list of currently available key bindings:\r
+             (if notmuch-show-empty-saved-searches\r
+                 notmuch-saved-searches\r
+               (loop for elem in notmuch-saved-searches\r
+-                    if (> (string-to-number (notmuch-saved-search-count (cdr elem))) 0)\r
++                    if (> (string-to-number (notmuch-saved-search-count\r
++                                             (if (functionp (cdr elem))\r
++                                                 (funcall (cdr elem) elem)\r
++                                               (cdr elem)))) 0)\r
+                     collect elem)))\r
+            (saved-widest (notmuch-hello-longest-label saved-alist))\r
+            (alltags-alist (if notmuch-show-all-tags-list (notmuch-hello-generate-tag-alist)))\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 0f856bf..2ecb3fc 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -36,8 +36,12 @@\r
+ ;;\r
\r
+ (defcustom notmuch-saved-searches nil\r
+-  "A list of saved searches to display."\r
+-  :type '(alist :key-type string :value-type string)\r
++  "A list of saved searches to display.\r
++\r
++The list of saved searches is a list of key/value pairs, where\r
++the key is the name of the saved search, and value is either a\r
++query string, or a function that should return a query string."\r
++  :type '(alist :key-type string :value-type (choice string function))\r
+   :group 'notmuch)\r
\r
+ (defvar notmuch-folders nil\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index c1827cc..62f33e9 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -854,14 +854,19 @@ characters as well as `_.+-'.\r
+         (let (longest\r
+               (longest-length 0))\r
+           (loop for tuple in notmuch-saved-searches\r
+-                if (let ((quoted-query (regexp-quote (cdr tuple))))\r
++                if (let ((quoted-query (regexp-quote\r
++                                        (if (functionp (cdr tuple))\r
++                                            (funcall (cdr tuple) tuple)\r
++                                          (cdr tuple)))))\r
+                      (and (string-match (concat "^" quoted-query) query)\r
+                           (> (length (match-string 0 query))\r
+                              longest-length)))\r
+                 do (setq longest tuple))\r
+           longest))\r
+        (saved-search-name (car saved-search))\r
+-       (saved-search-query (cdr saved-search)))\r
++       (saved-search-query (if (functionp (cdr saved-search))\r
++                               (funcall (cdr saved-search) saved-search)\r
++                             (cdr saved-search))))\r
+     (cond ((and saved-search (equal saved-search-query query))\r
+          ;; Query is the same as saved search (ignoring case)\r
+          (concat "*notmuch-saved-search-" saved-search-name "*"))\r
+-- \r
+1.7.5.4\r
+\r