[Enhancement] Make modeline color consistent while using minibuffer.

Close #114: Modeline color is inconsistent when using helm.
helm and eldoc-in-minibuffer-mode will trigger this issue.
This commit is contained in:
Vincent Zhang 2019-02-12 02:44:31 +08:00
parent b1656e47b2
commit a1e765fa56
2 changed files with 102 additions and 60 deletions

View file

@ -174,8 +174,8 @@ The icons may not be showed correctly in terminal and on Windows.")
(defface doom-modeline-panel (defface doom-modeline-panel
'((t (:inherit mode-line-highlight))) '((t (:inherit mode-line-highlight)))
"Face for 'X out of Y' segments, such as `doom-modeline--anzu', "Face for 'X out of Y' segments, such as `anzu', `evil-substitute'
`doom-modeline--evil-substitute' and`iedit'") and`iedit', etc.")
(defface doom-modeline-info (defface doom-modeline-info
`((t (:inherit (success bold)))) `((t (:inherit (success bold))))
@ -301,9 +301,10 @@ Example:
(let ((rhs-str (format-mode-line (cons "" rhs-forms)))) (let ((rhs-str (format-mode-line (cons "" rhs-forms))))
(list lhs-forms (list lhs-forms
(propertize (propertize
" " 'display " "
`((space :align-to (- (+ right right-fringe right-margin) 'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive)
,(+ 1 (string-width rhs-str)))))) 'display `((space :align-to (- (+ right right-fringe right-margin)
,(+ 1 (string-width rhs-str))))))
rhs-str))) rhs-str)))
(concat "Modeline:\n" (concat "Modeline:\n"
(format " %s\n %s" (format " %s\n %s"
@ -423,6 +424,10 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
(propertize " " 'face 'variable-pitch) (propertize " " 'face 'variable-pitch)
"Text style with icons in mode-line.") "Text style with icons in mode-line.")
(defvar doom-modeline-inactive-vspc
(propertize " " 'face '(:inherit (variable-pitch mode-line-inactive)))
"Text style with icons in inactive mode-line.")
(defun doom-modeline-icon-octicon (&rest args) (defun doom-modeline-icon-octicon (&rest args)
"Display octicon via ARGS." "Display octicon via ARGS."
(when doom-modeline-icon (when doom-modeline-icon

View file

@ -141,7 +141,9 @@
(doom-modeline-def-segment buffer-default-directory (doom-modeline-def-segment buffer-default-directory
"Displays `default-directory'. This is for special buffers like the scratch "Displays `default-directory'. 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 (doom-modeline--active) 'doom-modeline-buffer-path))) (let ((face (if (doom-modeline--active)
'doom-modeline-buffer-path
'mode-line-inactive)))
(concat (if (display-graphic-p) " ") (concat (if (display-graphic-p) " ")
(doom-modeline-icon-octicon (doom-modeline-icon-octicon
"file-directory" "file-directory"
@ -185,7 +187,7 @@ Uses `all-the-icons-material' to fetch the icon."
(when icon (when icon
(doom-modeline-icon-material (doom-modeline-icon-material
icon icon
:face (if (doom-modeline--active) face) :face face
:height (or height 1.1) :height (or height 1.1)
:v-adjust (or voffset -0.225))) :v-adjust (or voffset -0.225)))
(when text (when text
@ -257,7 +259,9 @@ Uses `all-the-icons-material' to fetch the icon."
(if buffer-file-name (if buffer-file-name
(doom-modeline-buffer-file-name) (doom-modeline-buffer-file-name)
(propertize "%b" (propertize "%b"
'face (if (doom-modeline--active) 'doom-modeline-buffer-file) 'face (if (doom-modeline--active)
'doom-modeline-buffer-file
'mode-line-inactive)
'help-echo "Buffer name 'help-echo "Buffer name
mouse-1: Previous buffer\nmouse-3: Next buffer" mouse-1: Previous buffer\nmouse-3: Next buffer"
'local-map mode-line-buffer-identification-keymap)))) 'local-map mode-line-buffer-identification-keymap))))
@ -289,7 +293,7 @@ mouse-1: Previous buffer\nmouse-3: Next buffer"
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 ((active (doom-modeline--active))) (let ((active (doom-modeline--active)))
(concat (concat
" " (propertize " " 'face (if active 'mode-line 'mode-line-inactive))
;; major mode icon ;; major mode icon
(when (and doom-modeline-icon doom-modeline-major-mode-icon) (when (and doom-modeline-icon doom-modeline-major-mode-icon)
@ -303,8 +307,8 @@ directory, the file name, and its state (modified, read-only or non-existent)."
,(doom-modeline-icon-height 1.1) ,(doom-modeline-icon-height 1.1)
:family :family
,(all-the-icons-icon-family icon) ,(all-the-icons-icon-family icon)
:inherit))) :inherit 'mode-line-inactive)))
doom-modeline-vspc))) (if active doom-modeline-vspc doom-modeline-inactive-vspc))))
;; state icon ;; state icon
(when-let ((icon (or doom-modeline--buffer-file-state-icon (when-let ((icon (or doom-modeline--buffer-file-state-icon
@ -319,9 +323,9 @@ directory, the file name, and its state (modified, read-only or non-existent)."
,(doom-modeline-icon-height 1.3) ,(doom-modeline-icon-height 1.3)
:family :family
,(all-the-icons-icon-family icon) ,(all-the-icons-icon-family icon)
:inherit) :inherit 'mode-line-inactive)
'mode-line-inactive))) 'mode-line-inactive)))
doom-modeline-vspc)) (if active doom-modeline-vspc doom-modeline-inactive-vspc)))
;; buffer file name ;; buffer file name
(when-let ((name (or doom-modeline--buffer-file-name (when-let ((name (or doom-modeline--buffer-file-name
@ -336,7 +340,8 @@ directory, the file name, and its state (modified, read-only or non-existent)."
" %b " " %b "
'face (cond ((and buffer-file-name (buffer-modified-p)) 'face (cond ((and buffer-file-name (buffer-modified-p))
'doom-modeline-buffer-modified) 'doom-modeline-buffer-modified)
((doom-modeline--active) 'doom-modeline-buffer-file)))) ((doom-modeline--active) 'doom-modeline-buffer-file)
(t 'mode-line-inactive))))
;; ;;
(doom-modeline-def-segment buffer-encoding (doom-modeline-def-segment buffer-encoding
@ -347,10 +352,12 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(1 " RLF") (1 " RLF")
(2 " CR")) (2 " CR"))
(let ((sys (coding-system-plist buffer-file-coding-system))) (let ((sys (coding-system-plist buffer-file-coding-system)))
(cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8)) (cond ((memq (plist-get sys :category)
'(coding-category-undecided coding-category-utf-8))
" UTF-8 ") " UTF-8 ")
(t (upcase (symbol-name (plist-get sys :name)))))) (t (upcase (symbol-name (plist-get sys :name))))))
" ") " ")
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive)
'help-echo 'mode-line-mule-info-help-echo 'help-echo 'mode-line-mule-info-help-echo
'mouse-face '(:box 1) 'mouse-face '(:box 1)
'local-map mode-line-coding-system-map)) 'local-map mode-line-coding-system-map))
@ -364,7 +371,9 @@ directory, the file name, and its state (modified, read-only or non-existent)."
"Hostname for remote buffers." "Hostname for remote buffers."
(when default-directory (when default-directory
(when-let ((host (file-remote-p default-directory 'host))) (when-let ((host (file-remote-p default-directory 'host)))
(concat "@" host)))) (propertize
(concat "@" host)
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive)))))
;; ;;
@ -391,7 +400,9 @@ mouse-3: Toggle minor modes"
" (%+d)" " (%+d)"
" (%-d)") " (%-d)")
text-scale-mode-amount))) text-scale-mode-amount)))
'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) 'face (if (doom-modeline--active)
'doom-modeline-buffer-major-mode
'mode-line-inactive)))
;; ;;
@ -400,7 +411,9 @@ mouse-3: Toggle minor modes"
(doom-modeline-def-segment process (doom-modeline-def-segment process
"The process info." "The process info."
mode-line-process) (if (doom-modeline--active)
mode-line-process
(propertize mode-line-process 'face 'mode-line-inactive)))
;; ;;
@ -414,7 +427,9 @@ mouse-3: Toggle minor modes"
(concat (concat
" " " "
(propertize minions-mode-line-lighter (propertize minions-mode-line-lighter
'face (if active 'doom-modeline-buffer-minor-mode) 'face (if active
'doom-modeline-buffer-minor-mode
'mode-line-inactive)
'help-echo "Minions 'help-echo "Minions
mouse-1: Display minor modes menu" mouse-1: Display minor modes menu"
'mouse-face 'mode-line-highlight 'mouse-face 'mode-line-highlight
@ -423,7 +438,9 @@ mouse-1: Display minor modes menu"
" ") " ")
(propertize (propertize
(concat (format-mode-line `(:propertize ("" minor-mode-alist))) " ") (concat (format-mode-line `(:propertize ("" minor-mode-alist))) " ")
'face (if active 'doom-modeline-buffer-minor-mode)))))) 'face (if active
'doom-modeline-buffer-minor-mode
'mode-line-inactive))))))
;; ;;
@ -492,7 +509,7 @@ Uses `all-the-icons-octicon' to fetch the icon."
(when-let ((icon (or doom-modeline--vcs-icon (doom-modeline--update-vcs-icon))) (when-let ((icon (or doom-modeline--vcs-icon (doom-modeline--update-vcs-icon)))
(text (or doom-modeline--vcs-text (doom-modeline-update-vcs-text)))) (text (or doom-modeline--vcs-text (doom-modeline-update-vcs-text))))
(concat (concat
" " (propertize " " 'face (if active 'mode-line 'mode-line-inactive))
(if active (if active
(concat icon doom-modeline-vspc text) (concat icon doom-modeline-vspc text)
(concat (concat
@ -503,11 +520,11 @@ Uses `all-the-icons-octicon' to fetch the icon."
,(doom-modeline-icon-height 1.2) ,(doom-modeline-icon-height 1.2)
:family :family
,(all-the-icons-icon-family icon) ,(all-the-icons-icon-family icon)
:inherit) :inherit 'mode-line-inactive)
'mode-line-inactive)) 'mode-line-inactive))
doom-modeline-vspc doom-modeline-inactive-vspc
(propertize text 'face 'mode-line-inactive))) (propertize text 'face 'mode-line-inactive)))
" ")))) (propertize " " 'face (if active 'mode-line 'mode-line-inactive))))))
;; ;;
@ -790,7 +807,8 @@ icons."
(let ((icon (car seg)) (let ((icon (car seg))
(text (cdr seg))) (text (cdr seg)))
(concat (concat
(if vc-mode " " " ") (propertize (if vc-mode " " " ")
'face (if active 'mode-line 'mode-line-inactive))
(if active (if active
(concat icon (concat icon
(when (and icon text) doom-modeline-vspc) (when (and icon text) doom-modeline-vspc)
@ -804,12 +822,11 @@ icons."
,(doom-modeline-icon-height 1.3) ,(doom-modeline-icon-height 1.3)
:family :family
,(all-the-icons-icon-family icon) ,(all-the-icons-icon-family icon)
:inherit) :inherit 'mode-line-inactive)
'mode-line-inactive))) 'mode-line-inactive)))
(when (and icon text) doom-modeline-vspc) (when (and icon text) doom-modeline-inactive-vspc)
(when text (when text (propertize text 'face 'mode-line-inactive))))
(propertize text 'face 'mode-line-inactive)))) (propertize " " 'face (if active 'mode-line 'mode-line-inactive))))))
" "))))
;; ;;
@ -919,7 +936,7 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
(format " %s+ " total)) (format " %s+ " total))
(t (t
(format " %s/%d " here total)))) (format " %s/%d " here total))))
'face (if (doom-modeline--active) 'doom-modeline-panel)))) 'face (if (doom-modeline--active) 'doom-modeline-panel 'mode-line-inactive))))
(defsubst doom-modeline--evil-substitute () (defsubst doom-modeline--evil-substitute ()
"Show number of matches for evil-ex substitutions and highlights in real time." "Show number of matches for evil-ex substitutions and highlights in real time."
@ -935,7 +952,7 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
(if pattern (if pattern
(format " %s matches " (how-many pattern (car range) (cdr range))) (format " %s matches " (how-many pattern (car range) (cdr range)))
" - ")) " - "))
'face (if (doom-modeline--active) 'doom-modeline-panel)))) 'face (if (doom-modeline--active) 'doom-modeline-panel 'mode-line-inactive))))
(defun doom-modeline-themes--overlay-sort (a b) (defun doom-modeline-themes--overlay-sort (a b)
"Sort overlay A and B." "Sort overlay A and B."
@ -959,7 +976,7 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
-1) -1)
"-") "-")
length)) length))
'face (if (doom-modeline--active) 'doom-modeline-panel)))) 'face (if (doom-modeline--active) 'doom-modeline-panel 'mode-line-inactive))))
(defsubst doom-modeline--symbol-overlay () (defsubst doom-modeline--symbol-overlay ()
"Show the number of matches for symbol overlay." "Show the number of matches for symbol overlay."
@ -977,7 +994,7 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
(format (concat " %d/%d " (and (cadr keyword) "in scope ")) (format (concat " %d/%d " (and (cadr keyword) "in scope "))
(+ count 1) (+ count 1)
(+ count (length after))) (+ count (length after)))
'face (if (doom-modeline--active) 'doom-modeline-panel)))))) 'face (if (doom-modeline--active) 'doom-modeline-panel 'mode-line-inactive))))))
(defsubst doom-modeline--multiple-cursors () (defsubst doom-modeline--multiple-cursors ()
"Show the number of multiple cursors." "Show the number of multiple cursors."
@ -986,13 +1003,14 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
(concat (car mc/mode-line) (concat (car mc/mode-line)
(eval (cadadr mc/mode-line)) (eval (cadadr mc/mode-line))
" ") " ")
'face (if (doom-modeline--active) 'doom-modeline-panel)))) 'face (if (doom-modeline--active) 'doom-modeline-panel 'mode-line-inactive))))
(defsubst doom-modeline--buffer-size () (defsubst doom-modeline--buffer-size ()
"Show buffer size." "Show buffer size."
(if (and buffer-file-name size-indication-mode) (if (and buffer-file-name size-indication-mode)
(propertize " %I " (propertize " %I "
'help-echo "Buffer size\n\ 'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive)
'help-echo "Buffer size
mouse-1: Display Line and Column Mode Menu" mouse-1: Display Line and Column Mode Menu"
'mouse-face '(:box 1) 'mouse-face '(:box 1)
'local-map mode-line-column-line-number-mode-map))) 'local-map mode-line-column-line-number-mode-map)))
@ -1027,7 +1045,9 @@ of active `multiple-cursors'."
(cl-destructuring-bind (width . height) (cl-destructuring-bind (width . height)
(when (fboundp 'image-size) (when (fboundp 'image-size)
(image-size (image-get-display-property) :pixels)) (image-size (image-get-display-property) :pixels))
(format " %dx%d " width height))))) (propertize
(format " %dx%d " width height)
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive))))))
;; ;;
@ -1122,8 +1142,8 @@ one. The ignored buffers are excluded unless `aw-ignore-on' is nil."
(if (< 0 (length num)) (if (< 0 (length num))
(propertize (format " %s " num) (propertize (format " %s " num)
'face (if (doom-modeline--active) 'face (if (doom-modeline--active)
'doom-modeline-buffer-major-mode)) 'doom-modeline-buffer-major-mode
""))) 'mode-line-inactive)))))
;; ;;
@ -1142,8 +1162,9 @@ Requires `eyebrowse-mode' to be enabled."
(when num (int-to-string num))))) (when num (int-to-string num)))))
(assq-delete-all 'eyebrowse-mode mode-line-misc-info) (assq-delete-all 'eyebrowse-mode mode-line-misc-info)
(propertize (format " %s " str) 'face (propertize (format " %s " str) 'face
(if (doom-modeline--active) 'doom-modeline-buffer-major-mode))) (if (doom-modeline--active)
"")) 'doom-modeline-buffer-major-mode
'mode-line-inactive)))))
;; ;;
@ -1192,8 +1213,7 @@ mouse-2: Show help for minor mode"
(doom-modeline-def-segment persp-name (doom-modeline-def-segment persp-name
"The current perspective name." "The current perspective name."
(if (doom-modeline--active) (if (doom-modeline--active)
doom-modeline--persp-name doom-modeline--persp-name))
""))
;; ;;
@ -1241,13 +1261,14 @@ See `mode-line-percent-position'.")
(doom-modeline-def-segment buffer-position (doom-modeline-def-segment buffer-position
"The buffer position information." "The buffer position information."
(let ((lc '(line-number-mode (let ((active (doom-modeline--active))
(lc '(line-number-mode
(column-number-mode (column-number-mode
(doom-modeline-column-zero-based " %l:%c" " %l:%C") (doom-modeline-column-zero-based " %l:%c" " %l:%C")
" %l") " %l")
(column-number-mode (doom-modeline-column-zero-based " :%c" " :%C"))))) (column-number-mode (doom-modeline-column-zero-based " :%c" " :%C")))))
(if (and (bound-and-true-p nyan-mode) (if (and (bound-and-true-p nyan-mode)
(doom-modeline--active) active
(>= (window-width) nyan-minimum-window-width)) (>= (window-width) nyan-minimum-window-width))
(concat " " (nyan-create) " " (concat " " (nyan-create) " "
(propertize (format-mode-line lc) (propertize (format-mode-line lc)
@ -1255,14 +1276,19 @@ See `mode-line-percent-position'.")
mouse-1: Display Line and Column Mode Menu" mouse-1: Display Line and Column Mode Menu"
'mouse-face '(:box 1) 'mouse-face '(:box 1)
'local-map mode-line-column-line-number-mode-map)) 'local-map mode-line-column-line-number-mode-map))
`(:propertize (" " (propertize
,lc (concat " "
(if doom-modeline-percent-position (" " doom-modeline-percent-position)) (format-mode-line lc)
(when (or line-number-mode column-number-mode doom-modeline-percent-position) " ")) (if doom-modeline-percent-position
help-echo "Buffer position\n\ (format-mode-line '(" " doom-modeline-percent-position "%%")))
(if (or line-number-mode
column-number-mode doom-modeline-percent-position)
" "))
'face (if active 'mode-line 'mode-line-inactive)
'help-echo "Buffer position\n\
mouse-1: Display Line and Column Mode Menu" mouse-1: Display Line and Column Mode Menu"
mouse-face (:box 1) 'mouse-face '(:box 1)
local-map ,mode-line-column-line-number-mode-map)))) 'local-map mode-line-column-line-number-mode-map))))
;; ;;
;; party parrot ;; party parrot
@ -1289,7 +1315,8 @@ mouse-1: Display Line and Column Mode Menu"
((evil-motion-state-p) 'doom-modeline-evil-motion-state) ((evil-motion-state-p) 'doom-modeline-evil-motion-state)
((evil-visual-state-p) 'doom-modeline-evil-visual-state) ((evil-visual-state-p) 'doom-modeline-evil-visual-state)
((evil-operator-state-p) 'doom-modeline-evil-operator-state) ((evil-operator-state-p) 'doom-modeline-evil-operator-state)
((evil-replace-state-p) 'doom-modeline-evil-replace-state))))))) ((evil-replace-state-p) 'doom-modeline-evil-replace-state))
'mode-line-inactive)))))
;; ;;
@ -1300,7 +1327,8 @@ mouse-1: Display Line and Column Mode Menu"
"The current god state. Requires `god-mode' to be enabled." "The current god state. Requires `god-mode' to be enabled."
(when (bound-and-true-p god-local-mode) (when (bound-and-true-p god-local-mode)
(propertize " <G> " 'face (if (doom-modeline--active) (propertize " <G> " 'face (if (doom-modeline--active)
'doom-modeline-evil-normal-state)))) 'doom-modeline-evil-normal-state
'mode-line-inactive))))
;; ;;
@ -1311,7 +1339,8 @@ mouse-1: Display Line and Column Mode Menu"
"The current ryo-modal state. Requires `ryo-modal-mode' to be enabled." "The current ryo-modal state. Requires `ryo-modal-mode' to be enabled."
(when (bound-and-true-p ryo-modal-mode) (when (bound-and-true-p ryo-modal-mode)
(propertize " <R> " 'face (if (doom-modeline--active) (propertize " <R> " 'face (if (doom-modeline--active)
'doom-modeline-evil-normal-state)))) 'doom-modeline-evil-normal-state
'mode-line-inactive))))
;; ;;
@ -1325,7 +1354,8 @@ mouse-1: Display Line and Column Mode Menu"
" <I> " " <I> "
" <C> ") " <C> ")
'face (if (doom-modeline--active) 'face (if (doom-modeline--active)
'doom-modeline-evil-normal-state)))) 'doom-modeline-evil-normal-state
'mode-line-inactive))))
;; ;;
;; input method ;; input method
@ -1344,7 +1374,9 @@ mouse-1: Display Line and Column Mode Menu"
(nth 3 (assoc default-input-method input-method-alist)) (nth 3 (assoc default-input-method input-method-alist))
" ")) " "))
(t "")) (t ""))
'face (if (doom-modeline--active) 'doom-modeline-buffer-major-mode) 'face (if (doom-modeline--active)
'doom-modeline-buffer-major-mode
'mode-line-inactive)
'help-echo (concat 'help-echo (concat
"Current input method: " "Current input method: "
current-input-method current-input-method
@ -1362,6 +1394,7 @@ mouse-3: Describe current input method")
(doom-modeline-def-segment lsp (doom-modeline-def-segment lsp
"The LSP server state." "The LSP server state."
(if (and doom-modeline-lsp (if (and doom-modeline-lsp
(doom-modeline--active)
(bound-and-true-p lsp-mode)) (bound-and-true-p lsp-mode))
(concat (lsp-mode-line) " "))) (concat (lsp-mode-line) " ")))
@ -1496,9 +1529,13 @@ mouse-1: Toggle Debug on Quit"
(doom-modeline-def-segment pdf-pages (doom-modeline-def-segment pdf-pages
(when (eq major-mode 'pdf-view-mode) (when (eq major-mode 'pdf-view-mode)
(format " P%d/%d " (propertize
(eval `(pdf-view-current-page)) (format " P%d/%d "
(pdf-cache-number-of-pages)))) (eval `(pdf-view-current-page))
(pdf-cache-number-of-pages))
'face (if (doom-modeline--active)
'mode-line
'mode-line-inactive))))
;; ;;