all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / 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

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

> 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*.

You can avoid hardcoding it by using

   (vc-call print-log file <buf> ...)

See lisp/vc/vc.el's commentary where it describes

    ;; * print-log (files buffer &optional shortlog start-revision limit)
    ;;
    ;;   Insert the revision log for FILES into BUFFER.
    ;;   If SHORTLOG is true insert a short version of the log.
    ;;   If LIMIT is true insert only insert LIMIT log entries.  If the
    ;;   backend does not support limiting the number of entries to show
    ;;   it should return `limit-unsupported'.
    ;;   If START-REVISION is given, then show the log starting from that
    ;;   revision ("starting" in the sense of it being the _newest_
    ;;   revision shown, rather than the working revision, which is normally
    ;;   the case).  Not all backends support this.  At present, this is
    ;;   only ever used with LIMIT = 1 (by
    ;;   vc-annotate-show-log-revision-at-line).

> Second, *vc-change-log* is build asynchronously, at least sometimes,
> and I don’t know how I can check if it’s done.

You can do

   (with-current-buffer <buf>
     (vc-exec-after
      (lambda ()
        <the-code-to-run-after-print-log-is-done>)))

[ Here, I presume you're using -*- lexical-binding:t -*-, which I strongly
  recommend.  ]


        Stefan




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

* Re: vc.el and modified time
  2016-04-27 16:06 ` Stefan Monnier
@ 2016-04-27 17:17   ` Rasmus
  0 siblings, 0 replies; 3+ messages in thread
From: Rasmus @ 2016-04-27 17:17 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Stefan,

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> 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*.
>
> You can avoid hardcoding it by using
>
>    (vc-call print-log file <buf> ...)
>
> See lisp/vc/vc.el's commentary where it describes
>
>     ;; * print-log (files buffer &optional shortlog start-revision limit)
>     ;;
>     ;;   Insert the revision log for FILES into BUFFER.
>     ;;   If SHORTLOG is true insert a short version of the log.
>     ;;   If LIMIT is true insert only insert LIMIT log entries.  If the
>     ;;   backend does not support limiting the number of entries to show
>     ;;   it should return `limit-unsupported'.
>     ;;   If START-REVISION is given, then show the log starting from that
>     ;;   revision ("starting" in the sense of it being the _newest_
>     ;;   revision shown, rather than the working revision, which is normally
>     ;;   the case).  Not all backends support this.  At present, this is
>     ;;   only ever used with LIMIT = 1 (by
>     ;;   vc-annotate-show-log-revision-at-line).

Brilliant!  I read that part, but I didn’t understand since the signature
of vc-print-log didn’t have a buffer argument (only the vc-backend-log
functions).  Thanks for showing me how to use vc-call!

>> Second, *vc-change-log* is build asynchronously, at least sometimes,
>> and I don’t know how I can check if it’s done.
>
> You can do
>
>    (with-current-buffer <buf>
>      (vc-exec-after
>       (lambda ()
>         <the-code-to-run-after-print-log-is-done>)))

Cool, thanks!

> [ Here, I presume you're using -*- lexical-binding:t -*-, which I strongly
>   recommend.  ]

Yes.

Thanks for the hints!

Rasmus

-- 
You people at the NSA are becoming my new best friends!




^ 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

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.