Optimize performance of displaying file icons.

This commit is contained in:
Vincent Zhang 2018-11-24 13:18:33 +08:00
parent 0c9888c5b6
commit 229366ffe5

View file

@ -687,6 +687,35 @@ buffer where knowing the current project directory is important."
file-name file-name
(format "%s[%s]" file-name buffer-name)))) (format "%s[%s]" file-name buffer-name))))
(defvar-local doom-modeline--file-icon nil)
(defun doom-modeline-update-file-icon ()
"Update file icon in mode-line."
(when doom-modeline-major-mode-icon
(setq doom-modeline--file-icon
(let ((icon (doom-modeline-icon-for-mode major-mode)))
(unless (symbolp icon)
(concat
(propertize icon
'help-echo (format "Major-mode: `%s'" major-mode)
'display '(raise 0)
'face (cond (buffer-read-only 'doom-modeline-warninng)
((buffer-modified-p) 'doom-modeline-buffer-modified)
((and buffer-file-name
(not (file-exists-p buffer-file-name)))
'doom-modeline-urgent)
((buffer-narrowed-p) 'doom-modeline-warning)))
" "))))))
(add-hook 'find-file-hook 'doom-modeline-update-file-icon)
(add-hook 'after-save-hook 'doom-modeline-update-file-icon)
(add-hook 'after-revert-hook 'doom-modeline-update-file-icon)
(add-hook 'after-change-major-mode-hook 'doom-modeline-update-file-icon)
(add-variable-watcher
'doom-modeline-major-mode-icon
(lambda (_sym _val op _where)
(when (eq op 'set)
(doom-modeline-update-file-icon))))
(doom-modeline-def-segment buffer-info (doom-modeline-def-segment buffer-info
"Combined information about the current buffer, including the current working "Combined information about the current buffer, including the current working
directory, the file name, and its state (modified, read-only or non-existent)." directory, the file name, and its state (modified, read-only or non-existent)."
@ -718,20 +747,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
:v-adjus t -0.05) :v-adjus t -0.05)
" "))) " ")))
(when doom-modeline-major-mode-icon (or doom-modeline--file-icon (doom-modeline-update-file-icon))
(let ((icon (doom-modeline-icon-for-mode major-mode)))
(unless (symbolp icon)
(concat
(propertize icon
'help-echo (format "Major-mode: `%s'" major-mode)
'display '(raise 0)
'face (cond (buffer-read-only 'doom-modeline-warninng)
((buffer-modified-p) 'doom-modeline-buffer-modified)
((and buffer-file-name
(not (file-exists-p buffer-file-name)))
'doom-modeline-urgent)
((buffer-narrowed-p) 'doom-modeline-warning)))
" "))))
(if buffer-file-name (if buffer-file-name
(doom-modeline-fix-buffer-file-name) (doom-modeline-fix-buffer-file-name)