Variable: battery-update-functions
battery-update-functions is a customizable variable defined in
battery.el.gz.
Value
nil
Documentation
Functions run by display-battery-mode(var)/display-battery-mode(fun) after updating the status.
These functions will be called with one parameter, an alist that contains data about the current battery status. The keys in the alist are single characters and the values are strings. Different battery backends deliver different information, so some of the following information may or may not be available:
v: driver-version
V: bios-version
I: bios-interface
L: line-status
B: battery-status
b: battery-status-symbol
p: load-percentage
s: seconds
m: minutes
h: hours
t: remaining-time
For instance, to play an alarm when the battery power dips below
10%, you could use a function like the following:
(defvar my-prev-battery nil)
(defun my-battery-alarm (data)
(when (and my-prev-battery
(equal (alist-get ?L data) "off-line")
(< (string-to-number (alist-get ?p data)) 10)
(>= (string-to-number (alist-get ?p my-prev-battery)) 10))
(play-sound-file "~/alarm.wav" 5))
(setq my-prev-battery data))
This variable was added, or its default value changed, in Emacs 29.1.
Probably introduced at or before Emacs version 29.1.
Source Code
;; Defined in /usr/src/emacs/lisp/battery.el.gz
(defcustom battery-update-functions nil
"Functions run by `display-battery-mode' after updating the status.
These functions will be called with one parameter, an alist that
contains data about the current battery status. The keys in the
alist are single characters and the values are strings.
Different battery backends deliver different information, so some
of the following information may or may not be available:
v: driver-version
V: bios-version
I: bios-interface
L: line-status
B: battery-status
b: battery-status-symbol
p: load-percentage
s: seconds
m: minutes
h: hours
t: remaining-time
For instance, to play an alarm when the battery power dips below
10%, you could use a function like the following:
(defvar my-prev-battery nil)
(defun my-battery-alarm (data)
(when (and my-prev-battery
(equal (alist-get ?L data) \"off-line\")
(< (string-to-number (alist-get ?p data)) 10)
(>= (string-to-number (alist-get ?p my-prev-battery)) 10))
(play-sound-file \"~/alarm.wav\" 5))
(setq my-prev-battery data))"
:version "29.1"
:type '(repeat function))