Re: [PATCH v2 4/7] emacs: Use result text properties for search result iteration

Subject: Re: [PATCH v2 4/7] emacs: Use result text properties for search result iteration

Date: Sat, 14 Jul 2012 12:31:45 -0700

To: Austin Clements, notmuch@notmuchmail.org

Cc:

From: Jameson Graef Rollins


On Fri, Jul 13 2012, Austin Clements <amdragon@MIT.EDU> wrote:
> Coincidentally, this also essentially enables multi-line search result
> formats; the only remaining non-multi-line-capable functions are
> notmuch-search-{next,previous}-thread, which are only used
> interactively.

So I tried to experiment with multi-line search results with this patch
series, but it didn't work.  I tried adding a '\n' in one of the
formatter fields, but I got a series of errors for each result insertion
in the buffer.  What's the way to get multi-line to work?

> +(defmacro notmuch-search-do-results (beg end pos-sym &rest body)
> +  "Invoke BODY for each result between BEG and END.
> +
> +POS-SYM will be bound to the point at the beginning of the
> +current result."
> +  (declare (indent 3))
> +  (let ((end-sym (make-symbol "end"))
> +	(first-sym (make-symbol "first")))
> +    `(let ((,pos-sym (notmuch-search-result-beginning ,beg))
> +	   ;; End must be a marker in case body changes the text
> +	   (,end-sym (copy-marker ,end))
> +	   ;; Make sure we examine one result, even if (= beg end)
> +	   (,first-sym t))
> +       ;; We have to be careful if the region extends beyond the
> +       ;; results.  In this case, pos could be null or there could be
> +       ;; no result at pos.
> +       (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym))
> +	 (when (notmuch-search-get-result ,pos-sym)
> +	   ,@body)
> +	 (setq ,pos-sym (notmuch-search-result-end ,pos-sym)
> +	       ,first-sym nil)))))

Austin, can you explain why you use a defmacro here?  I'm honestly have
a hard time parsing what's going on here.  I understand in principle how
elisp macros work, but I don't see why it's needed here.

I'm also trying to understand what the commas are doing
(e.g. ",pos-sym").  Are they doing some sort of escaping?  

Some sophisticated elisp here!

jamie.
part-000.sig (application/pgp-signature)

Thread: