Function: org-macro-expand

org-macro-expand is a byte-compiled function defined in org-macro.el.gz.

Signature

(org-macro-expand MACRO TEMPLATES)

Documentation

Return expanded MACRO, as a string.

MACRO is an object, obtained, for example, with org-element-context. TEMPLATES is an alist of templates used for expansion. See org-macro-templates for a buffer-local default value. Return nil if no template was found.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-macro.el.gz
(defun org-macro-expand (macro templates)
  "Return expanded MACRO, as a string.
MACRO is an object, obtained, for example, with
`org-element-context'.  TEMPLATES is an alist of templates used
for expansion.  See `org-macro-templates' for a buffer-local
default value.  Return nil if no template was found."
  (let ((template
	 ;; Macro names are case-insensitive.
	 (cdr (assoc-string (org-element-property :key macro) templates t))))
    (when template
      (let* ((value
	      (if (functionp template)
                  (apply template (org-element-property :args macro))
                (replace-regexp-in-string
                 "\\$[0-9]+"
                 (lambda (m)
		   (or (nth (1- (string-to-number (substring m 1)))
			    (org-element-property :args macro))
		       ;; No argument: remove place-holder.
		       ""))
		 template nil 'literal))))
        ;; Force return value to be a string.
        (format "%s" (or value ""))))))