| 
					
				 | 
			
			
				@@ -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) 
			 |