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 9BB6F431FCB for ; Tue, 6 May 2014 11:49:04 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, 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 WY57ThTyvg-a for ; Tue, 6 May 2014 11:48:59 -0700 (PDT) Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com [74.125.82.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id CDA7F431FAF for ; Tue, 6 May 2014 11:48:58 -0700 (PDT) Received: by mail-wg0-f48.google.com with SMTP id b13so4155629wgh.7 for ; Tue, 06 May 2014 11:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=S4DaxMJsAHRZFxMNDcN2p0yA5tG7SB5T2WHOo2Yu5Gc=; b=0R39i5hIRqQiS5bNbjIVjiczXNNmDogrAqgqFUCzYPbtkiP9PqE52BQitAm+0ZEIYH m2UIQErteKdtSdUayoXgkgjV614z0tYLUWj1jhV8b1csixGMn8slt3oz+Mc/8uQyrfHV vZgeyaY4kK5N9uH0z32AzW9OFWPKBuh0vFvDzoM0vVW5Qh6EeKp+wqeUlcXyNH/sOBXR Yxv/hxqZo+4gyF/zu9r32Ga3joNsfD8b3a1N7rmJW51wR+ScwvHtVkyOo5DK36t+mKY9 AbT0F5lhPtCoioOv7ARjCZgRuxgHT3KdMbRwXujtcZdS8Nclc4H3EFpVwV91Sc8Pif/i qAwQ== X-Received: by 10.180.104.5 with SMTP id ga5mr3704357wib.47.1399402137279; Tue, 06 May 2014 11:48:57 -0700 (PDT) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by mx.google.com with ESMTPSA id dn1sm26381493wid.6.2014.05.06.11.48.55 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 06 May 2014 11:48:56 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH] emacs: hello: allow arbitrary lisp for generating the count. Date: Tue, 6 May 2014 19:48:52 +0100 Message-Id: <1399402132-1030-1-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.10.4 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: Tue, 06 May 2014 18:49:04 -0000 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. --- 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=messages" (plist-get elem :query))))) "/" (notmuch-hello-nice-number (string-to-number (car (process-lines notmuch-command "count" "--output=threads" (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) (string :format "%v"))) (checklist :inline t :format "%v" - (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v")) + (group :format "%v" :inline t (const :format "Count-Query: " :count-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") :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 + 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")))) (unless (= (call-process-region (point-min) (point-max) notmuch-command 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 -- 1.7.10.4