From c44b9b1f9a88e3bb88d1b4d9b59284ae840f02ce Mon Sep 17 00:00:00 2001 From: Aaron Ecay Date: Wed, 4 Nov 2015 12:13:07 +0000 Subject: [PATCH] macros: automatically quote the arguments to an eval macro * lisp/org-macro.el (org-macro-expand): Automatically quote the arguments to an eval macro. --- lisp/org-macro.el | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lisp/org-macro.el b/lisp/org-macro.el index 5f9c227..4858427 100644 --- a/lisp/org-macro.el +++ b/lisp/org-macro.el @@ -159,20 +159,24 @@ MACRO is an object, obtained, for example, with `org-element-context'. TEMPLATES is an alist of templates used for expansion. See `org-macro-templates' for a buffer-local default value. Return nil if no template was found." - (let ((template - ;; Macro names are case-insensitive. - (cdr (assoc-string (org-element-property :key macro) templates t)))) + (let* ((template + ;; Macro names are case-insensitive. + (cdr (assoc-string (org-element-property :key macro) templates t))) + ;; Macro starts with "(eval": it is a s-exp and will be `eval'-ed. + (evalp (string-match "\\`(eval\\>" template))) (when template (let ((value (replace-regexp-in-string "\\$[0-9]+" (lambda (arg) - (or (nth (1- (string-to-number (substring arg 1))) - (org-element-property :args macro)) - ;; No argument: remove place-holder. - "")) + (let ((arg-val (nth (1- (string-to-number (substring arg 1))) + (org-element-property :args macro)))) + (cond + (evalp (format "%S" arg-val)) + (arg-val arg-val) + ;; No argument: remove place-holder. + (t "")))) template nil 'literal))) - ;; VALUE starts with "(eval": it is a s-exp, `eval' it. - (when (string-match "\\`(eval\\>" value) + (when evalp (setq value (eval (read value)))) ;; Return string. (format "%s" (or value "")))))) -- 2.6.2