浏览代码

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.
Aaron Ecay 10 年之前
父节点
当前提交
5f423f1208
共有 2 个文件被更改,包括 22 次插入14 次删除
  1. 20 13
      lisp/org-macro.el
  2. 2 1
      lisp/ox.el

+ 20 - 13
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)

+ 2 - 1
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