Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 13B54431FAF for ; Tue, 6 May 2014 22:41:17 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BP6Ag7QvHZGR for ; Tue, 6 May 2014 22:41:09 -0700 (PDT) Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 66773431FAE for ; Tue, 6 May 2014 22:41:09 -0700 (PDT) Received: by mail-wi0-f174.google.com with SMTP id r20so5159190wiv.7 for ; Tue, 06 May 2014 22:41:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:subject:in-reply-to:references:user-agent :from:date:message-id:mime-version:content-type; bh=9gYY1AklvGOyLb82qlMxrA+ZrZzHcdXYFy7VKm0UXnQ=; b=MWRT+Muwhyb50ZtkFgcf8KS3FGTg0+8W3+Yh0z1oGg85PZKfUKCa/OlCzEA3O6UQ6z le7mJ7uo+3Ez9OVIH8IAv/KvapVYcVWGKbTnr56AyMtp4uNkUlZDV0nUDEFHEtipKsVB 9eAvJUctzxo1vog8eo29NLNCD0fwBgs9kccTfIx763EJQ5s6jYqMC+AQkR1NkHyBPT/b p+cJMVFF8Pm3gptxB3xNbqh7kIEc1WFq06K7j0ocDw9vhWOk0zlsRBDNSoBU1JGZ2Rq5 01DUCYG0zd8nrallxNTuNbq0/ndgUa6RGmqdJxAYqggvHfwkvAecwAi0v0gNBlM2lYM+ 5yYA== X-Gm-Message-State: ALoCoQmwgMqnLp//agE5DxHcEirbsmOLIXzdVoReiBjK15/AtSVHcoDHIFPF6PSPWmx4I8aP31R5 X-Received: by 10.180.77.165 with SMTP id t5mr24607705wiw.38.1399441267998; Tue, 06 May 2014 22:41:07 -0700 (PDT) Received: from localhost (disaster-area.hh.sledj.net. [81.149.164.25]) by mx.google.com with ESMTPSA id fz11sm11958155wic.4.2014.05.06.22.41.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 May 2014 22:41:06 -0700 (PDT) To: Mark Walters , notmuch@notmuchmail.org Subject: Re: [PATCH] emacs: hello: allow arbitrary lisp for generating the count. In-Reply-To: <1399402132-1030-1-git-send-email-markwalters1009@gmail.com> References: <1399402132-1030-1-git-send-email-markwalters1009@gmail.com> User-Agent: Notmuch/0.18~rc1 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) From: David Edmondson Date: Wed, 07 May 2014 06:41:00 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 May 2014 05:41:17 -0000 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Looks good, two nits: On Tue, May 06 2014, Mark Walters wrote: > This allows a function to be given for the count-query of a saved > search. The function will be called with the query plist as an > argument to generate the count shown and should return either a string > or a number to be displayed as the count. > > If this option is a function then its query will not be part of the > normal bacth query used so it may make notmuch-hello slower to > display. "batch" > --- > There was some discussion on irc today about notmuch hello being slow > (because it can make a lot of queries). This extends the new > saved-searches :count-query option to allow aribtrary lisp functions. > > Thus a user could configure some searches to be (lambda (elem) "--") > so that these searches do not have a count executed and just display > "--". Alternatively (and at the risk of some slow down) they could > configure them to be my-notmuch-count where > > (defun my-notmuch-count (elem) > (concat > (notmuch-hello-nice-number > (string-to-number > (car > (process-lines notmuch-command "count" "--output=3Dmessages" > (plist-get elem :query))))) > "/" > (notmuch-hello-nice-number > (string-to-number > (car > (process-lines notmuch-command "count" "--output=3Dthreads" > (plist-get elem :query))))))) > > which would display messages/threads for that particular query. > > Maybe the interface is too complicated but I can actually imagine > using this (possibly even both of the above for different of my saved > searches!) > > Best wishes > > Mark > > > > emacs/notmuch-hello.el | 41 ++++++++++++++++++++++++++--------------- > 1 file changed, 26 insertions(+), 15 deletions(-) > > diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el > index 3de5238..877c84f 100644 > --- a/emacs/notmuch-hello.el > +++ b/emacs/notmuch-hello.el > @@ -85,7 +85,7 @@ (define-widget 'notmuch-saved-search-plist 'list > (group :format "%v" :inline t (const :format " Query: " :query) (stri= ng :format "%v"))) > (checklist :inline t > :format "%v" > - (group :format "%v" :inline t (const :format "Count-Query: " :cou= nt-query) (string :format "%v")) > + (group :format "%v" :inline t (const :format "Count-Query: " :cou= nt-query) (sexp :format "%v")) > (group :format "%v" :inline t (const :format "" :sort-order) > (choice :tag " Sort Order" > (const :tag "Default" nil) > @@ -101,9 +101,12 @@ (defcustom notmuch-saved-searches '((:name "inbox" := query "tag:inbox") >=20=20 > :name Name of the search (required). > :query Search to run (required). > - :count-query Optional extra query to generate the count > - shown. If not present then the :query property > - is used. > + :count-query Optional extra lisp to generate the count "Optional function to generate the count" > + shown. If it is a string then it is a query > + string for generating the count. If it is a > + function then the function is called with the > + query plist as a parameter. If it is nil or not > + present then the :query property is used. > :sort-order Specify the sort order to be used for the search. > Possible values are 'oldest-first 'newest-first or > nil. Nil means use the default sort order. > @@ -493,13 +496,14 @@ (defun notmuch-hello-query-counts (query-list &rest= options) > (dolist (elem query-list nil) > (let ((count-query (or (notmuch-saved-search-get elem :count-query) > (notmuch-saved-search-get elem :query)))) > - (insert > - (replace-regexp-in-string > - "\n" " " > - (notmuch-hello-filtered-query count-query > - (or (plist-get options :filter-count) > - (plist-get options :filter)))) > - "\n"))) > + (unless (functionp count-query) > + (insert > + (replace-regexp-in-string > + "\n" " " > + (notmuch-hello-filtered-query count-query > + (or (plist-get options :filter-count) > + (plist-get options :filter)))) > + "\n")))) >=20=20 > (unless (=3D (call-process-region (point-min) (point-max) notmuch-co= mmand > t t nil "count" "--batch") 0) > @@ -515,12 +519,17 @@ (defun notmuch-hello-query-counts (query-list &rest= options) > (mapcar > (lambda (elem) > (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem)) > + (count-query (plist-get elem-plist :count-query)) > (search-query (plist-get elem-plist :query)) > (filtered-query (notmuch-hello-filtered-query > search-query (plist-get options :filter))) > - (message-count (prog1 (read (current-buffer)) > - (forward-line 1)))) > - (when (and filtered-query (or (plist-get options :show-empty-searches= ) (> message-count 0))) > + (message-count (if (functionp count-query) > + (funcall count-query elem-plist) > + (prog1 (read (current-buffer)) > + (forward-line 1))))) > + (when (and filtered-query (or (plist-get options :show-empty-searches) > + (not (integerp message-count)) > + (> message-count 0))) > (setq elem-plist (plist-put elem-plist :query filtered-query)) > (plist-put elem-plist :count message-count)))) > query-list)))) > @@ -559,7 +568,9 @@ (defun notmuch-hello-insert-buttons (searches) > (otherwise notmuch-search-oldest-first))) > (msg-count (plist-get elem :count))) > (widget-insert (format "%8s " > - (notmuch-hello-nice-number msg-count))) > + (if (stringp msg-count) > + msg-count > + (notmuch-hello-nice-number msg-count)))) > (widget-create 'push-button > :notify #'notmuch-hello-widget-search > :notmuch-search-terms query > --=20 > 1.7.10.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iKYEARECAGYFAlNpx2xfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3Bl bnBncC5maWZ0aGhvcnNlbWFuLm5ldDc1M0Y5NDJDMEExNjc3MDE4OURGMUYyMDY5 RUNEMEFCRjA0OTY1MTYACgkQaezQq/BJZRanBACfVaWh9QqXpXtPes4ky1sHEw3T CbMAn3gKHCtxjT+/SsuZyyuSmXVmWqAP =UB+q -----END PGP SIGNATURE----- --=-=-=--