mirror of
https://github.com/correl/doom-modeline.git
synced 2024-12-27 11:09:49 +00:00
Add truncate-with-project style and set it to default.
This commit is contained in:
parent
7f28abb514
commit
87ee2e7122
1 changed files with 54 additions and 29 deletions
|
@ -74,11 +74,12 @@
|
|||
(defvar doom-modeline-bar-width 3
|
||||
"How wide the mode-line bar should be (only respected in GUI Emacs).")
|
||||
|
||||
(defvar doom-modeline-buffer-file-name-style 'truncate-upto-project
|
||||
(defvar doom-modeline-buffer-file-name-style 'truncate-with-project
|
||||
"Determines the style used by `doom-modeline-buffer-file-name'.
|
||||
|
||||
Given ~/Projects/FOSS/emacs/lisp/comint.el
|
||||
truncate-upto-project => ~/P/F/emacs/lisp/comint.el
|
||||
truncate-with-project => emacs/l/comint.el
|
||||
truncate-upto-root => ~/P/F/e/lisp/comint.el
|
||||
truncate-all => ~/P/F/e/l/comint.el
|
||||
relative-from-project => emacs/lisp/comint.el
|
||||
|
@ -503,6 +504,8 @@ active.")
|
|||
(pcase doom-modeline-buffer-file-name-style
|
||||
(`truncate-upto-project
|
||||
(doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink))
|
||||
(`truncate-with-project
|
||||
( doom-modeline--buffer-file-name-truncate-with-project buffer-file-name buffer-file-truename))
|
||||
(`truncate-upto-root
|
||||
(doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename))
|
||||
(`truncate-all
|
||||
|
@ -540,6 +543,29 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file."
|
|||
(propertize (file-name-nondirectory file-path)
|
||||
'face (if file-faces `(:inherit ,file-faces)))))))))
|
||||
|
||||
(defun doom-modeline--buffer-file-name-truncate-with-project (file-path _true-file-path)
|
||||
"Propertized variable `buffer-file-name' based on FILE-PATH.
|
||||
|
||||
Show relative path to the project and truncate it.
|
||||
Example:
|
||||
~/Projects/FOSS/emacs/lisp/comint.el => emacs/l/comint.el"
|
||||
(let* ((project-root (doom-modeline-project-root))
|
||||
(relative-path (file-relative-name (file-name-directory file-path)
|
||||
(file-truename project-root))))
|
||||
(let ((active (doom-modeline--active))
|
||||
(modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)))
|
||||
(let ((project-faces (or modified-faces (if active 'font-lock-string-face)))
|
||||
(relative-faces (or modified-faces (if active 'doom-modeline-buffer-path)))
|
||||
(file-faces (or modified-faces (if active 'doom-modeline-buffer-file))))
|
||||
(let ((project-props `(,@(if project-faces `(:inherit ,project-faces)) ,@(if active '(:weight bold))))
|
||||
(relative-props `(,@(if relative-faces `(:inherit ,relative-faces))))
|
||||
(file-props `(,@(if file-faces `(:inherit ,file-faces)))))
|
||||
(concat (propertize
|
||||
(concat (file-name-nondirectory (directory-file-name (doom-modeline-project-root))) "/")
|
||||
'face project-props)
|
||||
(unless (string-equal relative-path "./")
|
||||
(propertize (shrink-path--dirs-internal relative-path t) 'face relative-props))
|
||||
(propertize (file-name-nondirectory file-path) 'face file-props)))))))
|
||||
|
||||
(defun doom-modeline--buffer-file-name-relative (_file-path true-file-path &optional include-project)
|
||||
"Propertized variable `buffer-file-name' showing directories relative to project's root only."
|
||||
|
@ -630,36 +656,35 @@ buffer where knowing the current project directory is important."
|
|||
directory, the file name, and its state (modified, read-only or non-existent)."
|
||||
(let ((active (doom-modeline--active)))
|
||||
(concat
|
||||
(when active
|
||||
(cond (buffer-read-only
|
||||
(concat (doom-modeline-icon-octicon
|
||||
"lock"
|
||||
:face 'doom-modeline-warning
|
||||
:v-adjust -0.05)
|
||||
" "))
|
||||
((buffer-modified-p)
|
||||
(concat (doom-modeline-icon-faicon
|
||||
"floppy-o"
|
||||
:face 'doom-modeline-buffer-modified
|
||||
:v-adjust -0.0575)
|
||||
" "))
|
||||
((and buffer-file-name
|
||||
(not (file-exists-p buffer-file-name)))
|
||||
(concat (doom-modeline-icon-octicon
|
||||
"circle-slash"
|
||||
:face 'doom-modeline-urgent
|
||||
:v-adjust -0.05)
|
||||
" "))
|
||||
((buffer-narrowed-p)
|
||||
(concat (doom-modeline-icon-octicon
|
||||
"fold"
|
||||
:face 'doom-modeline-warning
|
||||
:v-adjust -0.05)
|
||||
" "))))
|
||||
(if active
|
||||
(cond (buffer-read-only
|
||||
(concat (doom-modeline-icon-octicon
|
||||
"lock"
|
||||
:face 'doom-modeline-warning
|
||||
:v-adjust -0.05)
|
||||
" "))
|
||||
((buffer-modified-p)
|
||||
(concat (doom-modeline-icon-faicon
|
||||
"floppy-o"
|
||||
:face 'doom-modeline-buffer-modified
|
||||
:v-adjust -0.0575)
|
||||
" "))
|
||||
((and buffer-file-name
|
||||
(not (file-exists-p buffer-file-name)))
|
||||
(concat (doom-modeline-icon-octicon
|
||||
"circle-slash"
|
||||
:face 'doom-modeline-urgent
|
||||
:v-adjust -0.05)
|
||||
" "))
|
||||
((buffer-narrowed-p)
|
||||
(concat (doom-modeline-icon-octicon
|
||||
"fold"
|
||||
:face 'doom-modeline-warning
|
||||
:v-adjust -0.05)
|
||||
" "))))
|
||||
(if buffer-file-name
|
||||
(doom-modeline-update-buffer-file-name)
|
||||
(propertize "%b" 'face (when (doom-modeline--active)
|
||||
'doom-modeline-buffer-file))))))
|
||||
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))))))
|
||||
|
||||
(doom-modeline-def-segment buffer-info-simple
|
||||
"Display only the current buffer's name, but with fontification."
|
||||
|
|
Loading…
Reference in a new issue