Function: org-macro-initialize-templates

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

Signature

(org-macro-initialize-templates &optional DEFAULT)

Documentation

Collect macro templates defined in current buffer.

DEFAULT is a list of globally available templates.

Templates are stored in buffer-local variable org-macro-templates.

In addition to buffer-defined macros, the function installs the following ones: "n", "author", "email", "keyword",
"time", "property", and, if the buffer is associated to
a file, "input-file" and "modification-time".

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-macro.el.gz
(defun org-macro-initialize-templates (&optional default)
  "Collect macro templates defined in current buffer.

DEFAULT is a list of globally available templates.

Templates are stored in buffer-local variable `org-macro-templates'.

In addition to buffer-defined macros, the function installs the
following ones: \"n\", \"author\", \"email\", \"keyword\",
\"time\", \"property\", and, if the buffer is associated to
a file, \"input-file\" and \"modification-time\"."
  (require 'org-element)
  (org-macro--counter-initialize)	;for "n" macro
  (setq org-macro-templates
	(nconc
	 ;; Install user-defined macros.  Local macros have higher
         ;; precedence than global ones.
         (org-macro--set-templates (append default (org-macro--collect-macros)))
	 ;; Install file-specific macros.
	 (let ((visited-file (buffer-file-name (buffer-base-buffer))))
	   (and visited-file
		(file-exists-p visited-file)
		(list
		 `("input-file" . ,(file-name-nondirectory visited-file))
		 `("modification-time" .
		   ,(let ((modtime (file-attribute-modification-time
                                    (file-attributes visited-file))))
		      (lambda (arg1 &optional arg2 &rest _)
                        (format-time-string
                         arg1
                         (or (and (org-string-nw-p arg2)
                                  (org-macro--vc-modified-time visited-file))
                             modtime))))))))
	 ;; Install generic macros.
	 '(("keyword" . (lambda (arg1 &rest _)
                          (org-macro--find-keyword-value arg1 t)))
	   ("n" . (lambda (&optional arg1 arg2 &rest _)
                    (org-macro--counter-increment arg1 arg2)))
           ("property" . (lambda (arg1 &optional arg2 &rest _)
                           (org-macro--get-property arg1 arg2)))
	   ("time" . (lambda (arg1 &rest _)
                       (format-time-string arg1)))))))