[Performance] Improve performance of buffer-info segment.

Do not update every time for icons.
This commit is contained in:
Vincent Zhang 2019-03-22 02:46:13 +08:00
parent 67cc091716
commit 77ac0984eb

View file

@ -270,12 +270,13 @@ Uses `all-the-icons-material' to fetch the icon."
(doom-modeline-buffer-file-state-icon (doom-modeline-buffer-file-state-icon
"vertical_align_center" "vertical_align_center"
"><" "><"
'doom-modeline-warning))))) 'doom-modeline-warning))
(t ""))))
(add-hook 'find-file-hook #'doom-modeline-update-buffer-file-state-icon) (add-hook 'find-file-hook #'doom-modeline-update-buffer-file-state-icon)
(add-hook 'after-revert-hook #'doom-modeline-update-buffer-file-state-icon) (add-hook 'after-revert-hook #'doom-modeline-update-buffer-file-state-icon)
(add-hook 'after-save-hook #'doom-modeline-update-buffer-file-state-icon) (add-hook 'after-save-hook #'doom-modeline-update-buffer-file-state-icon)
(add-hook 'read-only-mode-hook #'doom-modeline-update-buffer-file-state-icon) (add-hook 'read-only-mode-hook #'doom-modeline-update-buffer-file-state-icon)
;; (add-hook 'after-change-functions #'doom-modeline-update-buffer-file-state-icon) (add-hook 'after-change-functions #'doom-modeline-update-buffer-file-state-icon)
(add-hook 'clone-indirect-buffer-hook #'doom-modeline-update-buffer-file-state-icon) (add-hook 'clone-indirect-buffer-hook #'doom-modeline-update-buffer-file-state-icon)
(add-hook 'evil-insert-state-exit-hook #'doom-modeline-update-buffer-file-state-icon) (add-hook 'evil-insert-state-exit-hook #'doom-modeline-update-buffer-file-state-icon)
(advice-add #'undo :after #'doom-modeline-update-buffer-file-state-icon) (advice-add #'undo :after #'doom-modeline-update-buffer-file-state-icon)
@ -369,34 +370,36 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(when (and doom-modeline-icon doom-modeline-major-mode-icon) (when (and doom-modeline-icon doom-modeline-major-mode-icon)
(when-let ((icon (or doom-modeline--buffer-file-icon (when-let ((icon (or doom-modeline--buffer-file-icon
(doom-modeline-update-buffer-file-icon)))) (doom-modeline-update-buffer-file-icon))))
(concat (unless (string-empty-p icon)
(if (and active doom-modeline-major-mode-color-icon) (concat
icon (if (and active doom-modeline-major-mode-color-icon)
(propertize icon icon
'face `(:height (propertize icon
,(doom-modeline-icon-height 1.1) 'face `(:height
:family ,(doom-modeline-icon-height 1.1)
,(all-the-icons-icon-family icon) :family
:inherit ,(all-the-icons-icon-family icon)
,(if active 'mode-line 'mode-line-inactive)))) :inherit
(if active doom-modeline-vspc doom-modeline-inactive-vspc)))) ,(if active 'mode-line 'mode-line-inactive))))
(if active doom-modeline-vspc doom-modeline-inactive-vspc)))))
;; state icon ;; state icon
(when-let ((icon (or doom-modeline--buffer-file-state-icon (when-let ((icon (or doom-modeline--buffer-file-state-icon
(doom-modeline-update-buffer-file-state-icon)))) (doom-modeline-update-buffer-file-state-icon))))
(concat (unless (string-empty-p icon)
(if active (concat
icon (if active
(propertize icon icon
'face (propertize icon
(if doom-modeline-icon 'face
`(:height (if doom-modeline-icon
,(doom-modeline-icon-height 1.3) `(:height
:family ,(doom-modeline-icon-height 1.3)
,(all-the-icons-icon-family icon) :family
:inherit mode-line-inactive) ,(all-the-icons-icon-family icon)
'mode-line-inactive))) :inherit mode-line-inactive)
(if active doom-modeline-vspc doom-modeline-inactive-vspc))) 'mode-line-inactive)))
(if active doom-modeline-vspc doom-modeline-inactive-vspc))))
;; buffer file name ;; buffer file name
(when-let ((name (or doom-modeline--buffer-file-name (when-let ((name (or doom-modeline--buffer-file-name