Fix #57: [Enhancement] Display uniquified buffer names in help-echo.

This commit is contained in:
Vincent Zhang 2018-12-04 00:22:20 +08:00
parent da9fa3ced2
commit ac1605a92c

View file

@ -573,7 +573,10 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
(and (doom-modeline--active) (and (doom-modeline--active)
'doom-modeline-buffer-file)))) 'doom-modeline-buffer-file))))
(when face `(:inherit ,face)))))) (when face `(:inherit ,face))))))
'help-echo buffer-file-truename))) 'help-echo (concat buffer-file-truename
(unless (string-equal (buffer-name)
(file-name-nondirectory buffer-file-truename))
(concat "\n" (buffer-name)))))))
(defun doom-modeline--buffer-file-name-truncate (file-path true-file-path &optional truncate-tail) (defun doom-modeline--buffer-file-name-truncate (file-path true-file-path &optional truncate-tail)
"Propertized variable `buffer-file-name' that truncates every dir along path. "Propertized variable `buffer-file-name' that truncates every dir along path.
@ -751,30 +754,12 @@ buffer where knowing the current project directory is important."
(advice-add #'undo-tree-undo :after #'doom-modeline-update-buffer-file-state-icon) (advice-add #'undo-tree-undo :after #'doom-modeline-update-buffer-file-state-icon)
(advice-add #'narrow-to-region :after #'doom-modeline-update-buffer-file-state-icon) (advice-add #'narrow-to-region :after #'doom-modeline-update-buffer-file-state-icon)
(defun doom-modeline-fix-buffer-file-name ()
"Fix buffer file name in mode-line.
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 (or (eq doom-modeline-buffer-file-name-style 'buffer-name)
(not (file-exists-p buffer-file-name))
(and (not uniquify-buffer-name-style)
(not (eq uniquify-buffer-name-style 'post-forward-angle-brackets)))
(string-equal
(file-name-nondirectory buffer-file-name)
(replace-regexp-in-string "<.+>$" "" buffer-name)))
file-name
(format "%s[%s]" file-name buffer-name))))
(defvar-local doom-modeline--buffer-file-name nil) (defvar-local doom-modeline--buffer-file-name nil)
(defun doom-modeline-update-buffer-file-name (&rest _) (defun doom-modeline-update-buffer-file-name (&rest _)
"Update buffer file name in mode-line." "Update buffer file name in mode-line."
(setq doom-modeline--buffer-file-name (setq doom-modeline--buffer-file-name
(if buffer-file-name (if buffer-file-name
(doom-modeline-fix-buffer-file-name) (doom-modeline-buffer-file-name)
(propertize "%b" 'face (if (doom-modeline--active) 'doom-modeline-buffer-file))))) (propertize "%b" 'face (if (doom-modeline--active) 'doom-modeline-buffer-file)))))
(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-save-hook 'doom-modeline-update-buffer-file-name) (add-hook 'after-save-hook 'doom-modeline-update-buffer-file-name)