--- /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 9BB6F431FCB\r
+ for <notmuch@notmuchmail.org>; Tue, 6 May 2014 11:49:04 -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 WY57ThTyvg-a for <notmuch@notmuchmail.org>;\r
+ Tue, 6 May 2014 11:48:59 -0700 (PDT)\r
+Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com\r
+ [74.125.82.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ CDA7F431FAF for <notmuch@notmuchmail.org>; Tue, 6 May 2014 11:48:58 -0700\r
+ (PDT)\r
+Received: by mail-wg0-f48.google.com with SMTP id b13so4155629wgh.7\r
+ for <notmuch@notmuchmail.org>; Tue, 06 May 2014 11:48:57 -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;\r
+ bh=S4DaxMJsAHRZFxMNDcN2p0yA5tG7SB5T2WHOo2Yu5Gc=;\r
+ b=0R39i5hIRqQiS5bNbjIVjiczXNNmDogrAqgqFUCzYPbtkiP9PqE52BQitAm+0ZEIYH\r
+ m2UIQErteKdtSdUayoXgkgjV614z0tYLUWj1jhV8b1csixGMn8slt3oz+Mc/8uQyrfHV\r
+ vZgeyaY4kK5N9uH0z32AzW9OFWPKBuh0vFvDzoM0vVW5Qh6EeKp+wqeUlcXyNH/sOBXR\r
+ Yxv/hxqZo+4gyF/zu9r32Ga3joNsfD8b3a1N7rmJW51wR+ScwvHtVkyOo5DK36t+mKY9\r
+ AbT0F5lhPtCoioOv7ARjCZgRuxgHT3KdMbRwXujtcZdS8Nclc4H3EFpVwV91Sc8Pif/i\r
+ qAwQ==\r
+X-Received: by 10.180.104.5 with SMTP id ga5mr3704357wib.47.1399402137279;\r
+ Tue, 06 May 2014 11:48:57 -0700 (PDT)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by mx.google.com with ESMTPSA id dn1sm26381493wid.6.2014.05.06.11.48.55\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Tue, 06 May 2014 11:48:56 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: hello: allow arbitrary lisp for generating the count.\r
+Date: Tue, 6 May 2014 19:48:52 +0100\r
+Message-Id: <1399402132-1030-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\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: Tue, 06 May 2014 18:49:04 -0000\r
+\r
+This allows a function to be given for the count-query of a saved\r
+search. The function will be called with the query plist as an\r
+argument to generate the count shown and should return either a string\r
+or a number to be displayed as the count.\r
+\r
+If this option is a function then its query will not be part of the\r
+normal bacth query used so it may make notmuch-hello slower to display.\r
+---\r
+There was some discussion on irc today about notmuch hello being slow\r
+(because it can make a lot of queries). This extends the new\r
+saved-searches :count-query option to allow aribtrary lisp functions.\r
+\r
+Thus a user could configure some searches to be (lambda (elem) "--")\r
+so that these searches do not have a count executed and just display\r
+"--". Alternatively (and at the risk of some slow down) they could\r
+configure them to be my-notmuch-count where\r
+\r
+(defun my-notmuch-count (elem)\r
+ (concat\r
+ (notmuch-hello-nice-number\r
+ (string-to-number\r
+ (car\r
+ (process-lines notmuch-command "count" "--output=messages"\r
+ (plist-get elem :query)))))\r
+ "/"\r
+ (notmuch-hello-nice-number\r
+ (string-to-number\r
+ (car\r
+ (process-lines notmuch-command "count" "--output=threads"\r
+ (plist-get elem :query)))))))\r
+\r
+which would display messages/threads for that particular query.\r
+\r
+Maybe the interface is too complicated but I can actually imagine\r
+using this (possibly even both of the above for different of my saved\r
+searches!)\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+\r
+ emacs/notmuch-hello.el | 41 ++++++++++++++++++++++++++---------------\r
+ 1 file changed, 26 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 3de5238..877c84f 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -85,7 +85,7 @@ (define-widget 'notmuch-saved-search-plist 'list\r
+ (group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v")))\r
+ (checklist :inline t\r
+ :format "%v"\r
+- (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))\r
++ (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (sexp :format "%v"))\r
+ (group :format "%v" :inline t (const :format "" :sort-order)\r
+ (choice :tag " Sort Order"\r
+ (const :tag "Default" nil)\r
+@@ -101,9 +101,12 @@ (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")\r
+ \r
+ :name Name of the search (required).\r
+ :query Search to run (required).\r
+- :count-query Optional extra query to generate the count\r
+- shown. If not present then the :query property\r
+- is used.\r
++ :count-query Optional extra lisp to generate the count\r
++ shown. If it is a string then it is a query\r
++ string for generating the count. If it is a\r
++ function then the function is called with the\r
++ query plist as a parameter. If it is nil or not\r
++ present then the :query property is used.\r
+ :sort-order Specify the sort order to be used for the search.\r
+ Possible values are 'oldest-first 'newest-first or\r
+ nil. Nil means use the default sort order.\r
+@@ -493,13 +496,14 @@ (defun notmuch-hello-query-counts (query-list &rest options)\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
+- (notmuch-hello-filtered-query count-query\r
+- (or (plist-get options :filter-count)\r
+- (plist-get options :filter))))\r
+- "\n")))\r
++ (unless (functionp count-query)\r
++ (insert\r
++ (replace-regexp-in-string\r
++ "\n" " "\r
++ (notmuch-hello-filtered-query count-query\r
++ (or (plist-get options :filter-count)\r
++ (plist-get options :filter))))\r
++ "\n"))))\r
+ \r
+ (unless (= (call-process-region (point-min) (point-max) notmuch-command\r
+ t t nil "count" "--batch") 0)\r
+@@ -515,12 +519,17 @@ (defun notmuch-hello-query-counts (query-list &rest options)\r
+ (mapcar\r
+ (lambda (elem)\r
+ (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem))\r
++ (count-query (plist-get elem-plist :count-query))\r
+ (search-query (plist-get elem-plist :query))\r
+ (filtered-query (notmuch-hello-filtered-query\r
+ search-query (plist-get options :filter)))\r
+- (message-count (prog1 (read (current-buffer))\r
+- (forward-line 1))))\r
+- (when (and filtered-query (or (plist-get options :show-empty-searches) (> message-count 0)))\r
++ (message-count (if (functionp count-query)\r
++ (funcall count-query elem-plist)\r
++ (prog1 (read (current-buffer))\r
++ (forward-line 1)))))\r
++ (when (and filtered-query (or (plist-get options :show-empty-searches)\r
++ (not (integerp message-count))\r
++ (> message-count 0)))\r
+ (setq elem-plist (plist-put elem-plist :query filtered-query))\r
+ (plist-put elem-plist :count message-count))))\r
+ query-list))))\r
+@@ -559,7 +568,9 @@ (defun notmuch-hello-insert-buttons (searches)\r
+ (otherwise notmuch-search-oldest-first)))\r
+ (msg-count (plist-get elem :count)))\r
+ (widget-insert (format "%8s "\r
+- (notmuch-hello-nice-number msg-count)))\r
++ (if (stringp msg-count)\r
++ msg-count\r
++ (notmuch-hello-nice-number msg-count))))\r
+ (widget-create 'push-button\r
+ :notify #'notmuch-hello-widget-search\r
+ :notmuch-search-terms query\r
+-- \r
+1.7.10.4\r
+\r