Fix mode-line face & byte-compiler warnings

Fixes #184
This commit is contained in:
Henrik Lissner 2017-09-04 00:38:53 +02:00
parent d2d71795e5
commit 1a8e3a04f3
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -233,44 +233,49 @@ active."
('truncate-all (+doom-modeline--buffer-file-name-truncate t)) ('truncate-all (+doom-modeline--buffer-file-name-truncate t))
('relative-to-project (+doom-modeline--buffer-file-name-relative)) ('relative-to-project (+doom-modeline--buffer-file-name-relative))
('file-name (propertize (file-name-nondirectory buffer-file-name) ('file-name (propertize (file-name-nondirectory buffer-file-name)
'face `(:inherit ,(or (and (buffer-modified-p) 'face
'doom-modeline-buffer-modified) (let ((face (or (and (buffer-modified-p)
(and (active) 'doom-modeline-buffer-modified)
'doom-modeline-buffer-file)))))) (and (active)
'doom-modeline-buffer-file))))
(when face `(:inherit ,face))))))
'help-echo (+doom-modeline--buffer-file-name nil))) 'help-echo (+doom-modeline--buffer-file-name nil)))
(defun +doom-modeline--buffer-file-name-truncate (&optional truncate-tail) (defun +doom-modeline--buffer-file-name-truncate (&optional truncate-tail)
"Propertized `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* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)) (let ((dirs (shrink-path-prompt (file-name-directory
(active (active)) (or buffer-file-truename
(dirs (shrink-path-prompt (file-name-directory (file-truename buffer-file-name))))))
(or buffer-file-truename
(file-truename buffer-file-name))))))
(if (null dirs) (if (null dirs)
"%b" "%b"
(let ((dirname (car dirs)) (let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))
(basename (cdr dirs)) (active (active)))
(dir-faces `(:inherit ,(or modified-faces (if active 'doom-modeline-project-root-dir)))) (let ((dirname (car dirs))
(file-faces `(:inherit ,(or modified-faces (if active 'doom-modeline-buffer-file))))) (basename (cdr dirs))
(concat (propertize dirname 'face dir-faces) (dir-faces (or modified-faces (if active 'doom-modeline-project-root-dir)))
(propertize (concat (if truncate-tail (substring basename 0 1) basename) "/") (file-faces (or modified-faces (if active 'doom-modeline-buffer-file))))
'face dir-faces) (concat (propertize dirname
(propertize (file-name-nondirectory buffer-file-name) 'face file-faces)))))) 'face (if dir-faces `(:inherit ,dir-faces)))
(propertize (concat (if truncate-tail (substring basename 0 1) basename) "/")
'face (if dir-faces `(:inherit ,dir-faces)))
(propertize (file-name-nondirectory buffer-file-name)
'face (if file-faces `(:inherit ,file-faces)))))))))
(defun +doom-modeline--buffer-file-name-relative () (defun +doom-modeline--buffer-file-name-relative ()
"Propertized `buffer-file-name' showing directories relative to project's root only." "Propertized `buffer-file-name' showing directories relative to project's root only."
(let* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)) (let ((root (doom-project-root)))
(active (active))
(root (doom-project-root)))
(if (null root) (if (null root)
"%b" "%b"
(let ((relative-dirs (file-relative-name (file-name-directory buffer-file-name) root)) (let* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))
(relative-faces `(:inherit ,(or modified-faces (if active 'doom-modeline-buffer-path)))) (active (active))
(file-faces `(:inherit ,(or modified-faces (if active 'doom-modeline-buffer-file))))) (relative-dirs (file-relative-name (file-name-directory buffer-file-name) root))
(relative-faces (or modified-faces (if active 'doom-modeline-buffer-path)))
(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 relative-faces) (concat (propertize relative-dirs 'face (if relative-faces `(:inherit ,relative-faces)))
(propertize (file-name-nondirectory buffer-file-name) 'face file-faces)))))) (propertize (file-name-nondirectory buffer-file-name)
'face (if file-faces `(:inherit ,file-faces))))))))
(defun +doom-modeline--buffer-file-name (truncate-project-root-parent) (defun +doom-modeline--buffer-file-name (truncate-project-root-parent)
"Propertized `buffer-file-name'. "Propertized `buffer-file-name'.
@ -279,9 +284,7 @@ fish-shell style.
Example: 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* ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)) (let* ((project-root (doom-project-root))
(active (active))
(project-root (doom-project-root))
(file-name-split (shrink-path-file-mixed project-root (file-name-split (shrink-path-file-mixed project-root
(file-name-directory (file-name-directory
(or buffer-file-truename (or buffer-file-truename
@ -290,19 +293,25 @@ Example:
(if (null file-name-split) (if (null file-name-split)
"%b" "%b"
(pcase-let ((`(,root-path-parent ,project ,relative-path ,filename) file-name-split)) (pcase-let ((`(,root-path-parent ,project ,relative-path ,filename) file-name-split))
(let ((sp-faces `(:inherit ,(or modified-faces (if active 'font-lock-comment-face)) (let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified))
,@(if active '(:weight bold)))) (active (active)))
(project-faces `(:inherit ,(or modified-faces (if active 'font-lock-string-face)) (let ((sp-faces (or modified-faces (if active 'font-lock-comment-face)))
,@(if active '(:weight bold)))) (project-faces (or modified-faces (if active 'font-lock-string-face)))
(relative-faces `(:inherit ,(or modified-faces (if active 'doom-modeline-buffer-path)))) (relative-faces (or modified-faces (if active 'doom-modeline-buffer-path)))
(file-faces `(:inherit ,(or modified-faces (if active 'doom-modeline-buffer-file))))) (file-faces (or modified-faces (if active 'doom-modeline-buffer-file))))
(concat (propertize (if truncate-project-root-parent (let ((sp-props `(,@(if sp-faces `(:inherit ,sp-faces)) ,@(if active '(:weight bold))))
root-path-parent (project-props `(,@(if project-faces `(:inherit ,project-faces)) ,@(if active '(:weight bold))))
(abbreviate-file-name project-root)) (relative-props `(,@(if relative-faces `(:inherit ,relative-faces))))
'face sp-faces) (file-props `(,@(if file-faces `(:inherit ,file-faces)))))
(propertize (concat project "/") 'face project-faces) (concat (propertize (if truncate-project-root-parent
(when relative-path (propertize relative-path 'face relative-faces)) root-path-parent
(propertize filename 'face file-faces))))))) (abbreviate-file-name project-root))
'face sp-props)
(propertize (concat project "/") 'face project-props)
(when relative-path (propertize relative-path 'face relative-props))
(propertize filename 'face file-props)))))))))
;; ;;
;; Segments ;; Segments
;; ;;
@ -324,17 +333,14 @@ buffer where knowing the current project directory is important."
(def-modeline-segment! buffer-info (def-modeline-segment! buffer-info
"Combined information about the current buffer, including the current working "Combined information about the current buffer, including the current working
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))
(active (active))
(faces (if modified-p 'doom-modeline-buffer-modified)))
(concat (cond (buffer-read-only (concat (cond (buffer-read-only
(concat (all-the-icons-octicon (concat (all-the-icons-octicon
"lock" "lock"
:face 'doom-modeline-warning :face 'doom-modeline-warning
:v-adjust -0.05) :v-adjust -0.05)
" ")) " "))
(modified-p ((buffer-modified-p)
(concat (all-the-icons-faicon (concat (all-the-icons-faicon
"floppy-o" "floppy-o"
:face 'doom-modeline-buffer-modified :face 'doom-modeline-buffer-modified