[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

macro temp variables

From: Eric Abrahamsen
Subject: macro temp variables
Date: Fri, 19 Sep 2014 18:49:27 +0800
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4.50 (gnu/linux)

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

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")))
        (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))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]