Update vcs state in mode-line after refreshing in magit.

This commit is contained in:
Vincent Zhang 2018-06-28 17:06:11 +08:00
parent bd097590a2
commit 10ec55adcc

View file

@ -613,8 +613,10 @@ directory, the file name, and its state (modified, read-only or non-existent)."
;; vcs
;;
(doom-modeline-def-segment vcs
"Displays the current branch, colored based on its state."
(defvar-local doom-modeline--vcs nil)
(defun doom-modeline--update-vcs ()
"Update vsc state in mode-line."
(setq doom-modeline--vcs
(when (and vc-mode buffer-file-name)
(let* ((backend (vc-backend buffer-file-name))
(state (vc-state buffer-file-name backend)))
@ -646,7 +648,26 @@ directory, the file name, and its state (modified, read-only or non-existent)."
" "
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
'face (if active face))
" ")))))
" "))))))
(add-hook 'after-save-hook #'doom-modeline--update-vcs)
(add-hook 'find-file-hook #'doom-modeline--update-vcs t)
(declare-function magit-toplevel "magit-git")
(defun doom-modeline-magit-post-refresh ()
"Update vcs state in mode-line after refreshing in magit."
(dolist (buf (buffer-list))
(when (and (not (buffer-modified-p buf))
(buffer-file-name buf)
(file-exists-p (buffer-file-name buf))
(file-in-directory-p (buffer-file-name buf) (magit-toplevel)))
(with-current-buffer buf
(vc-refresh-state)
(doom-modeline--update-vcs)))))
(add-hook 'magit-post-refresh-hook #'doom-modeline-magit-post-refresh)
(doom-modeline-def-segment vcs
"Displays the current branch, colored based on its state."
doom-modeline--vcs)
;;