emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH 0/8] Org mode macros, refactored
@ 2011-08-02  9:23 David Maus
  2011-08-02  9:23 ` [PATCH 1/7] New macro: Execute BODY in enviroment with uninterned SYMBOLS David Maus
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: David Maus @ 2011-08-02  9:23 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: David Maus

Following series of patches is product of some refactoring of
macro-usage in Org mode. It defines two new macros and applies those
macros in other macros in org-macs and batch-agenda functions.

Comments are welcome. I'll create a bundle for the patches in
patchwork. If there are no objections I would like to push these
changes at the end of the week.

Maybe the most conveniant macro for further development is

(org-with-uninterend SYMBOLS BODY)

This macro wraps BODY in a let binding form where each symbol in
SYMBOLS is bound to a new but uninterned symbol of the same name. This
way you can avoid leaking or, more precisely, capturing of symbols if
you write a macro that needs to bind its own control variables in the
macro expansion form.

E.g.

(defmacro org-preserve-lc (&rest body)
  `(let ((line (org-current-line))
         (col (current-column)))
     (unwind-protect
       (progn ,@body)
	 (org-goto-line line)
	 (org-move-to-column col))))

The let binding at the top of the expansion form shadows symbols with
the name line and cols if they are bound before BODY, and if BODY uses
symbols with the same name it would overwrite the symbols bound in the
let form.

Org-with-uninterned prevents this by creating new uninterned symbols
which are unreachable outside the expanded form and inside BODY.

(defmacro org-preserve-lc (&rest body)
  (org-with-uninterned (line col)
    `(let ((,line (org-current-line))
	   (,col (current-column)))
       (unwind-protect
	   (progn ,@body)
	 (org-goto-line ,line)
	 (org-move-to-column ,col)))))

Expands to:

(let
    ((line
      (make-symbol
       (symbol-name 'line)))
     (col
      (make-symbol
       (symbol-name 'col))))
  `(let
       ((,line
	 (org-current-line))
	(,col
	 (current-column)))
     (unwind-protect
	 (progn ,@body)
       (org-goto-line ,line)
       (org-move-to-column ,col))))

This way ,line and ,col in the macro expansion refer to the new
uninterned symbols line and col created outside the expansion form.

Note: The usage of make-symbol works but has one drawback: The new
uninterned symbols have the same name as the maybe interned symbols in
BODY. Ideally we should use `gensym' instead, which creates a new
uninterned symbol with a unique name. But gensym is part of the
cl-package and thus not allowed to be called at runtime for a program
to be part of Emacs core.

David Maus (8):
  New macro: Execute BODY in enviroment with uninterned SYMBOLS.
  Use new macro org-with-uninterned
  New macro: Evaluate BODY in ENVIRONMENT
  New function: Substitute posix classes in regular expression
  Use macro org-with-uninterned
  New function: Turn a flat parameter list into an alist
  Use org-eval-in-environment, make macros functions
  Make org-batch-store-agenda-views a fun, use org-eval-in-environment

 lisp/org-agenda.el |   92 ++++++++++++++++-------------------
 lisp/org-macs.el   |  137 +++++++++++++++++++++++++++++++---------------------
 2 files changed, 123 insertions(+), 106 deletions(-)

-- 
1.7.2.5

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2011-08-16 17:30 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-02  9:23 [PATCH 0/8] Org mode macros, refactored David Maus
2011-08-02  9:23 ` [PATCH 1/7] New macro: Execute BODY in enviroment with uninterned SYMBOLS David Maus
2011-08-02 13:48   ` David Maus
     [not found]   ` <CAJcAo8uv46JCx9cG0x_ip9DMQ-aN=buLRO_fONPoFuDkik6J1Q@mail.gmail.com>
2011-08-10  7:43     ` David Maus
2011-08-16 16:34       ` Bastien
2011-08-16 17:08         ` David Maus
2011-08-16 17:30           ` Bastien
2011-08-02  9:23 ` [PATCH 2/7] New macro: Evaluate FORM in ENVIRONMENT David Maus
2011-08-02 10:50   ` Štěpán Němec
2011-08-02 13:25     ` David Maus
2011-08-02 13:49   ` David Maus
2011-08-02  9:23 ` [PATCH 3/7] Use new macro org-with-uninterned David Maus
2011-08-02  9:23 ` [PATCH 4/7] New function: Substitute posix classes in regular expression David Maus
2011-08-02  9:23 ` [PATCH 5/7] Use macro org-with-uninterned David Maus
2011-08-02  9:23 ` [PATCH 6/7] Use org-eval-in-environment, make macros functions David Maus
2011-08-02  9:23 ` [PATCH 7/7] Make org-batch-store-agenda-views a fun, use org-eval-in-environment David Maus
2011-08-02  9:34 ` [PATCH 0/8] Org mode macros, refactored David Maus
2011-08-02 10:44 ` Štěpán Němec

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).