From 9701be775c9acb88a441e48b7371fc0580d70906 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 16 Nov 2018 00:52:51 +0800 Subject: [PATCH] Revert performance optimization for buffer info. Because the buffer info will be updated in many scenarios and no need to handle all cases in hooks or advices. But Keep showing buffer name if it doesn't equal the file name. --- doom-modeline.el | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/doom-modeline.el b/doom-modeline.el index 369920e..6a52325 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -609,33 +609,20 @@ buffer where knowing the current project directory is important." 'face face)))) ;; -(defvar-local doom-modeline-buffer-file-name - (propertize "%b" 'face 'doom-modeline-buffer-file)) -(defun doom-modeline-update-buffer-file-name (&rest _) - "Propertized variable `buffer-file-name' based on `doom-modeline-buffer-file-name-style'." - (setq doom-modeline-buffer-file-name - ;; Show buffer name if it doesn't equal the file name. - ;; NOTE: Format: "buffer-file-name[buffer-name]". - ;; Except the same buffer names in different directories. - (when-let ((file-name (doom-modeline-buffer-file-name)) - (buffer-name (buffer-name)) - (buffer-file-name buffer-file-name)) - (if (string-equal - (file-name-nondirectory buffer-file-name) - (replace-regexp-in-string "<.+>$" "" buffer-name)) - file-name - (format "%s[%s]" file-name buffer-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-save-hook #'doom-modeline-update-buffer-file-name) -(advice-add #'rename-buffer :after #'doom-modeline-update-buffer-file-name) +(defun doom-modeline-update-buffer-file-name () + "Update buffer file name in mode-line. -(when (>= emacs-major-version 26) - (add-variable-watcher - 'doom-modeline-buffer-file-name-style - (lambda (_sym _val op _where) - (when (eq op 'set) - (doom-modeline-update-buffer-file-name))))) + Show buffer name if it doesn't equal the file name. + Format: \"buffer-file-name[buffer-name]\". + Except the same buffer names in different directories." + (when-let ((file-name (doom-modeline-buffer-file-name)) + (buffer-name (buffer-name)) + (buffer-file-name buffer-file-name)) + (if (string-equal + (file-name-nondirectory buffer-file-name) + (replace-regexp-in-string "<.+>$" "" buffer-name)) + file-name + (format "%s[%s]" file-name buffer-name)))) (doom-modeline-def-segment buffer-info "Combined information about the current buffer, including the current working @@ -668,9 +655,9 @@ directory, the file name, and its state (modified, read-only or non-existent)." :face 'doom-modeline-warning :v-adjust -0.05) " ")))) - (if (and active buffer-file-name) - doom-modeline-buffer-file-name - (propertize "%b" 'face (if active 'doom-modeline-buffer-file)))))) + (if buffer-file-name + (doom-modeline-update-buffer-file-name) + "%b")))) (doom-modeline-def-segment buffer-info-simple "Display only the current buffer's name, but with fontification."