forked from mirrors/org-mode
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.
This commit is contained in:
parent
56256a09df
commit
5f423f1208
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue