Add more faces for buffer path.

Fix #99.
This commit is contained in:
Vincent Zhang 2019-01-23 02:50:58 +08:00
parent 19b1bde931
commit 82e7020eec

View file

@ -148,6 +148,14 @@ The icons may not be showed correctly in terminal and on Windows.")
'((t (:inherit (mode-line-buffer-id bold)))) '((t (:inherit (mode-line-buffer-id bold))))
"Face used for the minor-modes segment in the mode-line.") "Face used for the minor-modes segment in the mode-line.")
(defface doom-modeline-project-parent-dir
'((t (:inherit (font-lock-comment-face bold))))
"Face used for the project parent directory of the mode-line buffer path.")
(defface doom-modeline-project-dir
'((t (:inherit (font-lock-string-face bold))))
"Face used for the project directory of the mode-line buffer path.")
(defface doom-modeline-project-root-dir (defface doom-modeline-project-root-dir
'((t (:inherit (mode-line-emphasis bold)))) '((t (:inherit (mode-line-emphasis bold))))
"Face used for the project part of the mode-line buffer path.") "Face used for the project part of the mode-line buffer path.")
@ -571,43 +579,39 @@ Example:
(let ((project-root (doom-modeline-project-root)) (let ((project-root (doom-modeline-project-root))
(active (doom-modeline--active)) (active (doom-modeline--active))
(modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))) (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 'doom-modeline-project-parent-dir)))
(project-faces (or modified-faces (if active 'font-lock-string-face))) (project-faces (or modified-faces (if active 'doom-modeline-project-dir)))
(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))))
(let ((sp-props `(,@(if sp-faces `(:inherit ,sp-faces)) ,@(if active '(:weight bold)))) (concat
(project-props `(,@(if project-faces `(:inherit ,project-faces)) ,@(if active '(:weight bold)))) ;; project root parent
(relative-props `(,@(if relative-faces `(:inherit ,relative-faces)))) (unless hide-project-root-parent
(file-props `(,@(if file-faces `(:inherit ,file-faces))))) (when-let (root-path-parent
(concat (file-name-directory (directory-file-name project-root)))
;; project root parent (propertize
(unless hide-project-root-parent (if (and truncate-project-root-parent
(when-let (root-path-parent (not (string-empty-p root-path-parent))
(file-name-directory (directory-file-name project-root))) (not (string= root-path-parent "/")))
(propertize (shrink-path--dirs-internal root-path-parent t)
(if (and truncate-project-root-parent (abbreviate-file-name root-path-parent))
(not (string-empty-p root-path-parent)) 'face sp-faces)))
(not (string= root-path-parent "/"))) ;; project
(shrink-path--dirs-internal root-path-parent t) (propertize
(abbreviate-file-name root-path-parent)) (concat (file-name-nondirectory (directory-file-name project-root)) "/")
'face sp-props))) 'face project-faces)
;; project ;; relative path
(propertize (propertize
(concat (file-name-nondirectory (directory-file-name project-root)) "/") (when-let (relative-path (file-relative-name
'face project-props) (or (file-name-directory file-path) "./")
;; relative path project-root))
(propertize (if (string= relative-path "./")
(when-let (relative-path (file-relative-name ""
(or (file-name-directory file-path) "./") (if truncate-project-relative-path
project-root)) (substring (shrink-path--dirs-internal relative-path t) 1)
(if (string= relative-path "./") relative-path)))
"" 'face relative-faces)
(if truncate-project-relative-path ;; file name
(substring (shrink-path--dirs-internal relative-path t) 1) (propertize (file-name-nondirectory file-path) 'face file-faces)))))
relative-path)))
'face relative-props)
;; file name
(propertize (file-name-nondirectory file-path) 'face file-props))))))
(provide 'doom-modeline-core) (provide 'doom-modeline-core)