[PATCH v2 4/6] emacs: add optional predicate arg to `notmuch-show-mapc'

Mark Walters markwalters1009 at gmail.com
Tue Mar 20 18:33:23 PDT 2012


On Fri, 24 Feb 2012 23:30:38 +0100, Pieter Praet <pieter at praet.org> wrote:
> * emacs/notmuch-show.el (notmuch-show-mapc):
> 
>   If provided with optional argument PREDICATE, only call
>   FUNCTION if calling PREDICATE returns non-nil.
> 
>   Also correct original docstring: 's/thread/buffer/'.
> ---
>  emacs/notmuch-show.el |   14 ++++++++++----
>  1 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index aa9ccee..6adbdc0 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -1272,13 +1272,19 @@ (defun notmuch-show-goto-message-previous ()
>      (notmuch-show-move-to-message-top)
>      t))
>  
> -(defun notmuch-show-mapc (function)
> -  "Iterate through all messages in the current thread with
> +(defun notmuch-show-mapc (function &optional predicate)
> +  "Iterate through all messages in the current buffer with
>  `notmuch-show-goto-message-next' and call FUNCTION for side
> -effects."
> +effects.
> +
> +If provided with optional argument PREDICATE, only call
> +FUNCTION if calling PREDICATE returns non-nil."
>    (save-excursion
>      (goto-char (point-min))
> -    (loop do (funcall function)
> +    (loop do (if predicate
> +		 (if (funcall predicate)
> +		     (funcall function))
> +	       (funcall function))
>  	  while (notmuch-show-goto-message-next))))
>  
>  ;; Functions relating to the visibility of messages and their

The change looks fine.

The original function feels a little fragile to me as to what happens if
predicate or function move point. Eg what happens if function collapses
the message: where does point go, and so where does
notmuch-show-goto-message-next go. Is this just my naivete as a lisp
beginner? Is there someway of writing it so the user doesn't need to
worry about such things?

Best wishes

Mark

(sorry for the duplicate mail: I sent the first message from the wrong address)



More information about the notmuch mailing list