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)) (cond ((memq state '(edited added))
(all-the-icons-default-adjust -0.1)) (doom-modeline-icon-octicon "git-compare"
(concat " " :face 'doom-modeline-info
(cond ((memq state '(edited added)) :v-adjust -0.05))
(if active (setq face 'doom-modeline-info)) ((eq state 'needs-merge)
(doom-modeline-icon-octicon (doom-modeline-icon-octicon "git-merge" :face 'doom-modeline-info))
"git-compare" ((eq state 'needs-update)
:face face (doom-modeline-icon-octicon "arrow-down" :face 'doom-modeline-warning))
:v-adjust -0.05)) ((memq state '(removed conflict unregistered))
((eq state 'needs-merge) (doom-modeline-icon-octicon "alert" :face 'doom-modeline-urgent))
(if active (setq face 'doom-modeline-info)) (t
(doom-modeline-icon-octicon "git-merge" :face face)) (doom-modeline-icon-octicon "git-branch"
((eq state 'needs-update) :face 'doom-modeline-info
(if active (setq face 'doom-modeline-warning)) :v-adjust -0.05))))))))
(doom-modeline-icon-octicon "arrow-down" :face face)) (add-hook 'after-revert-hook #'doom-modeline--update-vcs-icon)
((memq state '(removed conflict unregistered)) (add-hook 'after-save-hook #'doom-modeline--update-vcs-icon)
(if active (setq face 'doom-modeline-urgent)) (add-hook 'find-file-hook #'doom-modeline--update-vcs-icon t)
(doom-modeline-icon-octicon "alert" :face face)) (advice-add #'vc-refresh-state :after #'doom-modeline--update-vcs-icon)
(t
(if active (setq face 'doom-modeline-info)) (defvar-local doom-modeline--vcs-text nil)
(doom-modeline-icon-octicon (defun doom-modeline--update-vcs-text (&rest _)
"git-branch" "Update text of vsc state in mode-line."
:face face (setq doom-modeline--vcs-text
:v-adjust -0.05))) (when (and vc-mode buffer-file-name)
doom-modeline-vspc (let* ((backend (vc-backend buffer-file-name))
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) (state (vc-state buffer-file-name backend)))
'face (if active face)) (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
" ")))))) 'face (cond ((eq state 'needs-update)
(add-hook 'after-revert-hook #'doom-modeline--update-vcs) 'doom-modeline-warning)
(add-hook 'after-save-hook #'doom-modeline--update-vcs) ((memq state '(removed conflict unregistered))
(add-hook 'find-file-hook #'doom-modeline--update-vcs t) 'doom-modeline-urgent)
(advice-add #'vc-refresh-state :after #'doom-modeline--update-vcs) (t 'doom-modeline-info)))))))
(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))
" "))))
;; ;;