From e386809601d99291885136de1d9be84193b69a2c Mon Sep 17 00:00:00 2001 From: Aaron Ecay Date: Sat, 27 Sep 2014 23:50:23 -0400 Subject: [PATCH] Warn about unexpanded macros on export * lisp/org-macro.el (org-macro-replace-all): Add optional `finalize' argument. * lisp/ox.el (org-export-as): Use it. --- lisp/org-macro.el | 35 ++++++++++++++++++++++------------- lisp/ox.el | 3 ++- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lisp/org-macro.el b/lisp/org-macro.el index 50ce438..307e232 100644 --- a/lisp/org-macro.el +++ b/lisp/org-macro.el @@ -155,10 +155,14 @@ default value. Return nil if no template was found." ;; Return string. (format "%s" (or value "")))))) -(defun org-macro-replace-all (templates) +(defun org-macro-replace-all (templates &optional finalize) "Replace all macros in current buffer by their expansion. + TEMPLATES is an alist of templates used for expansion. See -`org-macro-templates' for a buffer-local default value." +`org-macro-templates' for a buffer-local default value. + +If optional arg FINALIZE is non-nil, raise an error if a macro is +found in the buffer with no definition in TEMPLATES." (save-excursion (goto-char (point-min)) (let (record) @@ -176,17 +180,22 @@ TEMPLATES is an alist of templates used for expansion. See (if (member signature record) (error "Circular macro expansion: %s" (org-element-property :key object)) - (when value - (push signature record) - (delete-region - begin - ;; Preserve white spaces after the macro. - (progn (goto-char (org-element-property :end object)) - (skip-chars-backward " \t") - (point))) - ;; Leave point before replacement in case of recursive - ;; expansions. - (save-excursion (insert value))))))))))) + (if value + (progn + (push signature record) + (delete-region + begin + ;; Preserve white spaces after the macro. + (progn (goto-char (org-element-property :end object)) + (skip-chars-backward " \t") + (point))) + ;; Leave point before replacement in case of recursive + ;; expansions. + (save-excursion (insert value))) + (when finalize + (error "Macro %s was undefined at line %s" + (org-element-property :key object) + (line-number-at-pos)))))))))))) (provide 'org-macro) diff --git a/lisp/ox.el b/lisp/ox.el index 59091fc..216a375 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3136,7 +3136,8 @@ Return code as a string." ;; EMAIL is not a parsed keyword: store it as-is. (cons "email" (or (plist-get info :email) "")) (cons "title" - (org-element-interpret-data (plist-get info :title))))) + (org-element-interpret-data (plist-get info :title)))) + 'finalize) ;; Parse buffer. (setq tree (org-element-parse-buffer nil visible-only)) ;; Handle left-over uninterpreted elements or objects in -- 2.1.1