--- /dev/null
+Return-Path: <dme@dme.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 13B54431FAF\r
+ for <notmuch@notmuchmail.org>; Tue, 6 May 2014 22:41:17 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 BP6Ag7QvHZGR for <notmuch@notmuchmail.org>;\r
+ Tue, 6 May 2014 22:41:09 -0700 (PDT)\r
+Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com\r
+ [209.85.212.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 66773431FAE\r
+ for <notmuch@notmuchmail.org>; Tue, 6 May 2014 22:41:09 -0700 (PDT)\r
+Received: by mail-wi0-f174.google.com with SMTP id r20so5159190wiv.7\r
+ for <notmuch@notmuchmail.org>; Tue, 06 May 2014 22:41:08 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:to:subject:in-reply-to:references:user-agent\r
+ :from:date:message-id:mime-version:content-type;\r
+ bh=9gYY1AklvGOyLb82qlMxrA+ZrZzHcdXYFy7VKm0UXnQ=;\r
+ b=MWRT+Muwhyb50ZtkFgcf8KS3FGTg0+8W3+Yh0z1oGg85PZKfUKCa/OlCzEA3O6UQ6z\r
+ le7mJ7uo+3Ez9OVIH8IAv/KvapVYcVWGKbTnr56AyMtp4uNkUlZDV0nUDEFHEtipKsVB\r
+ 9eAvJUctzxo1vog8eo29NLNCD0fwBgs9kccTfIx763EJQ5s6jYqMC+AQkR1NkHyBPT/b\r
+ p+cJMVFF8Pm3gptxB3xNbqh7kIEc1WFq06K7j0ocDw9vhWOk0zlsRBDNSoBU1JGZ2Rq5\r
+ 01DUCYG0zd8nrallxNTuNbq0/ndgUa6RGmqdJxAYqggvHfwkvAecwAi0v0gNBlM2lYM+\r
+ 5yYA==\r
+X-Gm-Message-State:\r
+ ALoCoQmwgMqnLp//agE5DxHcEirbsmOLIXzdVoReiBjK15/AtSVHcoDHIFPF6PSPWmx4I8aP31R5\r
+X-Received: by 10.180.77.165 with SMTP id t5mr24607705wiw.38.1399441267998;\r
+ Tue, 06 May 2014 22:41:07 -0700 (PDT)\r
+Received: from localhost (disaster-area.hh.sledj.net. [81.149.164.25])\r
+ by mx.google.com with ESMTPSA id\r
+ fz11sm11958155wic.4.2014.05.06.22.41.05 for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Tue, 06 May 2014 22:41:06 -0700 (PDT)\r
+To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] emacs: hello: allow arbitrary lisp for generating the\r
+ count.\r
+In-Reply-To: <1399402132-1030-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1399402132-1030-1-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Notmuch/0.18~rc1 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-pc-linux-gnu)\r
+From: David Edmondson <dme@dme.org>\r
+Date: Wed, 07 May 2014 06:41:00 +0100\r
+Message-ID: <cun8uqegn83.fsf@hotblack-desiato.hh.sledj.net>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="=-=-=";\r
+ micalg=pgp-sha1; protocol="application/pgp-signature"\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, 07 May 2014 05:41:17 -0000\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+Looks good, two nits:\r
+\r
+On Tue, May 06 2014, Mark Walters <markwalters1009@gmail.com> wrote:\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\r
+> display.\r
+\r
+"batch"\r
+\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=3Dmessages"\r
+> (plist-get elem :query)))))\r
+> "/"\r
+> (notmuch-hello-nice-number\r
+> (string-to-number\r
+> (car\r
+> (process-lines notmuch-command "count" "--output=3Dthreads"\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) (stri=\r
+ng :format "%v")))\r
+> (checklist :inline t\r
+> :format "%v"\r
+> - (group :format "%v" :inline t (const :format "Count-Query: " :cou=\r
+nt-query) (string :format "%v"))\r
+> + (group :format "%v" :inline t (const :format "Count-Query: " :cou=\r
+nt-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" :=\r
+query "tag:inbox")\r
+>=20=20\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
+\r
+"Optional function to generate the count"\r
+\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=\r
+ 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
+>=20=20\r
+> (unless (=3D (call-process-region (point-min) (point-max) notmuch-co=\r
+mmand\r
+> t t nil "count" "--batch") 0)\r
+> @@ -515,12 +519,17 @@ (defun notmuch-hello-query-counts (query-list &rest=\r
+ 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=\r
+) (> 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
+> --=20\r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r
+\r
+--=-=-=\r
+Content-Type: application/pgp-signature; name="signature.asc"\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1\r
+\r
+iKYEARECAGYFAlNpx2xfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3Bl\r
+bnBncC5maWZ0aGhvcnNlbWFuLm5ldDc1M0Y5NDJDMEExNjc3MDE4OURGMUYyMDY5\r
+RUNEMEFCRjA0OTY1MTYACgkQaezQq/BJZRanBACfVaWh9QqXpXtPes4ky1sHEw3T\r
+CbMAn3gKHCtxjT+/SsuZyyuSmXVmWqAP\r
+=UB+q\r
+-----END PGP SIGNATURE-----\r
+--=-=-=--\r