mirror of
https://github.com/vale981/doom-modeline
synced 2025-03-05 09:21:38 -05:00
[Feature] Use built-in battery instead of unmaintained fancy-battery.
See 9b88ae77a0
.
This commit is contained in:
parent
22b14c9b8e
commit
93135d4220
3 changed files with 102 additions and 99 deletions
|
@ -41,9 +41,10 @@ The `doom-modeline` was designed for minimalism, and offers:
|
||||||
- A window number segment for `ace-window`, `winum` and `window-numbering`
|
- A window number segment for `ace-window`, `winum` and `window-numbering`
|
||||||
- An indicator for modal editing state, including `evil`, `overwrite`, `god`, `ryo` and
|
- An indicator for modal editing state, including `evil`, `overwrite`, `god`, `ryo` and
|
||||||
`xah-fly-keys`, etc.
|
`xah-fly-keys`, etc.
|
||||||
- An indicator for remote host
|
- An indicator for battery status
|
||||||
- An indicator for debug state
|
|
||||||
- An indicator for current input method
|
- An indicator for current input method
|
||||||
|
- An indicator for debug state
|
||||||
|
- An indicator for remote host
|
||||||
- An indicator for LSP state with `lsp-mode` or `eglot`
|
- An indicator for LSP state with `lsp-mode` or `eglot`
|
||||||
- An indicator for GitHub notifications
|
- An indicator for GitHub notifications
|
||||||
- An indicator for unread emails with `mu4e-alert`
|
- An indicator for unread emails with `mu4e-alert`
|
||||||
|
@ -52,7 +53,6 @@ The `doom-modeline` was designed for minimalism, and offers:
|
||||||
- An indicator for party parrot
|
- An indicator for party parrot
|
||||||
- An indicator for PDF page number with `pdf-tools`
|
- An indicator for PDF page number with `pdf-tools`
|
||||||
- An indicator for markdown/org preview with `grip`
|
- An indicator for markdown/org preview with `grip`
|
||||||
- An indicator for battery status with `fancy-battery`
|
|
||||||
- Truncated file name, file icon, buffer state and project name in buffer information segment, which
|
- Truncated file name, file icon, buffer state and project name in buffer information segment, which
|
||||||
is compatible with `project`, `find-file-in-project` and `projectile`.
|
is compatible with `project`, `find-file-in-project` and `projectile`.
|
||||||
- New mode-line for `Info-mode` buffers
|
- New mode-line for `Info-mode` buffers
|
||||||
|
|
|
@ -50,6 +50,8 @@
|
||||||
(defvar anzu-cons-mode-line-p)
|
(defvar anzu-cons-mode-line-p)
|
||||||
(defvar aw-keys)
|
(defvar aw-keys)
|
||||||
(defvar battery-echo-area-format)
|
(defvar battery-echo-area-format)
|
||||||
|
(defvar battery-load-critical)
|
||||||
|
(defvar battery-status-function)
|
||||||
(defvar edebug-execution-mode)
|
(defvar edebug-execution-mode)
|
||||||
(defvar evil-ex-active-highlights-alist)
|
(defvar evil-ex-active-highlights-alist)
|
||||||
(defvar evil-ex-argument)
|
(defvar evil-ex-argument)
|
||||||
|
@ -59,7 +61,6 @@
|
||||||
(defvar evil-visual-beginning)
|
(defvar evil-visual-beginning)
|
||||||
(defvar evil-visual-end)
|
(defvar evil-visual-end)
|
||||||
(defvar evil-visual-selection)
|
(defvar evil-visual-selection)
|
||||||
(defvar fancy-battery-last-status)
|
|
||||||
(defvar flycheck-current-errors)
|
(defvar flycheck-current-errors)
|
||||||
(defvar flycheck-mode-menu-map)
|
(defvar flycheck-mode-menu-map)
|
||||||
(defvar flymake--backend-state)
|
(defvar flymake--backend-state)
|
||||||
|
@ -2052,89 +2053,84 @@ we don't want to remove that so we just return the original."
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; fancy battery
|
;; battery status
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defvar-local doom-modeline--battery-status nil)
|
(defvar-local doom-modeline--battery-status nil)
|
||||||
(defun doom-modeline-update-battery-status (&optional status)
|
(defun doom-modeline-update-battery-status ()
|
||||||
"Update battery STATUS."
|
"Update battery status."
|
||||||
(setq doom-modeline--battery-status
|
(setq doom-modeline--battery-status
|
||||||
(when-let*
|
(let* ((data (and (bound-and-true-p battery-status-function)
|
||||||
((status (or status (bound-and-true-p fancy-battery-last-status)))
|
(funcall battery-status-function)))
|
||||||
(charging? (string-equal "AC" (cdr (assoc ?L status))))
|
(charging? (string-equal "AC" (cdr (assoc ?L data))))
|
||||||
(percentage (cdr (assq ?p status)))
|
(percentage (car (read-from-string (cdr (assq ?p data)))))
|
||||||
(percentage-number (string-to-number percentage))
|
(face (when (numberp percentage)
|
||||||
(face (cond
|
(cond (charging? 'success)
|
||||||
(charging? 'fancy-battery-charging)
|
((< percentage battery-load-critical) 'error)
|
||||||
((< percentage-number 10) 'fancy-battery-critical)
|
((< percentage 25) 'warning)
|
||||||
((< percentage-number 25) 'fancy-battery-discharging)
|
((< percentage 95) 'mode-line)
|
||||||
((< percentage-number 95) 'mode-line)
|
(t 'success))))
|
||||||
(t 'fancy-battery-charging)))
|
(icon (if (numberp percentage)
|
||||||
(icon (cond
|
(cond (charging?
|
||||||
(charging?
|
(doom-modeline-icon 'alltheicon
|
||||||
(doom-modeline-icon 'alltheicon
|
"battery-charging"
|
||||||
"battery-charging"
|
"🔋"
|
||||||
"🔋"
|
"+"
|
||||||
"+"
|
face
|
||||||
face
|
:height 1.4
|
||||||
:height 1.4
|
:v-adjust -0.1))
|
||||||
:v-adjust -0.1))
|
((> percentage 95)
|
||||||
((> percentage-number 95)
|
(doom-modeline-icon 'faicon
|
||||||
(doom-modeline-icon 'faicon
|
"battery-full"
|
||||||
"battery-full"
|
"🔋"
|
||||||
"🔋"
|
"-"
|
||||||
"-"
|
face
|
||||||
face
|
:v-adjust -0.0575))
|
||||||
:v-adjust -0.0575))
|
((> percentage 70)
|
||||||
((> percentage-number 70)
|
(doom-modeline-icon 'faicon
|
||||||
(doom-modeline-icon 'faicon
|
"battery-three-quarters"
|
||||||
"battery-three-quarters"
|
"🔋"
|
||||||
"🔋"
|
"-"
|
||||||
"-"
|
face
|
||||||
face
|
:v-adjust -0.0575))
|
||||||
:v-adjust -0.0575))
|
((> percentage 40)
|
||||||
((> percentage-number 40)
|
(doom-modeline-icon 'faicon
|
||||||
(doom-modeline-icon 'faicon
|
"battery-half"
|
||||||
"battery-half"
|
"🔋"
|
||||||
"🔋"
|
"-"
|
||||||
"-"
|
face
|
||||||
face
|
:v-adjust -0.0575))
|
||||||
:v-adjust -0.0575))
|
((> percentage battery-load-critical)
|
||||||
((> percentage-number 15)
|
(doom-modeline-icon 'faicon
|
||||||
(doom-modeline-icon 'faicon
|
"battery-quarter"
|
||||||
"battery-quarter"
|
"🔋"
|
||||||
"🔋"
|
"-"
|
||||||
"-"
|
face
|
||||||
face
|
:v-adjust -0.0575))
|
||||||
:v-adjust -0.0575))
|
(t (doom-modeline-icon 'faicon
|
||||||
(t
|
"battery-empty"
|
||||||
(doom-modeline-icon 'faicon
|
"🔋"
|
||||||
"battery-empty"
|
"!"
|
||||||
"🔋"
|
face
|
||||||
"!"
|
:v-adjust -0.0575)))
|
||||||
face
|
(doom-modeline-icon 'faicon
|
||||||
:v-adjust -0.0575))))
|
"battery-empty"
|
||||||
(percent-str (and percentage (concat percentage "%%")))
|
"⚠"
|
||||||
(help-echo (if battery-echo-area-format
|
"N/A"
|
||||||
(battery-format battery-echo-area-format status)
|
'error
|
||||||
"Battery status not available")))
|
:v-adjust -0.0575)))
|
||||||
(concat
|
(text (if (numberp percentage)
|
||||||
(doom-modeline-spc)
|
(format "%d%%%%" percentage)
|
||||||
(if percent-str
|
""))
|
||||||
(propertize (concat icon
|
(help-echo (if (and battery-echo-area-format (numberp percentage))
|
||||||
(doom-modeline-vspc)
|
(battery-format battery-echo-area-format data)
|
||||||
(propertize percent-str 'face face))
|
"Battery status not available")))
|
||||||
'help-echo help-echo)
|
(concat (doom-modeline-spc)
|
||||||
;; Battery status is not available
|
(propertize (concat icon
|
||||||
(propertize (doom-modeline-icon 'faicon
|
(doom-modeline-vspc)
|
||||||
"battery-empty"
|
(propertize text 'face face))
|
||||||
"⚠"
|
'help-echo help-echo)
|
||||||
"N/A"
|
(doom-modeline-spc)))))
|
||||||
'error
|
|
||||||
:v-adjust -0.0575)
|
|
||||||
'help-echo "Battery status not available"))
|
|
||||||
(doom-modeline-spc)))))
|
|
||||||
(add-hook 'fancy-battery-status-update-functions #'doom-modeline-update-battery-status)
|
|
||||||
|
|
||||||
(when (>= emacs-major-version 26)
|
(when (>= emacs-major-version 26)
|
||||||
(add-variable-watcher
|
(add-variable-watcher
|
||||||
|
@ -2155,19 +2151,24 @@ we don't want to remove that so we just return the original."
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
(doom-modeline-update-battery-status)))))))
|
(doom-modeline-update-battery-status)))))))
|
||||||
|
|
||||||
(doom-modeline-def-segment fancy-battery
|
(doom-modeline-def-segment battery
|
||||||
"Display battery status."
|
"Display battery status."
|
||||||
(when (and (doom-modeline--active)
|
(when (and (doom-modeline--active)
|
||||||
(bound-and-true-p fancy-battery-mode))
|
(bound-and-true-p display-battery-mode))
|
||||||
(or doom-modeline--battery-status (doom-modeline-update-battery-status))))
|
(or doom-modeline--battery-status (doom-modeline-update-battery-status))))
|
||||||
|
|
||||||
(defun doom-modeline-override-fancy-battery-modeline ()
|
(defun doom-modeline-override-battery-modeline ()
|
||||||
"Override `fancy-battery' mode-line."
|
"Override default battery mode-line."
|
||||||
(if (bound-and-true-p doom-modeline-mode)
|
(if (bound-and-true-p doom-modeline-mode)
|
||||||
(setq global-mode-string
|
(progn
|
||||||
(delq 'fancy-battery-mode-line global-mode-string))))
|
(advice-add #'battery-update :override #'doom-modeline-update-battery-status)
|
||||||
(add-hook 'fancy-battery-mode-hook #'doom-modeline-override-fancy-battery-modeline)
|
(setq global-mode-string
|
||||||
(add-hook 'doom-modeline-mode-hook #'doom-modeline-override-fancy-battery-modeline)
|
(delq 'battery-mode-line-string global-mode-string)))
|
||||||
|
(progn
|
||||||
|
(advice-remove #'battery-update #'doom-modeline-update-battery-status)
|
||||||
|
(when display-battery-mode (display-battery-mode 1)))))
|
||||||
|
(add-hook 'display-battery-mode-hook #'doom-modeline-override-battery-modeline)
|
||||||
|
(add-hook 'doom-modeline-mode-hook #'doom-modeline-override-battery-modeline)
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -47,9 +47,10 @@
|
||||||
;; - A window number segment for winum and window-numbering
|
;; - A window number segment for winum and window-numbering
|
||||||
;; - An indicator for modal editing state, including evil, overwrite, god, ryo
|
;; - An indicator for modal editing state, including evil, overwrite, god, ryo
|
||||||
;; and xah-fly-keys, etc.
|
;; and xah-fly-keys, etc.
|
||||||
;; - An indicator for remote host
|
;; - An indicator for battery status
|
||||||
;; - An indicator for current input method
|
;; - An indicator for current input method
|
||||||
;; - An indicator for debug state
|
;; - An indicator for debug state
|
||||||
|
;; - An indicator for remote host
|
||||||
;; - An indicator for LSP state with lsp-mode or eglot
|
;; - An indicator for LSP state with lsp-mode or eglot
|
||||||
;; - An indicator for github notifications
|
;; - An indicator for github notifications
|
||||||
;; - An indicator for unread emails with mu4e-alert
|
;; - An indicator for unread emails with mu4e-alert
|
||||||
|
@ -58,7 +59,6 @@
|
||||||
;; - An indicator for party parrot
|
;; - An indicator for party parrot
|
||||||
;; - An indicator for PDF page number with pdf-tools
|
;; - An indicator for PDF page number with pdf-tools
|
||||||
;; - An indicator for markdown/org preivews with grip
|
;; - An indicator for markdown/org preivews with grip
|
||||||
;; - An indicator for battery status with fancy-battery
|
|
||||||
;; - Truncated file name, file icon, buffer state and project name in buffer
|
;; - Truncated file name, file icon, buffer state and project name in buffer
|
||||||
;; information segment, which is compatible with project, find-file-in-project
|
;; information segment, which is compatible with project, find-file-in-project
|
||||||
;; and projectile
|
;; and projectile
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
|
|
||||||
(doom-modeline-def-modeline 'main
|
(doom-modeline-def-modeline 'main
|
||||||
'(bar workspace-name window-number modals matches buffer-info remote-host buffer-position parrot selection-info)
|
'(bar workspace-name window-number modals matches buffer-info remote-host buffer-position parrot selection-info)
|
||||||
'(objed-state misc-info persp-name fancy-battery grip irc mu4e github debug lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs checker))
|
'(objed-state misc-info persp-name battery grip 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-simple)
|
'(bar matches buffer-info-simple)
|
||||||
|
@ -98,11 +98,11 @@
|
||||||
|
|
||||||
(doom-modeline-def-modeline 'special
|
(doom-modeline-def-modeline 'special
|
||||||
'(bar window-number modals matches buffer-info buffer-position parrot selection-info)
|
'(bar window-number modals matches buffer-info buffer-position parrot selection-info)
|
||||||
'(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 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 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)
|
||||||
|
@ -126,7 +126,7 @@
|
||||||
|
|
||||||
(doom-modeline-def-modeline 'timemachine
|
(doom-modeline-def-modeline 'timemachine
|
||||||
'(bar window-number matches git-timemachine buffer-position parrot selection-info)
|
'(bar window-number matches git-timemachine buffer-position parrot selection-info)
|
||||||
'(misc-info fancy-battery mu4e github debug minor-modes indent-info buffer-encoding major-mode))
|
'(misc-info battery mu4e github debug minor-modes indent-info buffer-encoding major-mode))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Interfaces
|
;; Interfaces
|
||||||
|
@ -200,7 +200,9 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
|
||||||
|
|
||||||
(defvar doom-modeline-mode-map (make-sparse-keymap))
|
(defvar doom-modeline-mode-map (make-sparse-keymap))
|
||||||
|
|
||||||
(declare-function helm-display-mode-line 'helm) ; suppress warnings
|
;; suppress warnings
|
||||||
|
(declare-function battery-update 'battery)
|
||||||
|
(declare-function helm-display-mode-line 'helm)
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode doom-modeline-mode
|
(define-minor-mode doom-modeline-mode
|
||||||
|
@ -227,7 +229,7 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
|
||||||
(add-hook 'pdf-view-mode-hook #'doom-modeline-set-pdf-modeline)
|
(add-hook 'pdf-view-mode-hook #'doom-modeline-set-pdf-modeline)
|
||||||
(add-hook 'git-timemachine-mode-hook #'doom-modeline-set-timemachine-modeline)
|
(add-hook 'git-timemachine-mode-hook #'doom-modeline-set-timemachine-modeline)
|
||||||
(add-hook 'paradox-menu-mode-hook #'doom-modeline-set-package-modeline)
|
(add-hook 'paradox-menu-mode-hook #'doom-modeline-set-package-modeline)
|
||||||
;; Add advice
|
;; Add advices
|
||||||
(advice-add #'helm-display-mode-line :override #'doom-modeline-set-helm-modeline))
|
(advice-add #'helm-display-mode-line :override #'doom-modeline-set-helm-modeline))
|
||||||
(progn
|
(progn
|
||||||
;; Restore mode-line
|
;; Restore mode-line
|
||||||
|
|
Loading…
Add table
Reference in a new issue