ui/doom-modeline: optimize vcs segment (experimental)

This commit is contained in:
Henrik Lissner 2018-05-29 14:03:31 +02:00
parent fbce2388ab
commit 9ae99deb65
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -376,8 +376,9 @@ directory, the file name, and its state (modified, read-only or non-existent)."
;; vcs
;;
(def-modeline-segment! vcs
"Displays the current branch, colored based on its state."
(defvar +doom-modeline--vcs nil)
(defun +doom-modeline--update-vcs ()
(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)))
@ -409,7 +410,12 @@ 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)
(def-modeline-var! vcs +doom-modeline--vcs
"Displays the current branch, colored based on its state.")
;;