diff --git a/doc/ChangeLog b/doc/ChangeLog index f180d6f91..390f113cb 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2009-05-11 Carsten Dominik + + * org.texi (Macro replacement): Document new macros. + 2009-05-10 Carsten Dominik * org.texi (Handling links): Document type-specific completion diff --git a/doc/org.texi b/doc/org.texi index 04fd80e78..ca5510d6c 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -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 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c00da4f78..ccacc00de 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2009-05-11 Carsten Dominik + + * org-exp.el (org-infile-export-plist): Add more default macros. + (org-export-preprocess-apply-macros): Process macro arguments. + 2009-05-10 Carsten Dominik * org-icalendar.el (org-icalendar-include-todo): New allowedvalue diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 71781187f..4e87a4fd4 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -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))))))