From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: macro temp variables Date: Fri, 19 Sep 2014 18:49:27 +0800 Message-ID: <87fvfnnavc.fsf@ericabrahamsen.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1411123579 9363 80.91.229.3 (19 Sep 2014 10:46:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Sep 2014 10:46:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 19 12:46:09 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XUvhZ-0001XA-34 for geh-help-gnu-emacs@m.gmane.org; Fri, 19 Sep 2014 12:46:09 +0200 Original-Received: from localhost ([::1]:57401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUvhY-0003wb-Nv for geh-help-gnu-emacs@m.gmane.org; Fri, 19 Sep 2014 06:46:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUvhH-0003wO-Ka for help-gnu-emacs@gnu.org; Fri, 19 Sep 2014 06:45:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XUvhA-00075n-4y for help-gnu-emacs@gnu.org; Fri, 19 Sep 2014 06:45:51 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:48610) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUvh9-000755-Lq for help-gnu-emacs@gnu.org; Fri, 19 Sep 2014 06:45:43 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XUvh2-0001NX-HG for help-gnu-emacs@gnu.org; Fri, 19 Sep 2014 12:45:36 +0200 Original-Received: from 123.122.40.239 ([123.122.40.239]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 19 Sep 2014 12:45:36 +0200 Original-Received: from eric by 123.122.40.239 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 19 Sep 2014 12:45:36 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 43 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 123.122.40.239 User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.4.50 (gnu/linux) Cancel-Lock: sha1:Q5/jiut4ipwoXzd//RRsUB5gyjM= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100022 Archived-At: 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)))))))