forked from mirrors/org-mode
Small refactoring
* lisp/org.el (org-macro-initialize-templates): Small refactoring.
This commit is contained in:
parent
ea77b2ccb2
commit
06bffa9120
59
lisp/org.el
59
lisp/org.el
|
@ -20938,20 +20938,19 @@ Templates are stored in buffer-local variable
|
||||||
function installs the following ones: \"property\", \"date\",
|
function installs the following ones: \"property\", \"date\",
|
||||||
\"time\". and, if appropriate, \"input-file\" and
|
\"time\". and, if appropriate, \"input-file\" and
|
||||||
\"modification-time\"."
|
\"modification-time\"."
|
||||||
(org-with-wide-buffer
|
(let ((case-fold-search t)
|
||||||
(goto-char (point-min))
|
(set-template
|
||||||
(let ((case-fold-search t)
|
(lambda (cell)
|
||||||
(set-template
|
;; Add CELL to `org-macro-templates' if there's no
|
||||||
(lambda (cell)
|
;; association matching its name already. Otherwise,
|
||||||
;; Add CELL to `org-macro-templates' if there's no
|
;; replace old association with the new one in that
|
||||||
;; association matching its CAR already. Otherwise,
|
;; variable.
|
||||||
;; replace old association with CELL.
|
(let ((old-template (assoc (car cell) org-macro-templates)))
|
||||||
(let* ((value (cdr cell))
|
(if old-template (setcdr old-template (cdr cell))
|
||||||
(key (car cell))
|
(push cell org-macro-templates))))))
|
||||||
(old-template (assoc key org-macro-templates)))
|
;; Install buffer-local macros.
|
||||||
(if old-template (setcdr old-template value)
|
(org-with-wide-buffer
|
||||||
(push cell org-macro-templates))))))
|
(goto-char (point-min))
|
||||||
;; Install buffer-local macros.
|
|
||||||
(while (re-search-forward "^[ \t]*#\\+MACRO:" nil t)
|
(while (re-search-forward "^[ \t]*#\\+MACRO:" nil t)
|
||||||
(let ((element (org-element-at-point)))
|
(let ((element (org-element-at-point)))
|
||||||
(when (eq (org-element-type element) 'keyword)
|
(when (eq (org-element-type element) 'keyword)
|
||||||
|
@ -20959,22 +20958,22 @@ function installs the following ones: \"property\", \"date\",
|
||||||
(when (string-match "^\\(.*?\\)\\(?:\\s-+\\(.*\\)\\)?\\s-*$" value)
|
(when (string-match "^\\(.*?\\)\\(?:\\s-+\\(.*\\)\\)?\\s-*$" value)
|
||||||
(funcall set-template
|
(funcall set-template
|
||||||
(cons (match-string 1 value)
|
(cons (match-string 1 value)
|
||||||
(or (match-string 2 value) ""))))))))
|
(or (match-string 2 value) "")))))))))
|
||||||
;; Install hard-coded macros.
|
;; Install hard-coded macros.
|
||||||
(mapc (lambda (cell) (funcall set-template cell))
|
(mapc (lambda (cell) (funcall set-template cell))
|
||||||
(list
|
(list
|
||||||
(cons "property" "(eval (org-entry-get nil \"$1\" 'selective))")
|
(cons "property" "(eval (org-entry-get nil \"$1\" 'selective))")
|
||||||
(cons "date" "(eval (format-time-string \"$1\"))")
|
(cons "date" "(eval (format-time-string \"$1\"))")
|
||||||
(cons "time" "(eval (format-time-string \"$1\"))")))
|
(cons "time" "(eval (format-time-string \"$1\"))")))
|
||||||
(let ((visited-file (buffer-file-name (buffer-base-buffer))))
|
(let ((visited-file (buffer-file-name (buffer-base-buffer))))
|
||||||
(when (and visited-file (file-exists-p visited-file))
|
(when (and visited-file (file-exists-p visited-file))
|
||||||
(mapc (lambda (cell) (funcall set-template cell))
|
(mapc (lambda (cell) (funcall set-template cell))
|
||||||
(list
|
(list
|
||||||
(cons "input-file" (file-name-nondirectory visited-file))
|
(cons "input-file" (file-name-nondirectory visited-file))
|
||||||
(cons "modification-time"
|
(cons "modification-time"
|
||||||
(format "(eval (format-time-string \"$1\" '%s))"
|
(format "(eval (format-time-string \"$1\" '%s))"
|
||||||
(prin1-to-string
|
(prin1-to-string
|
||||||
(nth 5 (file-attributes visited-file))))))))))))
|
(nth 5 (file-attributes visited-file)))))))))))
|
||||||
|
|
||||||
|
|
||||||
;;; Indentation
|
;;; Indentation
|
||||||
|
|
Loading…
Reference in New Issue