Update vc state on modeline while selecting the window.

This might address this issue:
Modeline VC branch name not updating on magit-checkout.
In doom-modeline, only show vc state in active window, so
it makes sense to update vc state while selecting the
window, and it won't bring performance issue.

Refer to:
https://github.com/hlissner/doom-emacs/issues/826
3d8e81b7e1
This commit is contained in:
Vincent Zhang 2018-09-25 00:05:01 +08:00
parent b020f8b0a7
commit f7a573906d

View file

@ -661,7 +661,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
;;
(defvar-local doom-modeline--vcs nil)
(defun doom-modeline--update-vcs ()
(defun doom-modeline--update-vcs (&rest _)
"Update vsc state in mode-line."
(setq doom-modeline--vcs
(when (and vc-mode buffer-file-name)
@ -699,7 +699,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(add-hook 'after-revert-hook #'doom-modeline--update-vcs)
(add-hook 'after-save-hook #'doom-modeline--update-vcs)
(add-hook 'find-file-hook #'doom-modeline--update-vcs t)
(advice-add #'vc-refresh-state :after #'doom-modeline--update-vcs)
(advice-add #'select-window :after #'doom-modeline--update-vcs)
(doom-modeline-def-segment vcs
"Displays the current branch, colored based on its state."