Optimize performance for flymake segment.

This commit is contained in:
Vincent Zhang 2019-01-02 22:35:02 +08:00
parent b56a9f233c
commit 30d882b9aa

View file

@ -1130,7 +1130,7 @@ icons."
;; ;;
(defvar-local doom-modeline--flymake nil) (defvar-local doom-modeline--flymake nil)
(defun doom-modeline-update-flymake-segment () (defun doom-modeline-update-flymake-segment (&rest _)
"Update flymake segment via STATUS." "Update flymake segment via STATUS."
(setq flymake--mode-line-format nil) ; remove the lighter of minor mode (setq flymake--mode-line-format nil) ; remove the lighter of minor mode
(setq doom-modeline--flymake (setq doom-modeline--flymake
@ -1200,24 +1200,28 @@ wheel-up/wheel-down: Previous/Next warning or error"
(with-selected-window (posn-window (event-start event)) (with-selected-window (posn-window (event-start event))
(flymake-goto-next-error 1 '(:error :warning) t)))) (flymake-goto-next-error 1 '(:error :warning) t))))
map)))))) map))))))
;; (add-hook 'flymake-diagnostic-functions #'doom-modeline-update-flymake-segment) (add-hook 'flymake-mode-hook #'doom-modeline-update-flymake-segment)
;; (add-hook 'flymake-mode-hook #'doom-modeline-update-flymake-segment) (advice-add #'flymake--handle-report :after #'doom-modeline-update-flymake-segment)
(doom-modeline-def-segment flymake (doom-modeline-def-segment flymake
"Displays color-coded flymake error status in the current buffer with pretty "Displays color-coded flymake error status in the current buffer with pretty
icons." icons."
(if (doom-modeline--active) (if (doom-modeline--active)
(doom-modeline-update-flymake-segment) doom-modeline--flymake
"")) ""))
;;
;; checker: flymake/flycheck
;;
(doom-modeline-def-segment checker (doom-modeline-def-segment checker
"Displays color-coded error status in the current buffer with pretty "Displays color-coded error status in the current buffer with pretty
icons." icons."
(when (doom-modeline--active) (when (doom-modeline--active)
(cond ((and (bound-and-true-p flymake-mode) (cond ((and (bound-and-true-p flymake-mode)
(bound-and-true-p flymake--backend-state)) ; only support 26+ (bound-and-true-p flymake--backend-state)) ; only support 26+
(doom-modeline-update-flymake-segment)) doom-modeline--flymake)
((bound-and-true-p flycheck-mode) ((bound-and-true-p flycheck-mode)
doom-modeline--flycheck)))) doom-modeline--flycheck))))