unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Óscar Fuentes" <ofv@wanadoo.es>
To: emacs-devel@gnu.org
Subject: Re: HG, git and others actualize the modeline when commit form the command line
Date: Mon, 16 Nov 2020 17:36:18 +0100	[thread overview]
Message-ID: <877dqlw96l.fsf@telefonica.net> (raw)
In-Reply-To: 87ima58f0s.fsf@mat.ucm.es

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	other threads:[~2020-11-16 16:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16 12:42 HG, git and others actualize the modeline when commit form the command line Uwe Brauer
2020-11-16 13:18 ` Eli Zaretskii
2020-11-16 16:02   ` Uwe Brauer
2020-11-16 17:30     ` Eli Zaretskii
2020-11-16 18:38       ` Uwe Brauer
2020-11-16 18:43       ` Dmitry Gutov
2020-11-16 19:26         ` Eli Zaretskii
2020-11-16 20:00           ` Dmitry Gutov
2020-11-16 13:54 ` Óscar Fuentes
2020-11-16 16:04   ` Uwe Brauer
2020-11-16 16:36     ` Óscar Fuentes [this message]
2020-11-17  7:21       ` Uwe Brauer

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=877dqlw96l.fsf@telefonica.net \
    --to=ofv@wanadoo.es \
    --cc=emacs-devel@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 public inbox

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

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