Show vcs segment in both active and inactive windows.

Similarly, display icon and text separately. No performance issue.
This commit is contained in:
Vincent Zhang 2019-01-03 02:08:35 +08:00
parent 2e33d98576
commit 239b3a97e1

View file

@ -222,6 +222,7 @@ It returns a file name which can be used directly as argument of
(declare-function flycheck-previous-error 'flycheck) (declare-function flycheck-previous-error 'flycheck)
(declare-function flymake--backend-state-diags 'flymake) (declare-function flymake--backend-state-diags 'flymake)
(declare-function flymake--diag-type 'flymake) (declare-function flymake--diag-type 'flymake)
(declare-function flymake--handle-report 'flymake)
(declare-function flymake-disabled-backends 'flymake) (declare-function flymake-disabled-backends 'flymake)
(declare-function flymake-goto-next-error 'flymake) (declare-function flymake-goto-next-error 'flymake)
(declare-function flymake-goto-prev-error 'flymake) (declare-function flymake-goto-prev-error 'flymake)
@ -992,52 +993,65 @@ mouse-1: Display minor modes menu"
;; vcs ;; vcs
;; ;;
(defvar-local doom-modeline--vcs nil) (defvar-local doom-modeline--vcs-icon nil)
(defun doom-modeline--update-vcs (&rest _) (defun doom-modeline--update-vcs-icon (&rest _)
"Update vsc state in mode-line." "Update icon of vsc state in mode-line."
(setq doom-modeline--vcs (setq doom-modeline--vcs-icon
(when (and vc-mode buffer-file-name) (when (and vc-mode buffer-file-name)
(let* ((backend (vc-backend buffer-file-name)) (let* ((backend (vc-backend buffer-file-name))
(state (vc-state buffer-file-name backend))) (state (vc-state buffer-file-name backend)))
(let ((face 'mode-line-inactive) (let ((all-the-icons-default-adjust -0.1))
(active (doom-modeline--active))
(all-the-icons-default-adjust -0.1))
(concat " "
(cond ((memq state '(edited added)) (cond ((memq state '(edited added))
(if active (setq face 'doom-modeline-info)) (doom-modeline-icon-octicon "git-compare"
(doom-modeline-icon-octicon :face 'doom-modeline-info
"git-compare"
:face face
:v-adjust -0.05)) :v-adjust -0.05))
((eq state 'needs-merge) ((eq state 'needs-merge)
(if active (setq face 'doom-modeline-info)) (doom-modeline-icon-octicon "git-merge" :face 'doom-modeline-info))
(doom-modeline-icon-octicon "git-merge" :face face))
((eq state 'needs-update) ((eq state 'needs-update)
(if active (setq face 'doom-modeline-warning)) (doom-modeline-icon-octicon "arrow-down" :face 'doom-modeline-warning))
(doom-modeline-icon-octicon "arrow-down" :face face))
((memq state '(removed conflict unregistered)) ((memq state '(removed conflict unregistered))
(if active (setq face 'doom-modeline-urgent)) (doom-modeline-icon-octicon "alert" :face 'doom-modeline-urgent))
(doom-modeline-icon-octicon "alert" :face face))
(t (t
(if active (setq face 'doom-modeline-info)) (doom-modeline-icon-octicon "git-branch"
(doom-modeline-icon-octicon :face 'doom-modeline-info
"git-branch" :v-adjust -0.05))))))))
:face face (add-hook 'after-revert-hook #'doom-modeline--update-vcs-icon)
:v-adjust -0.05))) (add-hook 'after-save-hook #'doom-modeline--update-vcs-icon)
doom-modeline-vspc (add-hook 'find-file-hook #'doom-modeline--update-vcs-icon t)
(advice-add #'vc-refresh-state :after #'doom-modeline--update-vcs-icon)
(defvar-local doom-modeline--vcs-text nil)
(defun doom-modeline--update-vcs-text (&rest _)
"Update text of vsc state in mode-line."
(setq doom-modeline--vcs-text
(when (and vc-mode buffer-file-name)
(let* ((backend (vc-backend buffer-file-name))
(state (vc-state buffer-file-name backend)))
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
'face (if active face)) 'face (cond ((eq state 'needs-update)
" ")))))) 'doom-modeline-warning)
(add-hook 'after-revert-hook #'doom-modeline--update-vcs) ((memq state '(removed conflict unregistered))
(add-hook 'after-save-hook #'doom-modeline--update-vcs) 'doom-modeline-urgent)
(add-hook 'find-file-hook #'doom-modeline--update-vcs t) (t 'doom-modeline-info)))))))
(advice-add #'vc-refresh-state :after #'doom-modeline--update-vcs) (add-hook 'after-revert-hook #'doom-modeline--update-vcs-text)
(add-hook 'after-save-hook #'doom-modeline--update-vcs-text)
(add-hook 'find-file-hook #'doom-modeline--update-vcs-text t)
(advice-add #'vc-refresh-state :after #'doom-modeline--update-vcs-text)
(doom-modeline-def-segment vcs (doom-modeline-def-segment vcs
"Displays the current branch, colored based on its state." "Displays the current branch, colored based on its state."
(if (doom-modeline--active) (let ((active (doom-modeline--active)))
(or doom-modeline--vcs (doom-modeline--update-vcs)) (when-let ((icon (or doom-modeline--vcs-icon (doom-modeline--update-vcs-icon)))
"")) (text (or doom-modeline--vcs-text (doom-modeline--update-vcs-text))))
(concat " "
(if active
icon
(propertize icon 'face `(:height 1.2 :family ,(all-the-icons-icon-family icon) :inherit)))
doom-modeline-vspc
(if active
text
(propertize text 'face 'mode-line-inactive))
" "))))
;; ;;