mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-27 19:19:53 +00:00
This commit is contained in:
parent
a22a895b7b
commit
b020f8b0a7
1 changed files with 36 additions and 30 deletions
|
@ -460,17 +460,24 @@ active.")
|
||||||
'xpm t :ascent 'center)))))
|
'xpm t :ascent 'center)))))
|
||||||
|
|
||||||
(defun doom-modeline-buffer-file-name ()
|
(defun doom-modeline-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 ""))
|
(let ((buffer-file-name (or (buffer-file-name (buffer-base-buffer)) "")))
|
||||||
(buffer-file-truename (or buffer-file-truename "")))
|
(unless buffer-file-truename
|
||||||
|
(setq buffer-file-truename (file-truename buffer-file-name)))
|
||||||
(propertize
|
(propertize
|
||||||
(pcase doom-modeline-buffer-file-name-style
|
(pcase doom-modeline-buffer-file-name-style
|
||||||
(`truncate-upto-project (doom-modeline--buffer-file-name 'shrink))
|
(`truncate-upto-project
|
||||||
(`truncate-upto-root (doom-modeline--buffer-file-name-truncate))
|
(doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink))
|
||||||
(`truncate-all (doom-modeline--buffer-file-name-truncate t))
|
(`truncate-upto-root
|
||||||
(`relative-to-project (doom-modeline--buffer-file-name-relative))
|
(doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename))
|
||||||
(`relative-from-project (doom-modeline--buffer-file-name-relative 'include-project))
|
(`truncate-all
|
||||||
(`file-name (propertize (file-name-nondirectory buffer-file-name)
|
(doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename t))
|
||||||
|
(`relative-to-project
|
||||||
|
(doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename))
|
||||||
|
(`relative-from-project
|
||||||
|
(doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename 'include-project))
|
||||||
|
(`file-name
|
||||||
|
(propertize (file-name-nondirectory buffer-file-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)
|
||||||
|
@ -479,11 +486,10 @@ active.")
|
||||||
(when face `(:inherit ,face))))))
|
(when face `(:inherit ,face))))))
|
||||||
'help-echo buffer-file-truename)))
|
'help-echo buffer-file-truename)))
|
||||||
|
|
||||||
(defun doom-modeline--buffer-file-name-truncate (&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 `buffer-file-name' that truncates every dir along path.
|
||||||
|
|
||||||
If TRUNCATE-TAIL is t also truncate the parent directory of the file."
|
If TRUNCATE-TAIL is t also truncate the parent directory of the file."
|
||||||
(let ((dirs (shrink-path-prompt (file-name-directory buffer-file-truename)))
|
(let ((dirs (shrink-path-prompt (file-name-directory true-file-path)))
|
||||||
(active (doom-modeline--active)))
|
(active (doom-modeline--active)))
|
||||||
(if (null dirs)
|
(if (null dirs)
|
||||||
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))
|
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))
|
||||||
|
@ -496,27 +502,27 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file."
|
||||||
(if truncate-tail (substring basename 0 1) basename)
|
(if truncate-tail (substring basename 0 1) basename)
|
||||||
"/")
|
"/")
|
||||||
'face (if dir-faces `(:inherit ,dir-faces)))
|
'face (if dir-faces `(:inherit ,dir-faces)))
|
||||||
(propertize (file-name-nondirectory buffer-file-name)
|
(propertize (file-name-nondirectory file-path)
|
||||||
'face (if file-faces `(:inherit ,file-faces)))))))))
|
'face (if file-faces `(:inherit ,file-faces)))))))))
|
||||||
|
|
||||||
(defun doom-modeline--buffer-file-name-relative (&optional include-project)
|
|
||||||
"Propertized variable `buffer-file-name' showing directories relative to INCLUDE-PROJECT root only."
|
(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."
|
||||||
(let ((root (doom-modeline-project-root))
|
(let ((root (doom-modeline-project-root))
|
||||||
(active (doom-modeline--active)))
|
(active (doom-modeline--active)))
|
||||||
(if (null root)
|
(if (null root)
|
||||||
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))
|
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))
|
||||||
(let* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))
|
(let* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))
|
||||||
(true-filename (file-truename buffer-file-name))
|
(relative-dirs (file-relative-name (file-name-directory true-file-path)
|
||||||
(relative-dirs (file-relative-name (file-name-directory true-filename)
|
|
||||||
(if include-project (concat root "../") root)))
|
(if include-project (concat root "../") root)))
|
||||||
(relative-faces (or modified-faces (if active 'doom-modeline-buffer-path)))
|
(relative-faces (or modified-faces (if active 'doom-modeline-buffer-path)))
|
||||||
(file-faces (or modified-faces (if active 'doom-modeline-buffer-file))))
|
(file-faces (or modified-faces (if active 'doom-modeline-buffer-file))))
|
||||||
(if (equal "./" relative-dirs) (setq relative-dirs ""))
|
(if (equal "./" relative-dirs) (setq relative-dirs ""))
|
||||||
(concat (propertize relative-dirs 'face (if relative-faces `(:inherit ,relative-faces)))
|
(concat (propertize relative-dirs 'face (if relative-faces `(:inherit ,relative-faces)))
|
||||||
(propertize (file-name-nondirectory true-filename)
|
(propertize (file-name-nondirectory true-file-path)
|
||||||
'face (if file-faces `(:inherit ,file-faces))))))))
|
'face (if file-faces `(:inherit ,file-faces))))))))
|
||||||
|
|
||||||
(defun doom-modeline--buffer-file-name (truncate-project-root-parent)
|
(defun doom-modeline--buffer-file-name (file-path _true-file-path &optional truncate-project-root-parent)
|
||||||
"Propertized variable `buffer-file-name'.
|
"Propertized variable `buffer-file-name'.
|
||||||
|
|
||||||
If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down
|
If TRUNCATE-PROJECT-ROOT-PARENT is t space will be saved by truncating it down
|
||||||
|
@ -526,12 +532,12 @@ Example:
|
||||||
~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el"
|
~/Projects/FOSS/emacs/lisp/comint.el => ~/P/F/emacs/lisp/comint.el"
|
||||||
(let* ((project-root (doom-modeline-project-root))
|
(let* ((project-root (doom-modeline-project-root))
|
||||||
(file-name-split (shrink-path-file-mixed (or project-root "")
|
(file-name-split (shrink-path-file-mixed (or project-root "")
|
||||||
(file-name-directory buffer-file-name)
|
(file-name-directory file-path)
|
||||||
buffer-file-name))
|
file-path))
|
||||||
(active (doom-modeline--active)))
|
(active (doom-modeline--active)))
|
||||||
(if (null file-name-split)
|
(if (null file-name-split)
|
||||||
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))
|
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))
|
||||||
(pcase-let ((`(,root-path-parent ,project ,relative-path ,filename) file-name-split))
|
(pcase-let ((`(,root-path-parent ,project ,relative-path ,file-path) file-name-split))
|
||||||
(let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)))
|
(let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)))
|
||||||
(let ((sp-faces (or modified-faces (if active 'font-lock-comment-face)))
|
(let ((sp-faces (or modified-faces (if active 'font-lock-comment-face)))
|
||||||
(project-faces (or modified-faces (if active 'font-lock-string-face)))
|
(project-faces (or modified-faces (if active 'font-lock-string-face)))
|
||||||
|
@ -547,7 +553,7 @@ Example:
|
||||||
'face sp-props)
|
'face sp-props)
|
||||||
(propertize (concat project "/") 'face project-props)
|
(propertize (concat project "/") 'face project-props)
|
||||||
(if relative-path (propertize relative-path 'face relative-props))
|
(if relative-path (propertize relative-path 'face relative-props))
|
||||||
(propertize filename 'face file-props)))))))))
|
(propertize file-path 'face file-props)))))))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue