all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Rasmus <rasmus@gmx.us>
To: help-gnu-emacs@gnu.org
Subject: vc.el and modified time
Date: Wed, 27 Apr 2016 17:36:38 +0200	[thread overview]
Message-ID: <87fuu7qd15.fsf@gmx.us> (raw)

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))))))



-- 
⠠⠵




             reply	other threads:[~2016-04-27 15:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-27 15:36 Rasmus [this message]
2016-04-27 16:06 ` vc.el and modified time Stefan Monnier
2016-04-27 17:17   ` Rasmus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fuu7qd15.fsf@gmx.us \
    --to=rasmus@gmx.us \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.