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

Austin Clements amdragon at MIT.EDU
Sat Jul 14 12:50:03 PDT 2012


Quoth Jameson Graef Rollins on Jul 14 at 12:31 pm:
> 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?

That's strange.  What was the error?

I've been testing with
   (("date" . "%12s ")
    ("count" . "%-7s ")
    ("authors" . "%-20s ")
    ("subject" . "\n%s ")
    ("tags" . "(%s)"))
But maybe there are other cases it doesn't handle correctly?

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

I did this as a macro to parallel things like dolist and loop, I'll
try this out with a higher-order procedure and see if the results are
less opaque.


More information about the notmuch mailing list