Rewrite mode-line (again)

This commit is contained in:
Henrik Lissner 2016-10-04 22:53:25 +02:00
parent 3de7fb54df
commit 09c805b84e

View file

@ -1,99 +1,107 @@
;;; core-modeline.el ;;; core-modeline.el
;; This file tries to be an almost self-contained configuration of my mode-line. ;; This file tries to be an almost self-contained configuration of my mode-line.
(require 'powerline)
;;; These are the invisible dependencies
;; Required
;;(require 'f)
;;(require 's)
;;(require 'evil)
;;(require 'projectile)
;;(require 'all-the-icons)
;; Optional
;;(require 'flycheck)
;;(require 'anzu)
;;(require 'evil-anzu)
;;(require 'iedit)
;;(require 'evil-multiedit)
;; ;;
;; It depends on the following external packages: ;; Variables
;; + REQUIRED
;; + f
;; + s
;; + powerline
;; + projectile
;; + OPTIONAL
;; + evil-mode
;; + anzu + evil-anzu
;; + iedit and evil-multiedit
;; + flycheck
;; ;;
;; Both are simple, isolated functions and, besides projectile, have no other
;; dependencies.
(defvar doom-modeline-height 29 (defconst doom-modeline-height 29
"How tall the mode-line should be. This is only respected in GUI emacs.") "How tall the mode-line should be (only respected in GUI emacs).")
(defvar doom-modeline-bar-width 3 (defconst doom-modeline-bar-width 3
"How wide the mode-line bar should be. This is only respected in GUI emacs.") "How wide the mode-line bar should be (only respected in GUI emacs).")
;;
;; Custom faces ;; Custom faces
;;
(defface doom-modeline-buffer-path '((t (:inherit mode-line :bold t)))
"Face used for the dirname part of the buffer path.")
(defface doom-modeline-buffer-name '((t (:inherit mode-line :bold t)))
"Face used for the filename part of the mode-line buffer path.")
(defface doom-modeline-buffer-project
'((t (:inherit doom-modeline-buffer-path :bold nil)))
"Face used for the filename part of the mode-line buffer path.")
(defface doom-modeline-buffer-modified '((t (:inherit highlight)))
"Face used for the 'unsaved' symbol in the mode-line.")
(defface doom-modeline-major-mode '((t (:inherit mode-line :bold t)))
"Face used for the major-mode segment in the mode-line.")
(defface doom-modeline-alternate '((t (:inherit mode-line))) (defface doom-modeline-alternate '((t (:inherit mode-line)))
"Secondary color for the modeline.") "Secondary color for the modeline.")
(defface doom-modeline-highlight '((t (:inherit mode-line))) (defface doom-modeline-highlight '((t (:inherit mode-line)))
"Face for bright segments of the mode-line.") "Face for bright segments of the mode-line.")
(defface doom-modeline-count '((t (:inherit mode-line))) (defface doom-modeline-panel '((t (:inherit mode-line)))
"Face for 'X out of Y' segments, such as `*anzu', `*evil-substitute' and "Face for 'X out of Y' segments, such as `*anzu', `*evil-substitute' and
`iedit'") `iedit'")
(defface doom-modeline-bar '((t (:inherit doom-modeline-highlight))) (defface doom-modeline-info `((t (:inherit success)))
"Face for info-level messages in the modeline. Used by `*vc'.")
(defface doom-modeline-warning `((t (:inherit warning)))
"Face for warnings in the modeline. Used by `*flycheck'")
(defface doom-modeline-urgent `((t (:inherit error)))
"Face for errors in the modeline. Used by `*flycheck'")
;; Bar
(defface doom-modeline-bar '((t (:inherit highlight :foreground nil)))
"The face used for the left-most bar on the mode-line of an active window.") "The face used for the left-most bar on the mode-line of an active window.")
(defface doom-modeline-eldoc-bar '((t (:inherit doom-modeline-bar))) (defface doom-modeline-eldoc-bar '((t (:inherit shadow :foreground nil)))
"The face used for the left-most bar on the mode-line when eldoc-eval is "The face used for the left-most bar on the mode-line when eldoc-eval is
active.") active.")
(defface doom-modeline-inactive-bar '((t (:inherit mode-line-inactive))) (defface doom-modeline-inactive-bar '((t (:inherit mode-line-inactive)))
"The face used for the left-most bar on the mode-line of an inactive window.") "The face used for the left-most bar on the mode-line of an inactive window.")
(defface doom-modeline-count '((t (:inherit mode-line)))
"Face for anzu/evil-substitute/evil-search number-of-matches display.")
(defface doom-modeline-info '((t (:inherit success)))
"Face for info-level messages in the modeline. Used by `*vc'.")
(defface doom-modeline-warning '((t (:inherit warning)))
"Face for warnings in the modeline. Used by `*flycheck'")
(defface doom-modeline-urgent '((t (:inherit error)))
"Face for errors in the modeline. Used by `*flycheck'")
;;
;; Dependencies
;;
(require 'powerline)
(require 'all-the-icons)
(use-package eldoc-eval
:config
(setq eldoc-in-minibuffer-show-fn 'doom-eldoc-show-in-mode-line)
(eldoc-in-minibuffer-mode +1))
;; ;;
;; Functions ;; Functions
;; ;;
(defun doom-ml-flycheck-count (state) ;; Where (py|rb)env version strings will be stored
"Return flycheck information for the given error type STATE." (defvar-local doom-ml--env-version nil)
(when (flycheck-has-current-errors-p state) (defvar-local doom-ml--env-command nil)
(if (eq 'running flycheck-last-status-change)
"?"
(cdr-safe (assq state (flycheck-count-errors flycheck-current-errors))))))
;; pyenv/rbenv version segment (add-hook 'focus-in-hook 'doom-ml|env-update)
(defvar doom-ml-env-version-hook '() (add-hook 'find-file-hook 'doom-ml|env-update)
"Hook that runs whenever the environment version changes (e.g. rbenv/pyenv)")
(defun doom-ml|env-update () (defun doom-ml|env-update ()
"Update (py|rb)env version string in `doom-ml--env-version', generated with "Update (py|rb)env version string in `doom-ml--env-version', generated with
`doom-ml--env-command'." `doom-ml--env-command'."
(when doom-ml--env-command (when doom-ml--env-command
(let ((default-directory (projectile-project-root))) (let* ((default-directory (projectile-project-root))
(let ((s (shell-command-to-string doom-ml--env-command))) (s (shell-command-to-string doom-ml--env-command)))
(setq doom-ml--env-version (if (string-match "[ \t\n\r]+\\'" s) (setq doom-ml--env-version (if (string-match "[ \t\n\r]+\\'" s)
(replace-match "" t t s) (replace-match "" t t s)
s)) s)))))
(run-hook-with-args 'doom-ml-env-version-hook doom-ml--env-version)))))
(defmacro def-version-cmd! (mode command) (defmacro def-version-cmd! (mode command)
"Define a COMMAND for MODE that will set `doom-ml--env-command' when that mode "Define a COMMAND for MODE that will set `doom-ml--env-command' when that mode
@ -105,54 +113,33 @@ For instance:
This will display the ruby version in the modeline in ruby-mode buffers. It is This will display the ruby version in the modeline in ruby-mode buffers. It is
cached the first time." cached the first time."
(add-hook 'focus-in-hook 'doom-ml|env-update)
(add-hook 'find-file-hook 'doom-ml|env-update)
`(add-hook ',mode (lambda () (setq doom-ml--env-command ,command)))) `(add-hook ',mode (lambda () (setq doom-ml--env-command ,command))))
(defun doom-ml-flycheck-count (state)
"Return flycheck information for the given error type STATE."
(when (flycheck-has-current-errors-p state)
(if (eq 'running flycheck-last-status-change)
"?"
(cdr-safe (assq state (flycheck-count-errors flycheck-current-errors))))))
(defun doom-make-xpm (color height width) (defun doom-make-xpm (color height width)
"Create an XPM bitmap." "Create an XPM bitmap."
(let ((data nil) (propertize
(i 0)) " " 'display
(setq data (make-list height (make-list width 1))) (let ((data nil)
(pl/make-xpm "percent" color color (reverse data)))) (i 0))
(setq data (make-list height (make-list width 1)))
(pl/make-xpm "percent" color color (reverse data)))))
(pl/memoize 'doom-make-xpm) (pl/memoize 'doom-make-xpm)
(defun doom-buffer-path ()
;;
;; Initialization
;;
;; Where (py|rb)env version strings will be stored
(defvar-local doom-ml--env-version nil)
(defvar-local doom-ml--env-command nil)
;; So the mode-line can keep track of "the current window"
(defvar doom-ml-selected-window nil)
(defun doom|set-selected-window (&rest _)
(let ((window (frame-selected-window)))
(when (and (windowp window)
(not (minibuffer-window-active-p window)))
(setq doom-ml-selected-window window))))
(add-hook 'window-configuration-change-hook #'doom|set-selected-window)
(add-hook 'focus-in-hook #'doom|set-selected-window)
(advice-add 'select-window :after 'doom|set-selected-window)
(advice-add 'select-frame :after 'doom|set-selected-window)
;;
;; Mode-line segments
;;
(defun *buffer-path ()
"Displays the buffer's full path relative to the project root (includes the "Displays the buffer's full path relative to the project root (includes the
project root). Excludes the file basename. See `*buffer-name' for that." project root). Excludes the file basename. See `doom-buffer-name' for that."
(when buffer-file-name (when buffer-file-name
(f-dirname (let ((buffer-path (f-relative (f-dirname buffer-file-name) (doom/project-root)))
(let ((buffer-path (file-relative-name buffer-file-name (projectile-project-root))) (max-length (truncate (/ (window-body-width) 1.75))))
(max-length (truncate (/ (window-body-width) 1.75)))) (when (and buffer-path (not (equal buffer-path ".")))
(concat (projectile-project-name) "/" (concat (if (> (length buffer-path) max-length)
(if (> (length buffer-path) max-length)
(let ((path (reverse (split-string buffer-path "/" t))) (let ((path (reverse (split-string buffer-path "/" t)))
(output "")) (output ""))
(when (and path (equal "" (car path))) (when (and path (equal "" (car path)))
@ -165,96 +152,131 @@ project root). Excludes the file basename. See `*buffer-name' for that."
(when (string-suffix-p "/" output) (when (string-suffix-p "/" output)
(setq output (substring output 0 -1))) (setq output (substring output 0 -1)))
output) output)
buffer-path)))))) buffer-path)
"/")))))
(defun *buffer-name ()
"The buffer's base name or id." ;;
(if buffer-file-name ;; Mode-line segments
(f-filename buffer-file-name) ;;
(s-trim-left (format-mode-line "%b"))))
(defconst &bar-active
(eval-when-compile
(doom-make-xpm (face-background 'doom-modeline-bar)
doom-modeline-height
doom-modeline-bar-width)))
(defconst &bar-inactive
(eval-when-compile
(doom-make-xpm (face-background 'doom-modeline-inactive-bar)
doom-modeline-height
doom-modeline-bar-width)))
(defun *buffer-project () (defun *buffer-project ()
"Displays `default-directory', for special buffers like the scratch buffer." "Displays `default-directory', for special buffers like the scratch buffer."
(concat (concat (all-the-icons-octicon
" " "file-directory"
(all-the-icons-octicon :face (if active 'doom-modeline-buffer-project) :v-adjust -0.05 :height 1.25)
"file-directory" (propertize (concat " " (abbreviate-file-name (doom/project-root)))
:face 'doom-modeline-alternate :v-adjust -0.05 :height 1.3) 'face (if active 'doom-modeline-buffer-project))))
(propertize (concat " " (abbreviate-file-name default-directory))
'face `(:inherit doom-modeline-alternate))))
(defun *buffer-state ()
"Displays symbols representing the buffer's state; which can be one or more
of: non-existent, modified or read-only."
(let ((state (list))
(base-face (if active 'doom-default 'mode-line-inactive)))
(when buffer-file-name
(if (file-exists-p buffer-file-name)
(when (buffer-modified-p)
(push (all-the-icons-octicon "primitive-dot" :face `(minibuffer-prompt ,base-face) :height 1.1 :v-adjust -0.05) state))
(push (all-the-icons-octicon "circle-slash" :face `(doom-modeline-urgent ,base-face) :height 1.1 :v-adjust -0.05) state)))
(when buffer-read-only
(push (all-the-icons-octicon "lock" :face `(doom-modeline-urgent ,base-face) :height 1.1 :v-adjust -0.05) state))
(when state
(concat (s-join (propertize " " 'face base-face) state)))))
(defun *buffer-info () (defun *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 ((face (if active 'doom-default 'mode-line-inactive))) (let ((all-the-icons-scale-factor 1.2)
(concat (propertize " " 'face face) (modified-p (buffer-modified-p)))
(propertize (or (*buffer-path) "") 'face `(:inherit (,face doom-modeline-alternate))) (concat (if buffer-read-only
(propertize (or (*buffer-name) "") 'face face) (concat (all-the-icons-octicon
(propertize " " 'face face) "lock"
(let ((state (*buffer-state))) :face 'doom-modeline-warning
(if state (concat state (propertize " " 'face face))))))) :v-adjust -0.05)
" ")
(when modified-p
(concat
(all-the-icons-faicon "floppy-o"
:face 'doom-modeline-buffer-modified
:v-adjust -0.1)
" ")))
(when (and buffer-file-name (not (file-exists-p buffer-file-name)))
(concat (all-the-icons-octicon
"circle-slash"
:face 'doom-modeline-urgent
:v-adjust -0.05)
" "))
(defun *buffer-encoding-abbrev () (if modified-p
"The line ending convention used in the buffer (if it isn't unix) and its (propertize (concat (doom-buffer-path)
character encoding (if it isn't UTF-8)." "%b")
(let ((sys (symbol-name buffer-file-coding-system))) 'face 'doom-modeline-buffer-modified)
(concat (cond ((string-suffix-p "-mac" sys) (concat
"MAC ") (propertize (or (doom-buffer-path) "")
((string-suffix-p "-dos" sys) 'face (if active 'doom-modeline-buffer-path))
"DOS ") (propertize "%b"
(t "")) 'face (if active 'doom-modeline-buffer-name))))
(if (string-match-p "u\\(tf-8\\|ndecided\\)" sys) " %l:%c %p ")))
""
(concat (s-chop-suffixes '("-unix" "-dos" "-mac") sys) " "))))) (defun *buffer-encoding ()
"The encoding and eol style of the buffer."
(concat (let ((eol-type (coding-system-eol-type buffer-file-coding-system)))
(cond ((eq eol-type 0) "LF ")
((eq eol-type 1) "CRLF ")
((eq eol-type 2) "CR ")))
(upcase
(symbol-name (plist-get (coding-system-plist buffer-file-coding-system)
:name)))
" "))
(defun *major-mode () (defun *major-mode ()
"The major mode, including process, environment and text-scale info." "The major mode, including process, environment and text-scale info."
(propertize (propertize
(concat " " (concat (format-mode-line mode-name)
(format-mode-line mode-name)
(if (stringp mode-line-process) mode-line-process) (if (stringp mode-line-process) mode-line-process)
(if doom-ml--env-version (concat " " doom-ml--env-version)) (if doom-ml--env-version (concat " " doom-ml--env-version))
(and (featurep 'face-remap) (and (featurep 'face-remap)
(/= text-scale-mode-amount 0) (/= text-scale-mode-amount 0)
(format " (%+d)" text-scale-mode-amount)) (format " (%+d)" text-scale-mode-amount)))
" ") 'face (if active 'doom-modeline-major-mode)))
'face (if active 'mode-line 'mode-line-inactive)))
(defun *vc () (defun *vc ()
"Displays the current branch, colored based on its state." "Displays the current branch, colored based on its state."
(when vc-mode (when vc-mode
(let ((backend (substring vc-mode (+ 2 (length (symbol-name (vc-backend buffer-file-name)))))) (let ((backend vc-mode)
(face (let ((state (vc-state buffer-file-name))) (state (vc-state buffer-file-name))
(cond ((memq state '(edited added)) (face 'mode-line-inactive)
'doom-modeline-info) (all-the-icons-scale-factor 1.2)
((memq state '(removed needs-merge needs-update conflict unregistered)) (all-the-icons-default-adjust -0.1))
'doom-modeline-urgent) (concat (propertize " " 'face 'variable-pitch)
(t 'doom-modeline-warning))))) (cond ((memq state '(edited added))
(concat (if active (setq face 'doom-modeline-info))
" " (all-the-icons-octicon
(propertize (all-the-icons-octicon "git-branch") "git-branch"
'face `(:inherit ,(if active face 'mode-line-inactive) :face face
:family ,(all-the-icons-octicon-family) :v-adjust -0.05))
:height 1.25) ((eq state 'needs-merge)
'display '(raise -0.1)) (if active (setq face 'doom-modeline-info))
" " (all-the-icons-octicon
(propertize backend 'face (if active face 'mode-line-inactive)) "git-merge"
" ")))) :face face
:height 1.0))
((eq state 'needs-update)
(if active (setq face 'doom-modeline-warning))
(all-the-icons-octicon
"arrow-down"
:face face
:height 1.0))
((memq state '(removed conflict unregistered))
(if active (setq face 'doom-modeline-urgent))
(all-the-icons-octicon
"alert"
:face face
:height 1.0))
(t
(if active (setq face 'mode-line))
(all-the-icons-octicon
"git-branch"
:face face)))
(propertize backend 'face (if active face))
" "))))
(defvar-local doom--flycheck-err-cache nil "") (defvar-local doom--flycheck-err-cache nil "")
(defvar-local doom--flycheck-cache nil "") (defvar-local doom--flycheck-cache nil "")
@ -265,67 +287,83 @@ character encoding (if it isn't UTF-8)."
(eq 'running flycheck-last-status-change)) (eq 'running flycheck-last-status-change))
(or (and (or (eq doom--flycheck-err-cache doom--flycheck-cache) (or (and (or (eq doom--flycheck-err-cache doom--flycheck-cache)
(memq flycheck-last-status-change '(running not-checked))) (memq flycheck-last-status-change '(running not-checked)))
doom--flycheck-cache) (if (eq flycheck-last-status-change 'running)
(all-the-icons-octicon
"ellipsis"
:face 'doom-modeline-warning
:height 1.05
:v-adjust 0)
doom--flycheck-cache))
(and (setq doom--flycheck-err-cache flycheck-current-errors) (and (setq doom--flycheck-err-cache flycheck-current-errors)
(setq doom--flycheck-cache (setq doom--flycheck-cache
(let ((fw (doom-ml-flycheck-count 'warning)) (let ((fw (doom-ml-flycheck-count 'warning))
(fe (doom-ml-flycheck-count 'error))) (fe (doom-ml-flycheck-count 'error)))
(concat (if fe (concat (concat (if fe (concat
(all-the-icons-octicon "x" :face 'doom-modeline-urgent :height 1.2 :v-adjust -0.06) (all-the-icons-octicon "x" :face 'doom-modeline-urgent :height 1.2 :v-adjust -0.06)
(propertize (format " %d " fe) 'face 'doom-modeline-urgent))) (propertize (format " %d " fe) 'face 'doom-modeline-urgent)
" "))
(if fw (concat (if fw (concat
(all-the-icons-octicon "x" :face 'doom-modeline-warning :height 1.2 :v-adjust -0.06) (all-the-icons-octicon "circle-slash" :face 'doom-modeline-warning :height 1.0 :v-adjust -0.01)
(propertize (format " %d " fw) 'face 'doom-modeline-warning))) (propertize (format " %d " fw) 'face 'doom-modeline-warning)
" "))
(unless (or fe fw) (unless (or fe fw)
(when active (when active
(all-the-icons-octicon "check" :face 'doom-modeline-info :height 1.2 :v-adjust -0.06))) (all-the-icons-octicon "check" :height 1.2 :v-adjust -0.06))))))))
" ")))))
(concat (concat
(all-the-icons-octicon "check" :face 'doom-modeline-info :height 1.2 :v-adjust -0.06) (all-the-icons-octicon "check"
" ")))) :face (if active 'doom-modeline-info)
:height 1.2
:v-adjust -0.06)))))
(defun *selection-info () (defun *selection-info ()
"Information about the current selection, such as how many characters and "Information about the current selection, such as how many characters and
lines are selected, or the NxM dimensions of a block selection." lines are selected, or the NxM dimensions of a block selection."
(when (and active (evil-visual-state-p)) (when (and active (evil-visual-state-p))
(propertize (concat
(let ((reg-beg (region-beginning)) " "
(reg-end (region-end)) (propertize
(evil (eq 'visual evil-state))) (let ((reg-beg (region-beginning))
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max)))) (reg-end (region-end))
(chars (- (1+ reg-end) reg-beg)) (evil (eq 'visual evil-state)))
(cols (1+ (abs (- (evil-column reg-end) (let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))
(evil-column reg-beg)))))) (chars (- (1+ reg-end) reg-beg))
(cond (cols (1+ (abs (- (evil-column reg-end)
;; rectangle selection (evil-column reg-beg))))))
((or (bound-and-true-p rectangle-mark-mode) (cond
(and evil (eq 'block evil-visual-selection))) ;; rectangle selection
(format " %dx%dB " lines (if evil cols (1- cols)))) ((or (bound-and-true-p rectangle-mark-mode)
;; line selection (and evil (eq 'block evil-visual-selection)))
((or (> lines 1) (eq 'line evil-visual-selection)) (format " %dx%dB " lines (if evil cols (1- cols))))
(if (and (eq evil-state 'visual) (eq evil-this-type 'line)) ;; line selection
(format " %dL " lines) ((or (> lines 1) (eq 'line evil-visual-selection))
(format " %dC %dL " chars lines))) (if (and (eq evil-state 'visual) (eq evil-this-type 'line))
(t (format " %dC " (if evil chars (1- chars))))))) (format " %dL " lines)
'face 'doom-modeline-highlight))) (format " %dC %dL " chars lines)))
(t (format " %dC " (if evil chars (1- chars)))))))
'face 'doom-modeline-highlight))))
(defun *macro-recording () (defun *macro-recording ()
"Display current macro being recorded." "Display current macro being recorded."
(when (and active defining-kbd-macro) (when (and active defining-kbd-macro)
(propertize (let ((sep (propertize " " 'face 'doom-modeline-panel)))
(format " %s • " (char-to-string evil-this-macro)) (concat sep
'face 'doom-modeline-highlight))) (propertize (char-to-string evil-this-macro)
'face 'doom-modeline-panel)
sep
(all-the-icons-octicon "triangle-right"
:face 'doom-modeline-panel
:v-adjust -0.05)
sep))))
(make-variable-buffer-local 'anzu--state) (make-variable-buffer-local 'anzu--state)
(defun *anzu () (defun *anzu ()
"Show the current match number and the total number of matches. Requires anzu "Show the match index and total number thereof. Requires `evil-anzu'."
to be enabled."
(when (and (featurep 'evil-anzu) (evil-ex-hl-active-p 'evil-ex-search)) (when (and (featurep 'evil-anzu) (evil-ex-hl-active-p 'evil-ex-search))
(propertize (propertize
(format " %s/%d%s " (format " %s/%d%s "
anzu--current-position anzu--total-matched anzu--current-position anzu--total-matched
(if anzu--overflow-p "+" "")) (if anzu--overflow-p "+" ""))
'face (if active 'doom-modeline-count 'mode-line-inactive)))) 'face (if active 'doom-modeline-panel))))
(defun *evil-substitute () (defun *evil-substitute ()
"Show number of :s matches in real time." "Show number of :s matches in real time."
@ -340,7 +378,7 @@ to be enabled."
(count-matches pattern (car range) (cdr range)) (count-matches pattern (car range) (cdr range))
evil-ex-argument) evil-ex-argument)
" ... ")) " ... "))
'face (if active 'doom-modeline-count 'mode-line-inactive)))) 'face (if active 'doom-modeline-panel))))
(defun *iedit () (defun *iedit ()
"Show the number of iedit regions matches + what match you're on." "Show the number of iedit regions matches + what match you're on."
@ -359,59 +397,35 @@ to be enabled."
(- length (-elem-index this-oc iedit-occurrences-overlays)) (- length (-elem-index this-oc iedit-occurrences-overlays))
"-")) "-"))
length)) length))
'face (if active 'doom-modeline-count 'mode-line-inactive)))) 'face (if active 'doom-modeline-panel 'mode-line-inactive))))
(defun *buffer-position ()
"A more vim-like buffer position."
(let ((start (window-start))
(end (window-end))
(pend (point-max)))
(propertize
(concat
" %l:%c :"
(if (and (= start 1)
(= end pend))
"All"
(cond ((= start 1) "Top")
((= end pend) "Bot")
(t (format "%d%%%%" (/ end 0.01 pend))))))
'face (if active 'doom-modeline-alternate 'mode-line-inactive))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar doom-modeline-bar-active (face-background 'doom-modeline-bar)
"The color to use for the bar in active window mode-lines.")
(defvar doom-modeline-bar-inactive (face-background 'mode-line-inactive)
"The color to use for the bar in inactive window mode-lines.")
(defun doom-modeline (&optional id) (defun doom-modeline (&optional id)
`(:eval `(:eval
(let* ((active (eq (selected-window) doom-ml-selected-window)) (let* ((active (eq (selected-window) powerline-selected-window))
(lhs (list (propertize (lhs (list ,(if window-system '(if active &bar-active &bar-inactive))
" " 'display (doom-make-xpm (if active ,(unless (eq id 'scratch)
doom-modeline-bar-active '(let ((side (concat (*macro-recording)
doom-modeline-bar-inactive) (*anzu)
doom-modeline-height (*evil-substitute)
doom-modeline-bar-width)) (*iedit))))
(*macro-recording) (if (= (length side) 0)
(*selection-info) " %I "
(*anzu) side)))
(*evil-substitute) " "
(*iedit)
,(if (eq id 'scratch) ,(if (eq id 'scratch)
'(*buffer-project) '(*buffer-project)
'(*buffer-info)) '(*buffer-info))
" " (*selection-info)
(*flycheck))) (*flycheck)))
(rhs (list (*buffer-encoding-abbrev) (rhs (list (*buffer-encoding)
(*vc) (*vc)
(*major-mode) (*major-mode)))
(*buffer-position))) (mid (propertize
(middle (propertize " " 'display `((space :align-to (- (+ right right-fringe right-margin)
" " 'display `((space :align-to (- (+ right right-fringe right-margin) ,(+ 1 (string-width (format-mode-line rhs)))))))))
,(1+ (string-width (format-mode-line rhs))))))))) (list lhs mid rhs))))
(list lhs middle rhs))))
(setq-default mode-line-format (doom-modeline)) (setq-default mode-line-format (doom-modeline))
@ -420,15 +434,10 @@ to be enabled."
;; Eldoc-in-mode-line support (for `eval-expression') ;; Eldoc-in-mode-line support (for `eval-expression')
;; ;;
(defvar doom-modeline-eldoc-bar-color (face-background 'doom-modeline-eldoc-bar)
"The color to use for the bar when eldoc uses the mode-line.")
(defun doom-eldoc-modeline () (defun doom-eldoc-modeline ()
`(:eval `(:eval
(let ((active (eq (selected-window) doom-ml-selected-window))) (let ((active (eq (selected-window) doom-ml-selected-window)))
(list (list (propertize " " 'display (doom-make-xpm doom-modeline-eldoc-bar-color (list (list
doom-modeline-height
doom-modeline-bar-width))
(and (bound-and-true-p str) str)) (and (bound-and-true-p str) str))
(propertize " " 'display `((space :align-to (1- (+ right right-fringe right-margin))))))))) (propertize " " 'display `((space :align-to (1- (+ right right-fringe right-margin)))))))))
@ -458,5 +467,11 @@ to be enabled."
(sit-for eldoc-show-in-mode-line-delay)))) (sit-for eldoc-show-in-mode-line-delay))))
(force-mode-line-update))) (force-mode-line-update)))
;; Show eldoc in the mode-line when using `eval-expression'.
(use-package eldoc-eval
:config
(setq eldoc-in-minibuffer-show-fn 'doom-eldoc-show-in-mode-line)
(eldoc-in-minibuffer-mode +1))
(provide 'core-modeline) (provide 'core-modeline)
;;; core-modeline.el ends here ;;; core-modeline.el ends here