[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,6 +370,7 @@ 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))))
(unless (string-empty-p icon)
(concat (concat
(if (and active doom-modeline-major-mode-color-icon) (if (and active doom-modeline-major-mode-color-icon)
icon icon
@ -379,11 +381,12 @@ directory, the file name, and its state (modified, read-only or non-existent)."
,(all-the-icons-icon-family icon) ,(all-the-icons-icon-family icon)
:inherit :inherit
,(if active 'mode-line 'mode-line-inactive)))) ,(if active 'mode-line 'mode-line-inactive))))
(if active doom-modeline-vspc doom-modeline-inactive-vspc)))) (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))))
(unless (string-empty-p icon)
(concat (concat
(if active (if active
icon icon
@ -396,7 +399,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
,(all-the-icons-icon-family icon) ,(all-the-icons-icon-family icon)
:inherit mode-line-inactive) :inherit mode-line-inactive)
'mode-line-inactive))) 'mode-line-inactive)))
(if active doom-modeline-vspc doom-modeline-inactive-vspc))) (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