[PATCH v2 2/5] emacs: hello: use the saved-search helper functions
authorMark Walters <markwalters1009@gmail.com>
Sun, 6 Apr 2014 05:44:46 +0000 (06:44 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:01:19 +0000 (10:01 -0800)
71/566c1b9d372fc4d83a88e216d2db9646834f77 [new file with mode: 0644]

diff --git a/71/566c1b9d372fc4d83a88e216d2db9646834f77 b/71/566c1b9d372fc4d83a88e216d2db9646834f77
new file mode 100644 (file)
index 0000000..82ff78b
--- /dev/null
@@ -0,0 +1,205 @@
+Return-Path: <markwalters1009@gmail.com>\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 15C38431FD4\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Apr 2014 22:45:16 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       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 WmMQ3Q+gLWlH for <notmuch@notmuchmail.org>;\r
+       Sat,  5 Apr 2014 22:45:10 -0700 (PDT)\r
+Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com\r
+       [209.85.212.182]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id A799A431FBF\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Apr 2014 22:45:07 -0700 (PDT)\r
+Received: by mail-wi0-f182.google.com with SMTP id d1so3311314wiv.9\r
+       for <notmuch@notmuchmail.org>; Sat, 05 Apr 2014 22:45:06 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+       bh=NGRfCsBSC5wLIhMeVkPiijOAySG24U1BPVgFCyJv/7o=;\r
+       b=itN0RKcPs6fT1puvKhLoB5a+XkGHEWH4ylt/nkSl22fKpGahm8F2aGrje+Z0NiI5Fc\r
+       +q4b8XtIDy1k7urNuw5Ye5ZbFostGYTLnj6Vkc7FP9w7czZPxyGvaO7qZc5Qex6fJWhb\r
+       9YEFgl3hRsMqDPQQeQmKwXbJEnc1jcL+CVvsFQINDBeX3mkTgQjhHSgUmlKUfJ4tZaIW\r
+       8rlKxUQaY3hj41cCT2ipSW8F1dUhQapPNZwuvufNKw3bxlmMb3ns+cDHxTzqAiNcFlKZ\r
+       Soy0naGw0jlwfX/iFFVjIoCX1NJV1J6lgQIYzBx/GfP/e2zPtvUj+wgkg0MJI2ECOPDk\r
+       FsdQ==\r
+X-Received: by 10.180.188.130 with SMTP id ga2mr16741265wic.18.1396763106564; \r
+       Sat, 05 Apr 2014 22:45:06 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPSA id\r
+       rx9sm20131441wjb.20.2014.04.05.22.45.05 for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sat, 05 Apr 2014 22:45:05 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org,\r
+       amdragon@MIT.EDU\r
+Subject: [PATCH v2 2/5] emacs: hello: use the saved-search helper functions\r
+Date: Sun,  6 Apr 2014 06:44:46 +0100\r
+Message-Id: <1396763089-32452-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1396763089-32452-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1396763089-32452-1-git-send-email-markwalters1009@gmail.com>\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: Sun, 06 Apr 2014 05:45:16 -0000\r
+\r
+This uses the helper functions: the saved searches format has not\r
+changed yet but backwards compatibility means everything still works.\r
+---\r
+ emacs/notmuch-hello.el |   48 ++++++++++++++++++++++--------------------------\r
+ emacs/notmuch.el       |    6 +++---\r
+ 2 files changed, 25 insertions(+), 29 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index f81ec27..568ae47 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -318,7 +318,7 @@ (defun notmuch-hello-add-saved-search (widget)\r
+     (setq notmuch-saved-searches\r
+         (loop for elem in notmuch-saved-searches\r
+               if (not (equal name\r
+-                             (car elem)))\r
++                             (notmuch-saved-search-get elem :name)))\r
+               collect elem))\r
+     ;; Add the new one.\r
+     (customize-save-variable 'notmuch-saved-searches\r
+@@ -338,7 +338,7 @@ (defun notmuch-hello-delete-search-from-history (widget)\r
\r
+ (defun notmuch-hello-longest-label (searches-alist)\r
+   (or (loop for elem in searches-alist\r
+-          maximize (length (car elem)))\r
++          maximize (length (notmuch-saved-search-get elem :name)))\r
+       0))\r
\r
+ (defun notmuch-hello-reflect-generate-row (ncols nrows row list)\r
+@@ -417,13 +417,12 @@ (defun notmuch-hello-filtered-query (query filter)\r
+     (concat "(" query ") and (" filter ")"))\r
+    (t query)))\r
\r
+-(defun notmuch-hello-query-counts (query-alist &rest options)\r
+-  "Compute list of counts of matched messages from QUERY-ALIST.\r
++(defun notmuch-hello-query-counts (query-list &rest options)\r
++  "Compute list of counts of matched messages from QUERY-LIST.\r
\r
+-QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)\r
+-or (NAME QUERY COUNT-QUERY). If the latter form is used,\r
+-COUNT-QUERY specifies an alternate query to be used to generate\r
+-the count for the associated query.\r
++QUERY-LIST must be a list of saved-searches. Ideally each of\r
++these is a plist but other options are available for backwards\r
++compatibility: see `notmuch-saved-searches' for details.\r
\r
+ The result is the list of elements of the form (NAME QUERY COUNT).\r
\r
+@@ -431,11 +430,9 @@ (defun notmuch-hello-query-counts (query-alist &rest options)\r
+ options will be handled as specified for\r
+ `notmuch-hello-insert-searches'."\r
+   (with-temp-buffer\r
+-    (dolist (elem query-alist nil)\r
+-      (let ((count-query (if (consp (cdr elem))\r
+-                           ;; do we have a different query for the message count?\r
+-                           (third elem)\r
+-                         (cdr elem))))\r
++    (dolist (elem query-list nil)\r
++      (let ((count-query (or (notmuch-saved-search-get elem :count-query)\r
++                           (notmuch-saved-search-get elem :query))))\r
+       (insert\r
+        (replace-regexp-in-string\r
+         "\n" " "\r
+@@ -457,18 +454,15 @@ (defun notmuch-hello-query-counts (query-alist &rest options)\r
+      #'identity\r
+      (mapcar\r
+       (lambda (elem)\r
+-      (let ((name (car elem))\r
+-            (search-query (if (consp (cdr elem))\r
+-                               ;; do we have a different query for the message count?\r
+-                               (second elem)\r
+-                            (cdr elem)))\r
++      (let ((name (notmuch-saved-search-get elem :name))\r
++            (search-query (notmuch-saved-search-get elem :query))\r
+             (message-count (prog1 (read (current-buffer))\r
+                               (forward-line 1))))\r
+         (and (or (plist-get options :show-empty-searches) (> message-count 0))\r
+              (list name (notmuch-hello-filtered-query\r
+                          search-query (plist-get options :filter))\r
+                    message-count))))\r
+-      query-alist))))\r
++      query-list))))\r
\r
+ (defun notmuch-hello-insert-buttons (searches)\r
+   "Insert buttons for SEARCHES.\r
+@@ -727,13 +721,15 @@ (defun notmuch-hello-insert-recent-searches ()\r
+       (indent-rigidly start (point) notmuch-hello-indent))\r
+     nil))\r
\r
+-(defun notmuch-hello-insert-searches (title query-alist &rest options)\r
+-  "Insert a section with TITLE showing a list of buttons made from QUERY-ALIST.\r
++(defun notmuch-hello-insert-searches (title query-list &rest options)\r
++  "Insert a section with TITLE showing a list of buttons made from QUERY-LIST.\r
\r
+-QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)\r
+-or (NAME QUERY COUNT-QUERY). If the latter form is used,\r
+-COUNT-QUERY specifies an alternate query to be used to generate\r
+-the count for the associated item.\r
++QUERY-LIST should ideally be a plist but for backwards\r
++compatibility other forms are also accepted (see\r
++`notmuch-saved-searches' for details).  The plist should\r
++contain keys :name and :query; if :count-query is also present\r
++then it specifies an alternate query to be used to generate the\r
++count for the associated search.\r
\r
+ Supports the following entries in OPTIONS as a plist:\r
+ :initially-hidden - if non-nil, section will be hidden on startup\r
+@@ -767,7 +763,7 @@ (defun notmuch-hello-insert-searches (title query-alist &rest options)\r
+                    "hide"))\r
+     (widget-insert "\n")\r
+     (when (not is-hidden)\r
+-      (let ((searches (apply 'notmuch-hello-query-counts query-alist options)))\r
++      (let ((searches (apply 'notmuch-hello-query-counts query-list options)))\r
+       (when (or (not (plist-get options :hide-if-empty))\r
+                 searches)\r
+         (widget-insert "\n")\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 233c784..1346b90 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -823,14 +823,14 @@ (defun notmuch-search-buffer-title (query)\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 (notmuch-saved-search-get tuple :query))))\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-name (notmuch-saved-search-get saved-search :name))\r
++       (saved-search-query (notmuch-saved-search-get saved-search :query)))\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.10.4\r
+\r