mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2025-01-05 11:45:52 +00:00
Export: More default macros.
This commit adds: {{{date(FORMAT)}}} current date/time, formatted with `format-time-string' {{{modification-time(FORMAT)}}} date/time of last modification of file, formatted with `format-time-string' {{{input-file}}} the file name of the source Org file.
This commit is contained in:
parent
21e08a117d
commit
ab0397758e
@ -1,3 +1,7 @@
|
||||
2009-05-11 Carsten Dominik <carsten.dominik@gmail.com>
|
||||
|
||||
* org.texi (Macro replacement): Document new macros.
|
||||
|
||||
2009-05-10 Carsten Dominik <carsten.dominik@gmail.com>
|
||||
|
||||
* org.texi (Handling links): Document type-specific completion
|
||||
|
@ -8165,6 +8165,10 @@ You can define text snippets with
|
||||
code examples) with @code{@{@{@{name@}@}@}}. In addition to defined macros,
|
||||
@code{@{@{@{title@}@}@}}, @code{@{@{@{author@}@}@}}, etc will reference
|
||||
information set by the @code{#+TITLE:}, @code{#+AUTHOR:}, and similar lines.
|
||||
Also, @code{@{@{@{date(FORMAT@}@}@}} and
|
||||
@code{@{@{@{modification-time(FORMAT)@}@}@}} refer to current date time and
|
||||
to the modification time of the file being exported, respectively. FORMAT
|
||||
should be a format string understood by @code{format-time-string}.
|
||||
|
||||
@node Selective export, Export options, Markup rules, Exporting
|
||||
@section Selective export
|
||||
|
@ -1,3 +1,8 @@
|
||||
2009-05-11 Carsten Dominik <carsten.dominik@gmail.com>
|
||||
|
||||
* org-exp.el (org-infile-export-plist): Add more default macros.
|
||||
(org-export-preprocess-apply-macros): Process macro arguments.
|
||||
|
||||
2009-05-10 Carsten Dominik <carsten.dominik@gmail.com>
|
||||
|
||||
* org-icalendar.el (org-icalendar-include-todo): New allowedvalue
|
||||
|
@ -685,6 +685,20 @@ modified) list.")
|
||||
(when options
|
||||
(setq p (org-export-add-options-to-plist p options)))
|
||||
;; Add macro definitions
|
||||
(setq p (plist-put p :macro-date "(eval (format-time-string \"$1\"))"))
|
||||
(setq p (plist-put p :macro-time "(eval (format-time-string \"$1\"))"))
|
||||
(setq p (plist-put
|
||||
p :macro-modification-time
|
||||
(and (buffer-file-name)
|
||||
(file-exists-p (buffer-file-name))
|
||||
(concat
|
||||
"(eval (format-time-string \"$1\" '"
|
||||
(prin1-to-string (nth 5 (file-attributes
|
||||
(buffer-file-name))))
|
||||
"))"))))
|
||||
(setq p (plist-put p :macro-input-file (and (buffer-file-name)
|
||||
(file-name-nondirectory
|
||||
(buffer-file-name)))))
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward
|
||||
"^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
|
||||
@ -1974,13 +1988,29 @@ TYPE must be a string, any of:
|
||||
(defun org-export-preprocess-apply-macros ()
|
||||
"Replace macro references."
|
||||
(goto-char (point-min))
|
||||
(let (sy val key)
|
||||
(while (re-search-forward "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)}}}" nil t)
|
||||
(setq key (downcase (match-string 1)))
|
||||
(let (sy val key args s n)
|
||||
(while (re-search-forward
|
||||
"{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\(.*?\\))\\)?}}}"
|
||||
nil t)
|
||||
(setq key (downcase (match-string 1))
|
||||
args (match-string 3))
|
||||
(when (setq val (or (plist-get org-export-opt-plist
|
||||
(intern (concat ":macro-" key)))
|
||||
(plist-get org-export-opt-plist
|
||||
(intern (concat ":" key)))))
|
||||
(save-match-data
|
||||
(when args
|
||||
(setq args (org-split-string args ","))
|
||||
(setq s 0)
|
||||
(while (string-match "\\$\\([0-9]+\\)" val s)
|
||||
(setq s (1+ (match-beginning 0))
|
||||
n (string-to-number (match-string 1 val)))
|
||||
(and (>= (length args) n)
|
||||
(setq val (replace-match (nth (1- n) args) t t val)))))
|
||||
(when (string-match "\\`(eval\\>" val)
|
||||
(setq val (eval (read val))))
|
||||
(if (and val (not (stringp val)))
|
||||
(setq val (format "%s" val))))
|
||||
(and (stringp val)
|
||||
(replace-match val t t))))))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user