Small refactoring

* lisp/org.el (org-macro-initialize-templates): Small refactoring.
This commit is contained in:
Nicolas Goaziou 2012-09-01 11:50:51 +02:00
parent ea77b2ccb2
commit 06bffa9120
1 changed files with 29 additions and 30 deletions

View File

@ -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
(goto-char (point-min))
(let ((case-fold-search t) (let ((case-fold-search t)
(set-template (set-template
(lambda (cell) (lambda (cell)
;; Add CELL to `org-macro-templates' if there's no ;; Add CELL to `org-macro-templates' if there's no
;; association matching its CAR already. Otherwise, ;; association matching its name already. Otherwise,
;; replace old association with CELL. ;; replace old association with the new one in that
(let* ((value (cdr cell)) ;; variable.
(key (car cell)) (let ((old-template (assoc (car cell) org-macro-templates)))
(old-template (assoc key org-macro-templates))) (if old-template (setcdr old-template (cdr cell))
(if old-template (setcdr old-template value)
(push cell org-macro-templates)))))) (push cell org-macro-templates))))))
;; Install buffer-local macros. ;; Install buffer-local macros.
(org-with-wide-buffer
(goto-char (point-min))
(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,7 +20958,7 @@ 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
@ -20974,7 +20973,7 @@ function installs the following ones: \"property\", \"date\",
(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