>From a3298310fe5f399dacd5ab13b725a95d9c626a21 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Thu, 28 Apr 2016 17:15:29 +0200 Subject: [PATCH 1/3] org-macro: Maybe get modification-time from vc.el * org-macro.el (org-macro-initialize-templates): Check modification-time in version control via vc. * doc/org.texi (Macro replacement): Document new behavior. * etc/ORG-NEWS: Mention new behavior. --- doc/org.texi | 6 +++--- etc/ORG-NEWS | 4 +++- lisp/org-macro.el | 27 ++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 17b01c2..bc08277 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -10251,9 +10251,9 @@ understood by @code{format-time-string}. @cindex time, macro @cindex modification time, macro These macros refer to the date and time when the document is exported and to -the modification date and time of the file being exported, respectively. address@hidden should be a format string understood by address@hidden +the modification date, potentially found via version control, and time of the +file being exported, respectively. @var{FORMAT} should be a format string +understood by @code{format-time-string}. @item @address@hidden@address@hidden@address@hidden @cindex input file, macro diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 99241e2..c8b1627 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -104,7 +104,9 @@ is straightforward. For example becomes : ("pdf" . (lambda (file link) (foo))) - +*** ~{{{modification-time}}}~ tries to obtain time via =vc= +As a fallback, the modification time will be found via the file +system. ** New features *** New org-protocol key=value syntax diff --git a/lisp/org-macro.el b/lisp/org-macro.el index 5e9be98..debe6b0 100644 --- a/lisp/org-macro.el +++ b/lisp/org-macro.el @@ -59,6 +59,9 @@ (declare-function org-mode "org" ()) (declare-function org-remove-double-quotes "org" (s)) (declare-function org-with-wide-buffer "org-macs" (&rest body)) +(declare-function vc-backend "vc-hooks" (f)) +(declare-function vc-call "vc-hooks" (&rest args)) +(declare-function vc-exec-after "vc-dispatcher" (code)) ;;; Variables @@ -148,7 +151,29 @@ function installs the following ones: \"property\", (cons "modification-time" (format "(eval (format-time-string \"$1\" '%s))" (prin1-to-string - (nth 5 (file-attributes visited-file))))))))) + (or + ;; First, check if file has a VC modification time. + (save-window-excursion + (when (vc-backend visited-file) + (let ((buf (get-buffer-create " *org-vc*")) + date) + (vc-call print-log visited-file buf nil nil 1) + (with-current-buffer buf + (vc-exec-after + (lambda () + (goto-char (point-min)) + (when (search-forward-regexp "Date:?[ \t]*" nil t) + (let ((time (parse-time-string + (buffer-substring + (point) (point-at-eol))))) + (when (org-some 'identity time) + (setq date (apply 'encode-time time)))))))) + (let ((proc (get-buffer-process buf))) + (while (and proc (accept-process-output proc .5 nil t)))) + (kill-buffer " *org-vc*") + date))) + ;; Otherwise use the time registered by the file system. + (nth 5 (file-attributes visited-file)))))))))) (setq org-macro-templates templates))) (defun org-macro-expand (macro templates) -- 2.8.0