mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-23 19:19:50 +00:00
Optimize the performance of getting the file names.
This commit is contained in:
parent
fafdafc122
commit
97d6b69222
1 changed files with 32 additions and 27 deletions
|
@ -494,32 +494,37 @@ active.")
|
||||||
(if (eq idx len) "\"};" "\",\n")))))
|
(if (eq idx len) "\"};" "\",\n")))))
|
||||||
'xpm t :ascent 'center)))))
|
'xpm t :ascent 'center)))))
|
||||||
|
|
||||||
(defun doom-modeline-buffer-file-name ()
|
(defvar-local doom-modeline-buffer-file-name nil)
|
||||||
|
(defun doom-modeline-update-buffer-file-name ()
|
||||||
"Propertized variable `buffer-file-name' based on `doom-modeline-buffer-file-name-style'."
|
"Propertized variable `buffer-file-name' based on `doom-modeline-buffer-file-name-style'."
|
||||||
(let ((buffer-file-name (or (buffer-file-name (buffer-base-buffer)) "")))
|
(setq doom-modeline-buffer-file-name
|
||||||
(unless buffer-file-truename
|
(let ((buffer-file-name (or (buffer-file-name (buffer-base-buffer)) "")))
|
||||||
(setq buffer-file-truename (file-truename buffer-file-name)))
|
(unless buffer-file-truename
|
||||||
(propertize
|
(setq buffer-file-truename (file-truename buffer-file-name)))
|
||||||
(pcase doom-modeline-buffer-file-name-style
|
(propertize
|
||||||
(`truncate-upto-project
|
(pcase doom-modeline-buffer-file-name-style
|
||||||
(doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink))
|
(`truncate-upto-project
|
||||||
(`truncate-upto-root
|
(doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink))
|
||||||
(doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename))
|
(`truncate-upto-root
|
||||||
(`truncate-all
|
(doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename))
|
||||||
(doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename t))
|
(`truncate-all
|
||||||
(`relative-to-project
|
(doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename t))
|
||||||
(doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename))
|
(`relative-to-project
|
||||||
(`relative-from-project
|
(doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename))
|
||||||
(doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename 'include-project))
|
(`relative-from-project
|
||||||
(`file-name
|
(doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename 'include-project))
|
||||||
(propertize (file-name-nondirectory buffer-file-name)
|
(`file-name
|
||||||
'face
|
(propertize (file-name-nondirectory buffer-file-name)
|
||||||
(let ((face (or (and (buffer-modified-p)
|
'face
|
||||||
'doom-modeline-buffer-modified)
|
(let ((face (or (and (buffer-modified-p)
|
||||||
(and (doom-modeline--active)
|
'doom-modeline-buffer-modified)
|
||||||
'doom-modeline-buffer-file))))
|
(and (doom-modeline--active)
|
||||||
(when face `(:inherit ,face))))))
|
'doom-modeline-buffer-file))))
|
||||||
'help-echo buffer-file-truename)))
|
(when face `(:inherit ,face))))))
|
||||||
|
'help-echo buffer-file-truename)))
|
||||||
|
(message "#####%s####" doom-modeline-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)
|
||||||
|
|
||||||
(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.
|
||||||
|
@ -637,8 +642,8 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
:face 'doom-modeline-warning
|
:face 'doom-modeline-warning
|
||||||
:v-adjust -0.05)
|
:v-adjust -0.05)
|
||||||
" ")))
|
" ")))
|
||||||
(if buffer-file-name
|
(if doom-modeline-buffer-file-name
|
||||||
(doom-modeline-buffer-file-name)
|
doom-modeline-buffer-file-name
|
||||||
"%b")))
|
"%b")))
|
||||||
|
|
||||||
(doom-modeline-def-segment buffer-info-simple
|
(doom-modeline-def-segment buffer-info-simple
|
||||||
|
|
Loading…
Reference in a new issue