Fix #47: new style buffer-name, which respects uniquify names.

This commit is contained in:
Vincent Zhang 2018-11-23 00:12:36 +08:00
parent 364f5acb0b
commit b91e76b383
2 changed files with 19 additions and 13 deletions

View file

@ -73,7 +73,8 @@ Recommand to use [doom-themes](https://github.com/hlissner/emacs-doom-themes);
;; truncate-all => ~/P/F/e/l/comint.el ;; truncate-all => ~/P/F/e/l/comint.el
;; relative-from-project => emacs/lisp/comint.el ;; relative-from-project => emacs/lisp/comint.el
;; relative-to-project => lisp/comint.el ;; relative-to-project => lisp/comint.el
;; file-name => comint.el" ;; file-name => comint.el
;; buffer-name => comint.el<2> (uniquify buffer name)
;; ;;
;; If you are expereicing the laggy issue, especially while editing remote files ;; If you are expereicing the laggy issue, especially while editing remote files
;; with tramp, please try `file-name' style. ;; with tramp, please try `file-name' style.

View file

@ -86,7 +86,8 @@ Given ~/Projects/FOSS/emacs/lisp/comint.el
truncate-all => ~/P/F/e/l/comint.el truncate-all => ~/P/F/e/l/comint.el
relative-from-project => emacs/lisp/comint.el relative-from-project => emacs/lisp/comint.el
relative-to-project => lisp/comint.el relative-to-project => lisp/comint.el
file-name => comint.el") file-name => comint.el
buffer-name => comint.el<2> (uniquify buffer name)")
(defvar doom-modeline-python-executable "python" (defvar doom-modeline-python-executable "python"
"What executable of Python will be used (if nil nothing will be showed).") "What executable of Python will be used (if nil nothing will be showed).")
@ -520,8 +521,11 @@ active.")
(doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename)) (doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename))
(`relative-from-project (`relative-from-project
(doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename 'include-project)) (doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename 'include-project))
(`file-name (style
(propertize (file-name-nondirectory buffer-file-name) (propertize
(pcase style
(`file-name (file-name-nondirectory buffer-file-name))
(`buffer-name (buffer-name)))
'face 'face
(let ((face (or (and (buffer-modified-p) (let ((face (or (and (buffer-modified-p)
'doom-modeline-buffer-modified) 'doom-modeline-buffer-modified)
@ -644,7 +648,7 @@ buffer where knowing the current project directory is important."
'face face)))) 'face face))))
;; ;;
(defun doom-modeline-fixed-buffer-file-name () (defun doom-modeline-fix-buffer-file-name ()
"Fix buffer file name in mode-line. "Fix buffer file name in mode-line.
Show buffer name if it doesn't equal the file name. Show buffer name if it doesn't equal the file name.
@ -653,7 +657,8 @@ buffer where knowing the current project directory is important."
(when-let ((file-name (doom-modeline-buffer-file-name)) (when-let ((file-name (doom-modeline-buffer-file-name))
(buffer-name (buffer-name)) (buffer-name (buffer-name))
(buffer-file-name buffer-file-name)) (buffer-file-name buffer-file-name))
(if (or (not (file-exists-p buffer-file-name)) (if (or (eq doom-modeline-buffer-file-name-style 'buffer-name)
(not (file-exists-p buffer-file-name))
(string-equal (string-equal
(file-name-nondirectory buffer-file-name) (file-name-nondirectory buffer-file-name)
(replace-regexp-in-string "<.+>$" "" buffer-name))) (replace-regexp-in-string "<.+>$" "" buffer-name)))
@ -692,7 +697,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
:v-adjust -0.05) :v-adjust -0.05)
" ")))) " "))))
(if buffer-file-name (if buffer-file-name
(doom-modeline-fixed-buffer-file-name) (doom-modeline-fix-buffer-file-name)
(propertize "%b" 'face (if active 'doom-modeline-buffer-file)))))) (propertize "%b" 'face (if active 'doom-modeline-buffer-file))))))
(doom-modeline-def-segment buffer-info-simple (doom-modeline-def-segment buffer-info-simple