unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Edmondson <dme@dme.org>
To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org
Subject: Re: [PATCH 2/7] emacs: hello: allow saved search display functions
Date: Mon, 12 May 2014 15:03:41 +0100	[thread overview]
Message-ID: <cuniopb6qma.fsf@hotblack-desiato.hh.sledj.net> (raw)
In-Reply-To: <1399797282-20389-3-git-send-email-markwalters1009@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6069 bytes --]

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))

> +	  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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 310 bytes --]

  reply	other threads:[~2014-05-12 14:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-11  8:34 [PATCH 0/7] emacs: hello: custom display of saved searches Mark Walters
2014-05-11  8:34 ` [PATCH 1/7] emacs: hello: separate out the saved-search display function Mark Walters
2017-03-11 14:57   ` David Bremner
2014-05-11  8:34 ` [PATCH 2/7] emacs: hello: allow saved search display functions Mark Walters
2014-05-12 14:03   ` David Edmondson [this message]
2014-05-12 15:20     ` Mark Walters
2014-05-11  8:34 ` [PATCH 3/7] emacs: hello: store previous saved-search results Mark Walters
2014-05-11  8:34 ` [PATCH 4/7] emacs: hello: add a threads-and-messages function Mark Walters
2014-05-11  8:34 ` [PATCH 5/7] emacs: hello: require cl Mark Walters
2017-03-11 15:01   ` David Bremner
2014-05-11  8:34 ` [PATCH 6/7] emacs: hello: add highlight newly arrived messages option Mark Walters
2014-05-12 13:58   ` David Edmondson
2014-05-12 15:33     ` Mark Walters
2016-01-07 22:52   ` Tomi Ollila
2014-05-11  8:34 ` [PATCH 7/7] emacs: hello: add option to omit count for a search Mark Walters

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cuniopb6qma.fsf@hotblack-desiato.hh.sledj.net \
    --to=dme@dme.org \
    --cc=markwalters1009@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).