From ac8bc10c93339805ea672a2b1db4e578e09e8d44 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Mon, 12 May 2014 16:20:00 +0100 Subject: [PATCH] Re: [PATCH 2/7] emacs: hello: allow saved search display functions --- cf/1b69f8afc42b151a75cb0c904aabba9338629d | 225 ++++++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 cf/1b69f8afc42b151a75cb0c904aabba9338629d diff --git a/cf/1b69f8afc42b151a75cb0c904aabba9338629d b/cf/1b69f8afc42b151a75cb0c904aabba9338629d new file mode 100644 index 000000000..4d47fa89f --- /dev/null +++ b/cf/1b69f8afc42b151a75cb0c904aabba9338629d @@ -0,0 +1,225 @@ +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 212C9431FC7 + for ; Mon, 12 May 2014 08:20:12 -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 8yFOV68n9+Qm for ; + Mon, 12 May 2014 08:20:04 -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 C1564431FC2 + for ; Mon, 12 May 2014 08:20:03 -0700 (PDT) +Received: by mail-wi0-f174.google.com with SMTP id r20so4675740wiv.13 + for ; Mon, 12 May 2014 08:20:02 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:subject:in-reply-to:references:user-agent:date:message-id + :mime-version:content-type; + bh=pH/7PJmg15Y0qTNgcT9K1L+wfwcZljTuiyBU+1duR7w=; + b=OyeoRB6Ibxcei6qPncM6mCMnjpkCZtwgHcOhSAkINVBxJy45JAJb/L3Nll6M+wFpRn + /Z4k23buXc6Q6avdqjXJTYcr3znJzF+bPGbVIuDA+lhxJtq5xBbGRczGlq88yDaKYoR0 + zSCzP+3hoIzxzITqcH2s4ejiuxrWaVQT9g1ZZSsFvwpmlct2vX89LoFc1e0WKT3NcXtL + kNdxlJUvMPjFyWhvLjWVrToLJmU/Pm0aBIth/rKhEyEv1RrEbr7IrYm9v1TvnZeKkcZ0 + JarmQAcn+6ZFtLUHJXARTsGdZOuaWxdLhxc0Kajz61ByVtQoUtXaJb051+YEMeMuV5X3 + DHwA== +X-Received: by 10.194.92.7 with SMTP id ci7mr22184509wjb.7.1399908002480; + Mon, 12 May 2014 08:20:02 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id dg7sm18329407wjc.4.2014.05.12.08.20.01 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Mon, 12 May 2014 08:20:01 -0700 (PDT) +From: Mark Walters +To: David Edmondson , notmuch@notmuchmail.org +Subject: Re: [PATCH 2/7] emacs: hello: allow saved search display functions +In-Reply-To: +References: <1399797282-20389-1-git-send-email-markwalters1009@gmail.com> + <1399797282-20389-3-git-send-email-markwalters1009@gmail.com> + +User-Agent: Notmuch/0.15.2+615~g78e3a93 (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Mon, 12 May 2014 16:20:00 +0100 +Message-ID: <871tvzkorj.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +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: Mon, 12 May 2014 15:20:12 -0000 + +On Mon, 12 May 2014, David Edmondson wrote: +> On Sun, May 11 2014, Mark Walters wrote: +>> Extend the saved search plist to include a :display-function property +>> that can customise the display of the saved search. It can change the +>> count string displayed and the name string. Thus the user can +>> customise so that a particular search: +>> +>> does not show a count (and is thus hello is faster), shows a thread +>> count, show a combined message/thread count, changes colour of the +>> search button based on new messages arriving etc. +>> +>> The display function should use (&rest args) to take a keyword list of +>> arguments. The advantage of this is that it is easy to add extra +>> arguments in a backwards compatible way (existing user scripts will +>> still work). +>> +>> If a user uses this it will not take advantage of the batch counting +>> currently done so will make things slower over remote links (except in +>> cases where no query is done!). +>> +>> It also deletes the :count-query option from the customise for saved +>> searches as this method is much more general. The code still supports +>> the :count-query option though (just the defcustom does not). +>> --- +>> emacs/notmuch-hello.el | 47 +++++++++++++++++++++++++++++++---------------- +>> 1 file changed, 31 insertions(+), 16 deletions(-) +>> +>> diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el +>> index 0a7004c..7075860 100644 +>> --- a/emacs/notmuch-hello.el +>> +++ b/emacs/notmuch-hello.el +>> @@ -85,12 +85,13 @@ (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 "" :sort-order) +>> (choice :tag " Sort Order" +>> (const :tag "Default" nil) +>> (const :tag "Oldest-first" oldest-first) +>> - (const :tag "Newest-first" newest-first)))))) +>> + (const :tag "Newest-first" newest-first))) +>> + (group :format "%v" :inline t (const :format "Display-function: " :display-function) (function :format "%v"))))) +>> + +>> +>> (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox") +>> (:name "unread" :query "tag:unread")) +>> @@ -101,12 +102,19 @@ (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. +>> :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. +>> + :display-function Optional function to generate the count and +>> + name to be displayed. The function takes a +>> + keyword list of arguments (it should use +>> + &rest). Keywords include :current for the +>> + current saved search plist and :options. If +>> + this function is not set then the default +>> + display of message count and name is used. The +>> + function should return an updated saved search +>> + plist including :name and :count as the name +>> + and count-string to be displayed. +>> +>> Other accepted forms are a cons cell of the form (NAME . QUERY) +>> or a list of the form (NAME QUERY COUNT-QUERY)." +>> @@ -507,15 +515,16 @@ (defun notmuch-hello-query-counts (query-list &rest options) +>> `notmuch-hello-insert-searches'." +>> (with-temp-buffer +>> (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 (notmuch-saved-search-get elem :display-function) +>> + (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 (= (call-process-region (point-min) (point-max) notmuch-command +>> t t nil "count" "--batch") 0) +>> @@ -530,8 +539,14 @@ (defun notmuch-hello-query-counts (query-list &rest options) +>> #'identity +>> (mapcar +>> (lambda (elem) +>> - (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem))) +>> - (notmuch-hello-batch-message-count elem-plist options))) +>> + (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem)) +>> + (display-function (plist-get elem-plist :display-function)) +>> + (result (if display-function +>> + (funcall display-function +>> + :current elem-plist +>> + :option options) +>> + (notmuch-hello-batch-message-count elem-plist +>> options)))) +> +> If `notmuch-hello-batch-message-count' were re-written to operate as a +> display-function, this could be replaced with something like: +> +> (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem)) +> (result (funcall (or (plist-get elem-plist :display-function) +> #'notmuch-hello-batch-message-count) +> :current elem-plist +> :option options)) +> + +The reason I didn't do this is that things would break if a user +manually configured display function to be +#'notmuch-hello-batch-message-count as the query would not have been +batched. Thus my version made the distinction fundamental. But perhaps +the batch queuing code could queue the query if either there is no +display function or the display-function is +notmuch-hello-batch-message-count, but that seems a bit gross. + +I also played with calling each display function in the batch phase too +and then they could queue any message counts they wanted. But I thought +that might be too complex. OTOH being able to do display +match/match-and-unread might be nice and could be batched with the +correct infrastructure. + +Any thoughts? + +Best wishes + +Mark + + + + + +>> + result)) +>> query-list)))) +>> +>> (defun notmuch-hello-insert-buttons (searches) +>> -- +>> 1.7.10.4 +>> +>> _______________________________________________ +>> notmuch mailing list +>> notmuch@notmuchmail.org +>> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2