unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* macro temp variables
@ 2014-09-19 10:49 Eric Abrahamsen
  2014-09-19 12:11 ` Nicolas Richard
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Abrahamsen @ 2014-09-19 10:49 UTC (permalink / raw)
  To: help-gnu-emacs

I've never actually needed to write a macro that provided temporary
local variables, and consequently am not very good at it. Despite having
read the docs and basically followed the examples there, my attempt is
producing errors.

The idea with the below is to make a macro that iterates over Org
headlines, and runs the body once for each headline: for each run, a
handful of temporary variables should be bound to various bits of the
headline.

It should be fairly clear from looking at it. "tree" should be bound
once, at the top level of the call. All the other make-symbol variables
should be re-bound with each pass of org-element-map.

I tested this with a little stub call that tried to access the 'todo
symbol, and that gets me "symbol's value as variable is void" for 'todo.
I tried replacing the inner "setq" series with a let*, and got the same
result. Clearly this is just not the way you do it, but I've tried
several different things and nothing works. Am I supposed to be using
nested back-quotes? Can someone tell me how to fix this?

(defmacro org-iter-headings (&rest body)
  (declare (indent 0))
  (let ((tree (make-symbol "tree"))
	(head (make-symbol "head"))
	(item (make-symbol "item"))
	(todo (make-symbol "todo"))
	(tags (make-symbol "tags"))
	(body-pars (make-symbol "body")))
    `(save-restriction
       (org-narrow-to-subtree
	(outline-next-heading) ; Get off the parent heading.
	(let ((,tree (org-element-parse-buffer)))
	  (org-element-map ,tree 'headline
	    (lambda (h)
	      (setq ,head (org-element-at-point)
		    ,item (org-element-property :raw-value ,head)
		    ,todo (cons
			   (org-element-property :todo-type ,head)
			   (org-element-property :todo-keyword ,head))
		    ,tags (org-element-property :tags ,head)
		    ,body-pars (org-element-map ,head 'paragraph 'identity))
	      ,@body)))))))




^ permalink raw reply	[flat|nested] 8+ messages in thread
[parent not found: <mailman.9181.1411123560.1147.help-gnu-emacs@gnu.org>]

end of thread, other threads:[~2014-09-21 20:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-19 10:49 macro temp variables Eric Abrahamsen
2014-09-19 12:11 ` Nicolas Richard
2014-09-19 15:48   ` Nicolas Richard
     [not found] <mailman.9181.1411123560.1147.help-gnu-emacs@gnu.org>
2014-09-19 17:33 ` Pascal J. Bourguignon
2014-09-19 17:45   ` Stefan Monnier
     [not found]   ` <mailman.9214.1411148764.1147.help-gnu-emacs@gnu.org>
2014-09-19 18:51     ` Pascal J. Bourguignon
2014-09-21  4:37   ` Eric Abrahamsen
     [not found]   ` <mailman.9302.1411299483.1147.help-gnu-emacs@gnu.org>
2014-09-21 20:59     ` Pascal J. Bourguignon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).