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)