diff --git a/lisp/org-macro.el b/lisp/org-macro.el index 50ce43877..923e377ae 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,20 @@ 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))))))))))) + (cond (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))) + (finalize + (error "Undefined Org macro: %s; aborting." + (org-element-property :key object)))))))))))) (provide 'org-macro) diff --git a/lisp/ox.el b/lisp/ox.el index 0da9bc25a..411048e6b 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3153,7 +3153,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