bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#21559: [PATCH] autorevert: Wait a while before calling vc-find-file-


From: Michael Albinus
Subject: bug#21559: [PATCH] autorevert: Wait a while before calling vc-find-file-hook
Date: Thu, 29 Oct 2015 09:20:25 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Ben Gamari <ben@smart-cactus.org> writes:

> Hi Michael,

Hi Ben,

> Ultimately the problem here is an annoyingly narrow one, namely the fact
> that auto-revert's action is correlated with file modifications due to
> rebasing. For this reason I think it may be best to keep the solution
> confined to auto-revert.
>
> In particular, I'm afraid that the changing the semantics of
> revert-buffer may break other users of this function who expect
> its effect to be apparent immediately after invocation. It seems like
> this approach may easily and unwittingly trade one subtle form of
> breakage for another (even harder to find) one.

I agree with you not to change the behaviour of revert-buffer for other
use cases but auto-revert. One could do it by introducing a new local
variable auto-revert-buffer-in-progress-p (similar to
revert-buffer-in-progress-p), which is bound during auto-revert. Then it
would be possible to define a new function

(defun vc-git-revert-buffer-function (ignore-auto noconfirm)
  "vc-git specific revert function."
  (if (and auto-revert-buffer-in-progress-p
           (check-for-git-rebase))
      (do-something-special)
    (revert-buffer--default ignore-auto noconfirm)))

One could also check, whether adding a function to before-revert-hook
could be helpful.

An alternative, w/o touching revert-buffer for vc-git files, would be
the provisiong of a special buffer-stale-function for vc-git. Something
like

(defun vc-git-buffer-stale-p (&optional noconfirm)
  "vc-git specific buffer-stale function."
  (check-that-git-needs-revert-and-it-is-safe-to-do-so))

This function returns t, when a buffer with a file under vc-git mode
needs a revert, and it is safe to revert it (no git rebase is
running). When autorevert either polls, or it is indicated by a file
notification event, it calls this function and reverts the buffer if the
function returns non-nil. If the function returns nil, auto-revert is
skipped for that buffer, and it is checked again by the next poll (after
5 seconds). By this, autorevert.el would stay clean (no additional vc
related code), and you would even not need to implement an own timer.

> Cheers,
>
> - Ben

Best regards, Michael.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]