Fix #173: Vertical separators showing up when modeline is inactive.

This commit is contained in:
Vincent Zhang 2019-05-18 23:53:47 +08:00
parent 66029d4590
commit 230ffe8efc
3 changed files with 148 additions and 154 deletions

View file

@ -86,6 +86,21 @@ It returns a file name which can be used directly as argument of
;; multiple-cursors ;; multiple-cursors
("i-cursor" . "\xf246") ("i-cursor" . "\xf246")
;; vcs
("git-compare" . "\xf0ac")
("git-merge" . "\xf023")
("arrow-down" . "\xf03f")
("alert" . "\xf02d")
("git-branch" . "\xf020")
;; checker: flycheck/flymake
("do_not_disturb_alt" . "\xe611")
("check" . "\xe5ca")
("access_time" . "\xe192")
("sim_card_alert" . "\xe624")
("pause" . "\xe034")
("priority_high" . "\xe645")
;; LSP ;; LSP
("rocket" . "\xf135") ("rocket" . "\xf135")
@ -128,7 +143,7 @@ It returns a file name which can be used directly as argument of
(defvar doom-modeline-buffer-file-name-style 'truncate-upto-project (defvar doom-modeline-buffer-file-name-style 'truncate-upto-project
"Determines the style used by `doom-modeline-buffer-file-name'. "Determines the style used by `doom-modeline-buffer-file-name'.
Given ~/Projects/FOSS/emacs/lisp/comint.el Given ~/Projects/FOSS/emacs/lisp/comint.el
truncate-upto-project => ~/P/F/emacs/lisp/comint.el truncate-upto-project => ~/P/F/emacs/lisp/comint.el
truncate-from-project => ~/Projects/FOSS/emacs/l/comint.el truncate-from-project => ~/Projects/FOSS/emacs/l/comint.el
truncate-with-project => emacs/l/comint.el truncate-with-project => emacs/l/comint.el
@ -373,9 +388,9 @@ Given ~/Projects/FOSS/emacs/lisp/comint.el
" " " "
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive) 'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive)
'display `((space :align-to (- (+ right right-fringe right-margin) 'display `((space :align-to (- (+ right right-fringe right-margin)
,(+ 1 (string-width ,(string-width
(format-mode-line (format-mode-line
(cons "" rhs-forms)))))))) (cons "" rhs-forms)))))))
rhs-forms)) rhs-forms))
(concat "Modeline:\n" (concat "Modeline:\n"
(format " %s\n %s" (format " %s\n %s"

View file

@ -192,17 +192,25 @@
(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) (let ((active (doom-modeline--active))
'doom-modeline-buffer-path (icon (doom-modeline-icon-octicon "file-directory"
'mode-line-inactive))) :face 'doom-modeline-buffer-path
:v-adjust -0.05
:height 1.25)))
(concat (doom-modeline-whitespace) (concat (doom-modeline-whitespace)
(doom-modeline-icon-octicon (when doom-modeline-icon
"file-directory" (concat
:face face (if active
:v-adjust -0.05 icon
:height 1.25) (propertize icon 'face `(:inherit
(when doom-modeline-icon (doom-modeline-whitespace)) ,(get-text-property 0 'face icon)
(propertize (abbreviate-file-name default-directory) 'face face)))) :inherit
mode-line-inactive)))
(doom-modeline-whitespace)))
(propertize (abbreviate-file-name default-directory)
'face (if active
'doom-modeline-buffer-path
'mode-line-inactive)))))
;; ;;
(defvar-local doom-modeline--buffer-file-icon nil) (defvar-local doom-modeline--buffer-file-icon nil)
@ -374,40 +382,29 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(when (and doom-modeline-icon doom-modeline-major-mode-icon) (when (and doom-modeline-icon doom-modeline-major-mode-icon)
(when-let ((icon (or doom-modeline--buffer-file-icon (when-let ((icon (or doom-modeline--buffer-file-icon
(doom-modeline-update-buffer-file-icon)))) (doom-modeline-update-buffer-file-icon))))
(unless (string-empty-p icon) (when icon
(concat (concat
(propertize icon 'face (if active
(if active icon
`(:inherit (propertize icon 'face `(:inherit
mode-line ,(let* ((props (get-text-property 0 'face icon)))
:inherit (if doom-modeline-major-mode-color-icon
,(let ((props (get-text-property 0 'face icon))) props (remove :inherit props)))
(if doom-modeline-major-mode-color-icon :inherit
props mode-line-inactive)))
(remove :inherit props))))
`(:inherit
,(let ((props (get-text-property 0 'face icon)))
(if doom-modeline-major-mode-color-icon
props
(remove :inherit props)))
:inherit
mode-line-inactive)))
(doom-modeline-vspc))))) (doom-modeline-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
(doom-modeline-update-buffer-file-state-icon)))) (doom-modeline-update-buffer-file-state-icon))))
(unless (string-empty-p icon) (when icon
(concat (concat
(propertize icon 'face (if active
(if active `(:inherit icon
mode-line (propertize icon 'face `(:inherit
:inherit ,(get-text-property 0 'face icon)
,(get-text-property 0 'face icon)) :inherit
`(:inherit mode-line-inactive)))
,(get-text-property 0 'face icon)
:inherit
mode-line-inactive)))
(doom-modeline-vspc)))) (doom-modeline-vspc))))
;; buffer file name ;; buffer file name
@ -443,8 +440,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(cond ((memq (plist-get sys :category) (cond ((memq (plist-get sys :category)
'(coding-category-undecided coding-category-utf-8)) '(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)))))))
(doom-modeline-whitespace))
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive) '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 0) 'mouse-face '(:box 0)
@ -482,23 +478,25 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(doom-modeline-def-segment major-mode (doom-modeline-def-segment major-mode
"The major mode, including environment and text-scale info." "The major mode, including environment and text-scale info."
(propertize (propertize
(concat (format-mode-line (concat
`(:propertize ("" mode-name) (doom-modeline-whitespace)
help-echo "Major mode\n\ (propertize mode-name
'help-echo "Major mode\n\
mouse-1: Display major mode menu\n\ mouse-1: Display major mode menu\n\
mouse-2: Show help for major mode\n\ mouse-2: Show help for major mode\n\
mouse-3: Toggle minor modes" mouse-3: Toggle minor modes"
mouse-face mode-line-highlight 'mouse-face 'mode-line-highlight
local-map ,mode-line-major-mode-keymap)) 'local-map mode-line-major-mode-keymap)
(when (and doom-modeline-env-version doom-modeline-env--version) (when (and doom-modeline-env-version doom-modeline-env--version)
(format " %s" doom-modeline-env--version)) (format " %s" doom-modeline-env--version))
(and (boundp 'text-scale-mode-amount) (and (boundp 'text-scale-mode-amount)
(/= text-scale-mode-amount 0) (/= text-scale-mode-amount 0)
(format (format
(if (> text-scale-mode-amount 0) (if (> text-scale-mode-amount 0)
" (%+d)" " (%+d)"
" (%-d)") " (%-d)")
text-scale-mode-amount))) text-scale-mode-amount))
(doom-modeline-whitespace))
'face (if (doom-modeline--active) 'face (if (doom-modeline--active)
'doom-modeline-buffer-major-mode 'doom-modeline-buffer-major-mode
'mode-line-inactive))) 'mode-line-inactive)))
@ -543,7 +541,7 @@ mouse-1: Display minor modes menu"
"%%%%" "%%%%"
(format-mode-line '("" minor-mode-alist)) (format-mode-line '("" minor-mode-alist))
t t) t t)
" ") (doom-modeline-whitespace))
'face (if active 'face (if active
'doom-modeline-buffer-minor-mode 'doom-modeline-buffer-minor-mode
'mode-line-inactive)))))) 'mode-line-inactive))))))
@ -622,27 +620,17 @@ 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
(doom-modeline-whitespace) (doom-modeline-whitespace) (doom-modeline-whitespace)
(propertize icon 'face (if active
(if active `(:inherit icon
mode-line (propertize icon 'face `(:inherit
:inherit ,(get-text-property 0 'face icon)
,(get-text-property 0 'face icon)) :inherit
`(:inherit mode-line-inactive)))
,(get-text-property 0 'face icon) (if doom-modeline-icon (doom-modeline-vspc))
:inherit (if active
mode-line-inactive))) text
(if doom-modeline-icon (propertize text 'face 'mode-line-inactive))
(doom-modeline-vspc))
(propertize text 'face
(if active `(:inherit
,(get-text-property 0 'face text)
:inherit
mode-line)
`(:inherit
,(get-text-property 0 'face text)
:inherit
mode-line-inactive)))
(doom-modeline-whitespace))))) (doom-modeline-whitespace)))))
@ -691,26 +679,26 @@ Uses `all-the-icons-material' to fetch the icon."
(`interrupted (doom-modeline-checker-icon "pause" "!" 'doom-modeline-debug)) (`interrupted (doom-modeline-checker-icon "pause" "!" 'doom-modeline-debug))
(`suspicious (doom-modeline-checker-icon "priority_high" "!" 'doom-modeline-urgent)) (`suspicious (doom-modeline-checker-icon "priority_high" "!" 'doom-modeline-urgent))
(_ nil)))) (_ nil))))
(propertize (when icon
icon (propertize icon
'help-echo (concat "Flycheck\n" 'help-echo (concat "Flycheck\n"
(pcase status (pcase status
('finished "mouse-1: Display minor mode menu ('finished "mouse-1: Display minor mode menu
mouse-2: Show help for minor mode") mouse-2: Show help for minor mode")
('running "Running...") ('running "Running...")
('no-checker "No Checker") ('no-checker "No Checker")
('errored "Error") ('errored "Error")
('interrupted "Interrupted") ('interrupted "Interrupted")
('suspicious "Suspicious"))) ('suspicious "Suspicious")))
'mouse-face '(:box 0) 'mouse-face '(:box 0)
'local-map (let ((map (make-sparse-keymap))) 'local-map (let ((map (make-sparse-keymap)))
(define-key map [mode-line down-mouse-1] (define-key map [mode-line down-mouse-1]
flycheck-mode-menu-map) flycheck-mode-menu-map)
(define-key map [mode-line mouse-2] (define-key map [mode-line mouse-2]
(lambda () (lambda ()
(interactive) (interactive)
(describe-function 'flycheck-mode))) (describe-function 'flycheck-mode)))
map))))) map))))))
(add-hook 'flycheck-status-changed-functions #'doom-modeline-update-flycheck-icon) (add-hook 'flycheck-status-changed-functions #'doom-modeline-update-flycheck-icon)
(add-hook 'flycheck-mode-hook #'doom-modeline-update-flycheck-icon) (add-hook 'flycheck-mode-hook #'doom-modeline-update-flycheck-icon)
@ -957,30 +945,24 @@ icons."
`(,doom-modeline--flymake-icon . ,doom-modeline--flymake-text)) `(,doom-modeline--flymake-icon . ,doom-modeline--flymake-text))
((bound-and-true-p flycheck-mode) ((bound-and-true-p flycheck-mode)
`(,doom-modeline--flycheck-icon . ,doom-modeline--flycheck-text))))) `(,doom-modeline--flycheck-icon . ,doom-modeline--flycheck-text)))))
(if seg (when seg
(let ((icon (car seg)) (let ((icon (car seg))
(text (cdr seg))) (text (cdr seg)))
(concat (concat
(doom-modeline-whitespace) (doom-modeline-whitespace)
(unless vc-mode (doom-modeline-whitespace)) (when icon
(when icon (if active
(propertize icon 'face icon
(if active `(:inherit (propertize icon 'face `(:inherit
mode-line ,(get-text-property 0 'face icon)
:inherit :inherit
,(get-text-property 0 'face icon)) mode-line-inactive))))
`(:inherit (when (and doom-modeline-icon icon text)
,(get-text-property 0 'face icon) (doom-modeline-vspc))
:inherit (when text
mode-line-inactive)))) (if active
(when (and doom-modeline-icon icon text) text
(doom-modeline-vspc)) (propertize text 'face 'mode-line-inactive))))))))
(when text
(if active
text
(propertize text 'face 'mode-line-inactive)))
(doom-modeline-whitespace)))
"")))
;; ;;
@ -1589,7 +1571,7 @@ mouse-3: Describe current input method")
"The topic and nodes in the Info buffer." "The topic and nodes in the Info buffer."
(let ((active (doom-modeline--active))) (let ((active (doom-modeline--active)))
(concat (concat
" (" (propertize " (" (if active 'mode-line 'mode-line-inactive))
;; topic ;; topic
(propertize (if (stringp Info-current-file) (propertize (if (stringp Info-current-file)
(replace-regexp-in-string (replace-regexp-in-string
@ -1598,7 +1580,7 @@ mouse-3: Describe current input method")
(file-name-nondirectory Info-current-file))) (file-name-nondirectory Info-current-file)))
(format "*%S*" Info-current-file)) (format "*%S*" Info-current-file))
'face (if active 'doom-modeline-info 'mode-line-inactive)) 'face (if active 'doom-modeline-info 'mode-line-inactive))
") " (propertize ") " (if active 'mode-line 'mode-line-inactive))
;; node ;; node
(if Info-current-node (if Info-current-node
(propertize (replace-regexp-in-string (propertize (replace-regexp-in-string
@ -1629,7 +1611,6 @@ mouse-3: Describe current input method")
(face (if workspaces 'success 'warning)) (face (if workspaces 'success 'warning))
(icon (doom-modeline-lsp-icon "LSP" face))) (icon (doom-modeline-lsp-icon "LSP" face)))
(propertize icon (propertize icon
'face `(:inherit ,(get-text-property 0 'face icon))
'help-echo (if workspaces 'help-echo (if workspaces
(concat "LSP Connected " (concat "LSP Connected "
(string-join (--map (format "[%s]\n" (lsp--workspace-print it)) (string-join (--map (format "[%s]\n" (lsp--workspace-print it))
@ -1679,7 +1660,6 @@ mouse-1: Reload to start server")
(t 'mode-line))) (t 'mode-line)))
(icon (doom-modeline-lsp-icon "EGLOT" face))) (icon (doom-modeline-lsp-icon "EGLOT" face)))
(propertize icon (propertize icon
'face `(:inherit ,(get-text-property 0 'face icon))
'help-echo (cond 'help-echo (cond
(last-error (last-error
(format "EGLOT\nAn error occured: %s (format "EGLOT\nAn error occured: %s
@ -1719,22 +1699,20 @@ mouse-3: Reconnect to server" nick (eglot--major-mode server)))
(doom-modeline-def-segment lsp (doom-modeline-def-segment lsp
"The LSP server state." "The LSP server state."
(when doom-modeline-lsp (when doom-modeline-lsp
(when-let ((active (doom-modeline--active)) (let ((active (doom-modeline--active))
(icon (cond ((bound-and-true-p lsp-mode) (icon (cond ((bound-and-true-p lsp-mode)
doom-modeline--lsp) doom-modeline--lsp)
((bound-and-true-p eglot--managed-mode) ((bound-and-true-p eglot--managed-mode)
doom-modeline--eglot)))) doom-modeline--eglot))))
(concat (concat
(doom-modeline-whitespace) (doom-modeline-whitespace)
(propertize icon 'face (if active (when icon
`(:inherit (if active
mode-line icon
(propertize icon 'face `(:inherit
,(get-text-property 0 'face icon)
:inherit :inherit
,(get-text-property 0 'face icon)) mode-line-inactive))))
`(:inherit
,(get-text-property 0 'face icon)
:inherit
mode-line-inactive)))
(doom-modeline-whitespace))))) (doom-modeline-whitespace)))))
(defun doom-modeline-override-eglot-modeline () (defun doom-modeline-override-eglot-modeline ()
@ -2116,9 +2094,9 @@ we don't want to remove that so we just return the original."
:inherit ,face) :inherit ,face)
'help-echo help-echo) 'help-echo help-echo)
(if doom-modeline-icon (doom-modeline-vspc)) (if doom-modeline-icon (doom-modeline-vspc))
(propertize percent-str (propertize percent-str
'face face 'face face
'help-echo help-echo)) 'help-echo help-echo))
;; Battery status is not available ;; Battery status is not available
(if doom-modeline-icon (if doom-modeline-icon
(doom-modeline-icon-faicon "battery-empty" :v-adjust -0.0575 :face 'error) (doom-modeline-icon-faicon "battery-empty" :v-adjust -0.0575 :face 'error)
@ -2159,14 +2137,15 @@ we don't want to remove that so we just return the original."
(when (and doom-modeline-icon doom-modeline-major-mode-icon) (when (and doom-modeline-icon doom-modeline-major-mode-icon)
(concat (doom-modeline-whitespace) (concat (doom-modeline-whitespace)
(let ((icon (doom-modeline-icon-for-mode 'paradox-menu-mode :v-adjust -0.15))) (let ((icon (doom-modeline-icon-for-mode 'paradox-menu-mode :v-adjust -0.15)))
(propertize icon 'face `(:inherit (if active
,(let ((props (get-text-property 0 'face icon))) icon
(if doom-modeline-major-mode-color-icon (propertize icon 'face `(:inherit
props ,(let ((props (get-text-property 0 'face icon)))
(remove :inherit props))) (if doom-modeline-major-mode-color-icon
:inherit props
,(if active 'mode-line 'mode-line-inactive)))))) (remove :inherit props)))
:inherit
mode-line-inactive))))))
(let ((info (format-mode-line 'mode-line-buffer-identification))) (let ((info (format-mode-line 'mode-line-buffer-identification)))
(if active (if active
info info

View file

@ -90,7 +90,7 @@
'(objed-state misc-info persp-name fancy-battery irc mu4e github debug lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs checker)) '(objed-state misc-info persp-name fancy-battery irc mu4e github debug lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs checker))
(doom-modeline-def-modeline 'minimal (doom-modeline-def-modeline 'minimal
'(bar matches " " buffer-info) '(bar matches buffer-info)
'(media-info major-mode)) '(media-info major-mode))
(doom-modeline-def-modeline 'special (doom-modeline-def-modeline 'special
@ -98,12 +98,12 @@
'(objed-state misc-info fancy-battery irc-buffers debug lsp minor-modes input-method indent-info buffer-encoding major-mode process checker)) '(objed-state misc-info fancy-battery irc-buffers debug lsp minor-modes input-method indent-info buffer-encoding major-mode process checker))
(doom-modeline-def-modeline 'project (doom-modeline-def-modeline 'project
'(bar window-number " " buffer-default-directory) '(bar window-number buffer-default-directory)
'(misc-info fancy-battery mu4e github debug " " major-mode process)) '(misc-info fancy-battery mu4e github debug major-mode process))
(doom-modeline-def-modeline 'package (doom-modeline-def-modeline 'package
'(bar window-number package) '(bar window-number package)
'(misc-info " " major-mode process)) '(misc-info major-mode process))
(doom-modeline-def-modeline 'info (doom-modeline-def-modeline 'info
'(bar window-number buffer-info info-nodes buffer-position parrot selection-info) '(bar window-number buffer-info info-nodes buffer-position parrot selection-info)
@ -115,7 +115,7 @@
(doom-modeline-def-modeline 'pdf (doom-modeline-def-modeline 'pdf
'(bar window-number buffer-size buffer-info pdf-pages) '(bar window-number buffer-size buffer-info pdf-pages)
'(misc-info " " major-mode process vcs)) '(misc-info major-mode process vcs))
(doom-modeline-def-modeline 'helm (doom-modeline-def-modeline 'helm
'(bar helm-buffer-id helm-number helm-follow helm-prefix-argument) '(bar helm-buffer-id helm-number helm-follow helm-prefix-argument)