From 19b79ffc6a74eaa24292f43fa8f54628bda98db8 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 2 Sep 2019 17:09:41 +0800 Subject: [PATCH] [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. --- doom-modeline-segments.el | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doom-modeline-segments.el b/doom-modeline-segments.el index 86426dc..1125bb3 100644 --- a/doom-modeline-segments.el +++ b/doom-modeline-segments.el @@ -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-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 #'symbol-overlay-rename :after #'doom-modeline-update-buffer-file-state-icon) (when (>= emacs-major-version 26) (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 'after-revert-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 'evil-insert-state-exit-hook #'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-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 #'symbol-overlay-rename :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 #'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 (if (boundp 'after-focus-change-function) @@ -375,6 +375,15 @@ mouse-1: Previous buffer\nmouse-3: Next buffer" (if 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 () "The icon of the current major mode." (when (and doom-modeline-icon doom-modeline-major-mode-icon)