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

Pieter Praet pieter at praet.org
Fri Feb 24 14:35:26 PST 2012


On Fri, 24 Feb 2012 14:39:41 +0400, Dmitry Kurochkin <dmitry.kurochkin at gmail.com> wrote:
> On Fri, 24 Feb 2012 00:09:12 +0100, Pieter Praet <pieter at praet.org> wrote:
> > * emacs/notmuch-show.el
> > 
> >   (notmuch-show-mapc):
> >     Only call FUNCTION if new argument PREDICATE is satisfied.
> >     Also correct original docstring: 's/thread/buffer/'.
> > 
> >   (notmuch-show-get-messages-ids):
> >     Update wrt changes to `notmuch-show-mapc'.
> > 
> >   (notmuch-show-tag-all):
> >     Update wrt changes to `notmuch-show-mapc'.
> > ---
> >  emacs/notmuch-show.el |   15 ++++++++-------
> >  1 files changed, 8 insertions(+), 7 deletions(-)
> > 
> > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> > index aa9ccee..5fc0e43 100644
> > --- a/emacs/notmuch-show.el
> > +++ b/emacs/notmuch-show.el
> > @@ -1272,13 +1272,14 @@ (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
> > -`notmuch-show-goto-message-next' and call FUNCTION for side
> > -effects."
> > +(defun notmuch-show-mapc (predicate function)
> 
> Please make PREDICATE optional to avoid giving t when it is not needed.
>

Done.

> I would expect PREDICATE to be a function, [...]

Well, it *can* be a function actually (see later usage in e.g.
`notmuch-show-get-messages-ids' [1]), but should be provided
as a form instead of as a quoted symbol.

> [...] but perhaps the way you
> implemented it is common in Emacs.
>

Far from it, apparently.  I did it that way to prevent `funcall' from
choking on t/nil, which -in retrospect- was rather shortsighted...

I've used a more sensible approach in v2 [2].

> Regards,
>   Dmitry
> 
> > +  "Iterate through all messages in the current buffer with
> > +`notmuch-show-goto-message-next'.  If PREDICATE is satisfied,
> > +call FUNCTION for side effects."
> >    (save-excursion
> >      (goto-char (point-min))
> > -    (loop do (funcall function)
> > +    (loop do (if (eval predicate)
> > +		 (funcall function))
> >  	  while (notmuch-show-goto-message-next))))
> >  
> >  ;; Functions relating to the visibility of messages and their
> > @@ -1336,7 +1337,7 @@ (defun notmuch-show-get-message-id ()
> >  (defun notmuch-show-get-messages-ids ()
> >    "Return all message ids of messages in the current thread."
> >    (let ((message-ids))
> > -    (notmuch-show-mapc
> > +    (notmuch-show-mapc t
> >       (lambda () (push (notmuch-show-get-message-id) message-ids)))
> >      message-ids))
> >  
> > @@ -1633,7 +1634,7 @@ (defun notmuch-show-tag-all (&rest tag-changes)
> >  TAG-CHANGES is a list of tag operations for `notmuch-tag'."
> >    (interactive (notmuch-read-tag-changes nil notmuch-show-thread-id))
> >    (apply 'notmuch-tag (notmuch-show-get-messages-ids-search) tag-changes)
> > -  (notmuch-show-mapc
> > +  (notmuch-show-mapc t
> >     (lambda ()
> >       (let* ((current-tags (notmuch-show-get-tags))
> >  	    (new-tags (notmuch-update-tags current-tags tag-changes)))
> > -- 
> > 1.7.8.1
> > 


Peace

-- 
Pieter

[1] id:"1330038554-10347-6-git-send-email-pieter at praet.org"
[2] id:"1330122640-18895-5-git-send-email-pieter at praet.org"


More information about the notmuch mailing list