unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* vc.el and modified time
@ 2016-04-27 15:36 Rasmus
  2016-04-27 16:06 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Rasmus @ 2016-04-27 15:36 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I would like to obtain the modification time of a file as registered by my
version control.  Thus, vc.el springs to mind.

My first attempt is below, but I’m not entirely happy with it.  First, it
is intrusive as it might overwrite the user’s *vc-change-log*.  Second,
*vc-change-log* is build asynchronously, at least sometimes, and I don’t
know how I can check if it’s done.

Does there exists a more systematic or "script friendly" way to consumer
logs from vc.el?  The only interface that I found that seems public is the
ones that write the information to *vc-change-log*.

Thanks,
Rasmus

(defun org--get-modified-time-vc (file)
  "Get the modified time of FILE as recorded by version control."
  (when (vc-backend file)
    ;; TODO: It seems that `*vc-change-log*' is the hardcoded.  It is
    ;; quite intrusive as it would mean that calling the function
    ;; would change this buffer.  Is there a better way than to kill
    ;; old buffer to make sure `*vc-change-log*' is current?
    (if (get-buffer "*vc-change-log*")
        (kill-buffer "*vc-change-log*"))
    (save-window-excursion
      (with-current-buffer (or (find-buffer-visiting file)
                               (find-file-noselect file))
        (vc-print-log nil 1)
        (bury-buffer)))
    (when (get-buffer "*vc-change-log*")
      (let ((date (with-current-buffer  (get-buffer "*vc-change-log*")
                    ;; TODO: The buffer is updated asynchronously so
                    ;; we need to wait.  Is there a better way to wait
                    ;; until vc-log has done its thing?
                    (sit-for .1)
                    (goto-char (point-min))
                    (when (search-forward-regexp "Date:?[ \t]*" nil t)
                      (buffer-substring (point) (point-at-eol))))))
        (let ((time (parse-time-string (or date ""))))
          (when (org-some 'identity time) time))))))



-- 
⠠⠵




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-04-27 17:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-27 15:36 vc.el and modified time Rasmus
2016-04-27 16:06 ` Stefan Monnier
2016-04-27 17:17   ` Rasmus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).