emacs-devel
[Top][All Lists]
Advanced

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

Re: HG, git and others actualize the modeline when commit form the comma


From: Óscar Fuentes
Subject: Re: HG, git and others actualize the modeline when commit form the command line
Date: Mon, 16 Nov 2020 17:36:18 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1.50 (gnu/linux)

Uwe Brauer <oub@mat.ucm.es> writes:

>    > Uwe Brauer <oub@mat.ucm.es> writes:
>
>    > This is what I use for git, wrapped into a command:
>
>    >               (vc-file-clearprops buffer-file-name)
>    >               (vc-state-refresh buffer-file-name 'Git)
>    >               (vc-mode-line buffer-file-name 'Git)
>
>    > Of course, Eli's suggestion also works, although it does a lot more
>    > than updating VC state display.
>
> Yeah the revert function is a bit slow. So you have something like this 
>
> (defun my-refresh-vc-stuff ()
> (interactive) 
> (vc-file-clearprops buffer-file-name)
> (vc-state-refresh buffer-file-name 'Git)
> (vc-mode-line buffer-file-name 'Git))
>
> And bind that to key or insert it into a hook?

I use those functions on a magit fork of mine (for updating the modeline
after certain magit commands) but, for your use case, IMO a command like
your example above is what you need. You can even travel the buffer
list, so you don't need to execute the command for every buffer that
might be affected:

  (dolist (buffer (buffer-list))
    (when (string-prefix-p (expand-file-name default-directory)
                           (buffer-file-name buffer))
      (with-current-buffer buffer
        (with-demoted-errors "Error mientras revirtiendo (ignorado) %S"
          (if (and vc-mode (buffer-stale--default-function t)
                   (not (buffer-modified-p)))
              (revert-buffer t t)
            (vc-file-clearprops buffer-file-name)
            (vc-state-refresh buffer-file-name 'Git)
            (vc-mode-line buffer-file-name 'Git))))))

The code above travels the buffers and, for each buffer which is
visiting a file under the current directory or its childs, either
reverts the buffer (if it is not modified and its contents might have
changed) or just updates the modeline.

As you also use Hg, you need to adapt the code for using the correct
backeng on each case: (vc-backend buffer-file-name) looks like the
correct thing, but I didn't test it.




reply via email to

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