From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [patch] get modification-time from vc Date: Wed, 18 May 2016 12:12:57 +0200 Message-ID: <87k2irad3q.fsf@gmx.us> References: <877ffhn3gz.fsf@gmx.us> <87shy2ydpx.fsf@saiph.selenimh> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2yTZ-0001uB-Ve for emacs-orgmode@gnu.org; Wed, 18 May 2016 06:13:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2yTT-0008Ti-Tx for emacs-orgmode@gnu.org; Wed, 18 May 2016 06:13:12 -0400 Received: from mout.gmx.net ([212.227.17.22]:60996) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2yTT-0008Tc-JX for emacs-orgmode@gnu.org; Wed, 18 May 2016 06:13:07 -0400 Received: from W530 ([46.166.190.211]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0LeNGL-1bM9SW1nKf-00q9Yq for ; Wed, 18 May 2016 12:13:05 +0200 In-Reply-To: <87shy2ydpx.fsf@saiph.selenimh> (Nicolas Goaziou's message of "Sat, 30 Apr 2016 23:43:38 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, An overdue "Thanks" for the feedback. Here=E2=80=99s a new version. Nicolas Goaziou writes: > Well, if you ask, I do not like much when some software tries to > outsmart me (note that I like it even less when it actually succeeds). > So, I think {{{modification-time}}} should expand to modification time. New idea, an optional 2nd argument to modification-time. E.g. {{{modification-time(%Y, vc)}}} > If you think that is useful, then I vote for a different macro. I prefer an argument as it gives a clear ranking: get the modified time from vc, if possible (if the second argument is vc), otherwise get it from the file system (also default behavior). >> + (when (org-some 'identity time) > > (cl-some #'identity time) Is cl-lib OK now?! Thanks, Rasmus --=20 ... The proofs are technical in nature and provide no real understanding --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-macro.el-Allow-modification-time-from-vc.el.patch >From 20f2268c7555c08e26654c77c0191012e176e059 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Wed, 18 May 2016 11:23:46 +0200 Subject: [PATCH 1/3] org-macro.el: Allow modification-time from vc.el * org-macro.el (org-macro--vc-modified-time): New function. * org-macro.el (org-macro-initialize-templates): Add support for new function. * doc/org.texi (Macro replacement): Document new behavior. * etc/ORG-NEWS: Mention new behavior. --- doc/org.texi | 9 +++++---- etc/ORG-NEWS | 3 +++ lisp/org-macro.el | 32 +++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 0bfee39..f0fd8bb 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -10247,13 +10247,14 @@ argument to the @code{@{@{@{date@}@}@}} macro that will be used only if understood by @code{format-time-string}. @item @{@{@{time(@var{FORMAT})@}@}@} -@itemx @{@{@{modification-time(@var{FORMAT})@}@}@} +@itemx @{@{@{modification-time(@var{FORMAT}, @var{VC})@}@}@} @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. -@var{FORMAT} should be a format string understood by -@code{format-time-string}. +the modification date and time, respectively. @var{FORMAT} should be a +format string understood by @code{format-time-string}. If the second +argument to the @code{modification-time} macro is @samp{vc}, Org will try to +find the modification time via version control (using @code{vc.el}). @item @{@{@{input-file@}@}@} @cindex input file, macro diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 7a0a890..370963e 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -105,6 +105,9 @@ becomes : ("pdf" . (lambda (file link) (foo))) +*** The ~{{{modification-time}}}~ macro can obtain time via =vc= +The modification time will be determined via =vc.el= if the second +argument is =vc=. See the manual for details. ** New features *** New org-protocol key=value syntax diff --git a/lisp/org-macro.el b/lisp/org-macro.el index e135374..d86aaee 100644 --- a/lisp/org-macro.el +++ b/lisp/org-macro.el @@ -58,6 +58,10 @@ (declare-function org-file-contents "org" (file &optional noerror)) (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 @@ -145,11 +149,13 @@ function installs the following ones: \"property\", (mapc update-templates (list (cons "input-file" (file-name-nondirectory visited-file)) (cons "modification-time" - (format "(eval (format-time-string \"$1\" '%s))" + (format "(eval (format-time-string \"$1\" (or (when (equal (org-trim (downcase \"$2\")) \"vc\") (org-macro--vc-modified-time %s)) '%s)))" + (prin1-to-string visited-file) (prin1-to-string (nth 5 (file-attributes visited-file))))))))) (setq org-macro-templates templates))) + (defun org-macro-expand (macro templates) "Return expanded MACRO, as a string. MACRO is an object, obtained, for example, with @@ -276,6 +282,30 @@ Return a list of arguments, as strings. This is the opposite of s nil t) "\000")) +(defun org-macro--vc-modified-time (file) + (save-window-excursion + (when (vc-backend file) + (let ((buf (get-buffer-create " *org-vc*")) + (case-fold-search t) + date) + (unwind-protect + (progn + (vc-call print-log file buf nil nil 1) + (with-current-buffer buf + (vc-exec-after + (lambda () + (goto-char (point-min)) + (when (re-search-forward "Date:?[ \t]*" nil t) + (let ((time (parse-time-string + (buffer-substring + (point) (line-end-position))))) + (when (cl-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 buf)) + date)))) + (provide 'org-macro) ;;; org-macro.el ends here -- 2.8.2 --=-=-=--