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

Jameson Graef Rollins jrollins at finestructure.net
Sat Jul 14 12:31:45 PDT 2012


On Fri, Jul 13 2012, Austin Clements <amdragon at 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)
> +	   , at 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20120714/8a361946/attachment.pgp>


More information about the notmuch mailing list