--- /dev/null
+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 DC8C6431FD7\r
+ for <notmuch@notmuchmail.org>; Sat, 5 Apr 2014 14:24:57 -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 40x7qX-qgyHX for <notmuch@notmuchmail.org>;\r
+ Sat, 5 Apr 2014 14:24:52 -0700 (PDT)\r
+Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com\r
+ [209.85.212.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id C85F3431FC2\r
+ for <notmuch@notmuchmail.org>; Sat, 5 Apr 2014 14:24:47 -0700 (PDT)\r
+Received: by mail-wi0-f177.google.com with SMTP id cc10so3059425wib.10\r
+ for <notmuch@notmuchmail.org>; Sat, 05 Apr 2014 14:24:46 -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=r3ODfphJoiR2U84CiwW/8hyOZI2OF05FAWAYQ/iAtHs=;\r
+ b=cTkx7NCSBP8vGZMtBNB84mEMoyrDFQJ0kVP7bYZMDcBFf1Ga2J0qxzwkStotdZY39m\r
+ O5AuoieHiPjZLJWuHdv5q1Unjszukq5CVA2LdYL4HUW4uHVNsmOc0NkQIS9kxMNK0ft7\r
+ wgUclP2RSXAEZnrJYsTucsb+rcZart6gLXm/c9ot6KrMcftD58qWq3hz+5dG9blFjYpS\r
+ T2gTbZ+GGQ1dMFCBex4qcdrk2whDosg0wRSKUKmz6qCQq12NVlhrB5tPP2jgx8hKaUwb\r
+ 7aIwLUAhC+vTLdt4Oin9HzGDc0BbdH9e3KBkO8WYXXB/l76KA66IpFplgtVMv++v7gw+\r
+ XcIA==\r
+X-Received: by 10.180.96.225 with SMTP id dv1mr14319177wib.37.1396733086709;\r
+ Sat, 05 Apr 2014 14:24:46 -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 be3sm18587893wjc.5.2014.04.05.14.24.45\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sat, 05 Apr 2014 14:24:46 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/5] emacs: hello: use the saved-search helper functions\r
+Date: Sat, 5 Apr 2014 22:24:22 +0100\r
+Message-Id: <1396733065-32602-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1396733065-32602-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1396733065-32602-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: Sat, 05 Apr 2014 21:24:58 -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 0b9ed16..733208b 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -319,7 +319,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
+@@ -339,7 +339,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
+@@ -418,13 +418,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-search-get for details.\r
+ \r
+ The result is the list of elements of the form (NAME QUERY COUNT).\r
+ \r
+@@ -432,11 +431,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
+@@ -458,18 +455,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
+@@ -728,13 +722,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-search-get' 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
+@@ -768,7 +764,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