ui/doom-modeline: fontify path separately from filename
This commit is contained in:
parent
e256d0017a
commit
b86634e79f
1 changed files with 39 additions and 26 deletions
|
@ -121,8 +121,8 @@
|
||||||
"Face used for the dirname part of the buffer path."
|
"Face used for the dirname part of the buffer path."
|
||||||
:group '+doom-modeline)
|
:group '+doom-modeline)
|
||||||
|
|
||||||
(defface doom-modeline-buffer-project
|
(defface doom-modeline-buffer-file
|
||||||
'((t (:inherit doom-modeline-buffer-path :bold nil)))
|
'((t (:inherit doom-modeline-buffer-path)))
|
||||||
"Face used for the filename part of the mode-line buffer path."
|
"Face used for the filename part of the mode-line buffer path."
|
||||||
:group '+doom-modeline)
|
:group '+doom-modeline)
|
||||||
|
|
||||||
|
@ -238,13 +238,18 @@ active."
|
||||||
data))))
|
data))))
|
||||||
'xpm t :ascent 'center)))))
|
'xpm t :ascent 'center)))))
|
||||||
|
|
||||||
|
(defun +doom-modeline--buffer-file ()
|
||||||
|
"TODO"
|
||||||
|
"%b")
|
||||||
|
|
||||||
(defun +doom-modeline--buffer-path ()
|
(defun +doom-modeline--buffer-path ()
|
||||||
"Displays the buffer's full path relative to the project root (includes the
|
"Displays the buffer's full path relative to the project root (includes the
|
||||||
project root). Excludes the file basename. See `doom-buffer-name' for that."
|
project root). Excludes the file basename. See `doom-buffer-name' for that."
|
||||||
(if buffer-file-name
|
(when buffer-file-name
|
||||||
(let* ((default-directory (file-name-directory buffer-file-name))
|
(let ((buffer-path
|
||||||
(buffer-path (file-relative-name buffer-file-name (doom-project-root))))
|
(file-relative-name (file-name-directory buffer-file-name)
|
||||||
(when (and buffer-path (not (equal buffer-path ".")))
|
(doom-project-root))))
|
||||||
|
(unless (equal buffer-path "./")
|
||||||
(let ((max-length (truncate (* (window-body-width) 0.4))))
|
(let ((max-length (truncate (* (window-body-width) 0.4))))
|
||||||
(if (> (length buffer-path) max-length)
|
(if (> (length buffer-path) max-length)
|
||||||
(let ((path (nreverse (split-string buffer-path "/" t)))
|
(let ((path (nreverse (split-string buffer-path "/" t)))
|
||||||
|
@ -256,11 +261,10 @@ project root). Excludes the file basename. See `doom-buffer-name' for that."
|
||||||
(setq path (cdr path)))
|
(setq path (cdr path)))
|
||||||
(when path
|
(when path
|
||||||
(setq output (concat "../" output)))
|
(setq output (concat "../" output)))
|
||||||
(when (string-suffix-p "/" output)
|
(unless (string-suffix-p "/" output)
|
||||||
(setq output (substring output 0 -1)))
|
(setq output (concat output "/")))
|
||||||
output)
|
output)
|
||||||
buffer-path))))
|
buffer-path))))))
|
||||||
"%b"))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -270,7 +274,7 @@ project root). Excludes the file basename. See `doom-buffer-name' for that."
|
||||||
(def-modeline-segment! buffer-project
|
(def-modeline-segment! buffer-project
|
||||||
"Displays `doom-project-root'. This is for special buffers like the scratch
|
"Displays `doom-project-root'. This is for special buffers like the scratch
|
||||||
buffer where knowing the current project directory is important."
|
buffer where knowing the current project directory is important."
|
||||||
(let ((face (if (active) 'doom-modeline-buffer-project)))
|
(let ((face (if (active) 'doom-modeline-buffer-path)))
|
||||||
(concat (all-the-icons-octicon
|
(concat (all-the-icons-octicon
|
||||||
"file-directory"
|
"file-directory"
|
||||||
:face face
|
:face face
|
||||||
|
@ -285,8 +289,8 @@ buffer where knowing the current project directory is important."
|
||||||
directory, the file name, and its state (modified, read-only or non-existent)."
|
directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
(let ((all-the-icons-scale-factor 1.2)
|
(let ((all-the-icons-scale-factor 1.2)
|
||||||
(modified-p (buffer-modified-p))
|
(modified-p (buffer-modified-p))
|
||||||
|
(active (active))
|
||||||
faces)
|
faces)
|
||||||
(if (active) (push 'doom-modeline-buffer-path faces))
|
|
||||||
(if modified-p (push 'doom-modeline-buffer-modified faces))
|
(if modified-p (push 'doom-modeline-buffer-modified faces))
|
||||||
(concat (if buffer-read-only
|
(concat (if buffer-read-only
|
||||||
(concat (all-the-icons-octicon
|
(concat (all-the-icons-octicon
|
||||||
|
@ -306,8 +310,17 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
:face 'doom-modeline-urgent
|
:face 'doom-modeline-urgent
|
||||||
:v-adjust -0.05)
|
:v-adjust -0.05)
|
||||||
" "))
|
" "))
|
||||||
(propertize (+doom-modeline--buffer-path)
|
(let ((dir-path (+doom-modeline--buffer-path))
|
||||||
'face (if faces `(:inherit ,faces))))))
|
(faces (or faces (if active 'doom-modeline-buffer-path))))
|
||||||
|
(when dir-path
|
||||||
|
(if faces
|
||||||
|
(propertize dir-path 'face `(:inherit ,faces))
|
||||||
|
dir-path)))
|
||||||
|
(let ((file-path (+doom-modeline--buffer-file))
|
||||||
|
(faces (or faces (if active 'doom-modeline-buffer-file))))
|
||||||
|
(if faces
|
||||||
|
(propertize file-path 'face `(:inherit ,faces))
|
||||||
|
file-path)))))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
(def-modeline-segment! buffer-encoding
|
(def-modeline-segment! buffer-encoding
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue