mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-23 11:09:54 +00:00
[Optimize] just update the face of the buffer name in `after-change-functions'.
`doom-modeline--buffer-file-name' may consume lots fof CPU if it's called too frequently. Refer to https://github.com/seagle0128/doom-modeline/issues/32#issuecomment-525838909.
This commit is contained in:
parent
2a6e2e1dc0
commit
19b79ffc6a
1 changed files with 11 additions and 2 deletions
|
@ -305,6 +305,7 @@ Uses `all-the-icons-material' to fetch the icon."
|
||||||
(advice-add #'org-narrow-to-element :after #'doom-modeline-update-buffer-file-state-icon)
|
(advice-add #'org-narrow-to-element :after #'doom-modeline-update-buffer-file-state-icon)
|
||||||
(advice-add #'org-narrow-to-subtree :after #'doom-modeline-update-buffer-file-state-icon)
|
(advice-add #'org-narrow-to-subtree :after #'doom-modeline-update-buffer-file-state-icon)
|
||||||
(advice-add #'org-edit-src-save :after #'doom-modeline-update-buffer-file-state-icon)
|
(advice-add #'org-edit-src-save :after #'doom-modeline-update-buffer-file-state-icon)
|
||||||
|
(advice-add #'symbol-overlay-rename :after #'doom-modeline-update-buffer-file-state-icon)
|
||||||
|
|
||||||
(when (>= emacs-major-version 26)
|
(when (>= emacs-major-version 26)
|
||||||
(add-variable-watcher
|
(add-variable-watcher
|
||||||
|
@ -340,7 +341,6 @@ mouse-1: Previous buffer\nmouse-3: Next buffer"
|
||||||
(add-hook 'find-file-hook #'doom-modeline-update-buffer-file-name)
|
(add-hook 'find-file-hook #'doom-modeline-update-buffer-file-name)
|
||||||
(add-hook 'after-revert-hook #'doom-modeline-update-buffer-file-name)
|
(add-hook 'after-revert-hook #'doom-modeline-update-buffer-file-name)
|
||||||
(add-hook 'after-save-hook #'doom-modeline-update-buffer-file-name)
|
(add-hook 'after-save-hook #'doom-modeline-update-buffer-file-name)
|
||||||
(add-hook 'after-change-functions #'doom-modeline-update-buffer-file-name)
|
|
||||||
(add-hook 'clone-indirect-buffer-hook #'doom-modeline-update-buffer-file-name)
|
(add-hook 'clone-indirect-buffer-hook #'doom-modeline-update-buffer-file-name)
|
||||||
(add-hook 'evil-insert-state-exit-hook #'doom-modeline-update-buffer-file-name)
|
(add-hook 'evil-insert-state-exit-hook #'doom-modeline-update-buffer-file-name)
|
||||||
(advice-add #'not-modified :after #'doom-modeline-update-buffer-file-name)
|
(advice-add #'not-modified :after #'doom-modeline-update-buffer-file-name)
|
||||||
|
@ -350,10 +350,10 @@ mouse-1: Previous buffer\nmouse-3: Next buffer"
|
||||||
(advice-add #'undo :after #'doom-modeline-update-buffer-file-name)
|
(advice-add #'undo :after #'doom-modeline-update-buffer-file-name)
|
||||||
(advice-add #'undo-tree-undo-1 :after #'doom-modeline-update-buffer-file-name)
|
(advice-add #'undo-tree-undo-1 :after #'doom-modeline-update-buffer-file-name)
|
||||||
(advice-add #'undo-tree-redo-1 :after #'doom-modeline-update-buffer-file-name)
|
(advice-add #'undo-tree-redo-1 :after #'doom-modeline-update-buffer-file-name)
|
||||||
(advice-add #'symbol-overlay-rename :after #'doom-modeline-update-buffer-file-name)
|
|
||||||
(advice-add #'popup-create :after #'doom-modeline-update-buffer-file-name)
|
(advice-add #'popup-create :after #'doom-modeline-update-buffer-file-name)
|
||||||
(advice-add #'popup-delete :after #'doom-modeline-update-buffer-file-name)
|
(advice-add #'popup-delete :after #'doom-modeline-update-buffer-file-name)
|
||||||
(advice-add #'org-edit-src-save :after #'doom-modeline-update-buffer-file-name)
|
(advice-add #'org-edit-src-save :after #'doom-modeline-update-buffer-file-name)
|
||||||
|
(advice-add #'symbol-overlay-rename :after #'doom-modeline-update-buffer-file-name)
|
||||||
|
|
||||||
(with-no-warnings
|
(with-no-warnings
|
||||||
(if (boundp 'after-focus-change-function)
|
(if (boundp 'after-focus-change-function)
|
||||||
|
@ -375,6 +375,15 @@ mouse-1: Previous buffer\nmouse-3: Next buffer"
|
||||||
(if buffer-file-name
|
(if buffer-file-name
|
||||||
(doom-modeline-update-buffer-file-name))))))))
|
(doom-modeline-update-buffer-file-name))))))))
|
||||||
|
|
||||||
|
;; Optimize: just update the face of the buffer name in `after-change-functions', since
|
||||||
|
;; `doom-modeline--buffer-file-name' may consume lots fof CPU if it's called too frequently.
|
||||||
|
(defun doom-modeline-update-buffer-file-name-face (&rest _)
|
||||||
|
"Update the face of buffer file name in mode-line."
|
||||||
|
(when (and doom-modeline--buffer-file-name (buffer-modified-p))
|
||||||
|
(setq doom-modeline--buffer-file-name
|
||||||
|
(propertize doom-modeline--buffer-file-name 'face 'doom-modeline-buffer-modified))))
|
||||||
|
(add-hook 'after-change-functions #'doom-modeline-update-buffer-file-name-face)
|
||||||
|
|
||||||
(defsubst doom-modeline--buffer-mode-icon ()
|
(defsubst doom-modeline--buffer-mode-icon ()
|
||||||
"The icon of the current major mode."
|
"The icon of the current major mode."
|
||||||
(when (and doom-modeline-icon doom-modeline-major-mode-icon)
|
(when (and doom-modeline-icon doom-modeline-major-mode-icon)
|
||||||
|
|
Loading…
Reference in a new issue