61 |
(cond ((eq battery-status-function 'battery-linux-proc-apm) |
(cond ((eq battery-status-function 'battery-linux-proc-apm) |
62 |
"Power %L, battery %B (%p%% load, remaining time %t)") |
"Power %L, battery %B (%p%% load, remaining time %t)") |
63 |
((eq battery-status-function 'battery-linux-proc-acpi) |
((eq battery-status-function 'battery-linux-proc-acpi) |
64 |
"Power %L, battery %B at %r mA (%p%% load, remaining time %t)")) |
"Power %L, battery %B at %r (%p%% load, remaining time %t)")) |
65 |
"*Control string formatting the string to display in the echo area. |
"*Control string formatting the string to display in the echo area. |
66 |
Ordinary characters in the control string are printed as-is, while |
Ordinary characters in the control string are printed as-is, while |
67 |
conversion specifications introduced by a `%' character in the control |
conversion specifications introduced by a `%' character in the control |
243 |
%m Remaining time in minutes |
%m Remaining time in minutes |
244 |
%h Remaining time in hours |
%h Remaining time in hours |
245 |
%t Remaining time in the form `h:min'" |
%t Remaining time in the form `h:min'" |
246 |
(let (capacity design-capacity rate charging-state warn low minutes hours) |
(let (capacity design-capacity rate rate-type charging-state warn low |
247 |
|
minutes hours) |
248 |
(when (file-directory-p "/proc/acpi/battery/") |
(when (file-directory-p "/proc/acpi/battery/") |
249 |
;; ACPI provides information about each battery present in the system in |
;; ACPI provides information about each battery present in the system in |
250 |
;; a separate subdirectory. We are going to merge the available |
;; a separate subdirectory. We are going to merge the available |
262 |
;; battery is "charging"/"discharging", the others are |
;; battery is "charging"/"discharging", the others are |
263 |
;; "unknown". |
;; "unknown". |
264 |
(setq charging-state (match-string 1))) |
(setq charging-state (match-string 1))) |
265 |
(when (re-search-forward "present rate: +\\([0-9]+\\) mA$" nil t) |
(when (re-search-forward "present rate: +\\([0-9]+\\) \\(m[AW]\\)$" |
266 |
(setq rate (+ (or rate 0) (string-to-int (match-string 1))))) |
nil t) |
267 |
(when (re-search-forward "remaining capacity: +\\([0-9]+\\) mAh$" |
(setq rate (+ (or rate 0) (string-to-int (match-string 1))) |
268 |
|
rate-type (or (and rate-type |
269 |
|
(if (string= rate-type (match-string 2)) |
270 |
|
rate-type |
271 |
|
(error |
272 |
|
"Inconsistent rate types (%s vs. %s)" |
273 |
|
rate-type (match-string 2)))) |
274 |
|
(match-string 2)))) |
275 |
|
(when (re-search-forward "remaining capacity: +\\([0-9]+\\) m[AW]h$" |
276 |
nil t) |
nil t) |
277 |
(setq capacity |
(setq capacity |
278 |
(+ (or capacity 0) (string-to-int (match-string 1)))))) |
(+ (or capacity 0) (string-to-int (match-string 1)))))) |
279 |
(goto-char (point-max)) |
(goto-char (point-max)) |
280 |
(insert-file-contents (expand-file-name "info" dir)) |
(insert-file-contents (expand-file-name "info" dir)) |
281 |
(when (re-search-forward "present: +yes$" nil t) |
(when (re-search-forward "present: +yes$" nil t) |
282 |
(when (re-search-forward "design capacity: +\\([0-9]+\\) mAh$" |
(when (re-search-forward "design capacity: +\\([0-9]+\\) m[AW]h$" |
283 |
nil t) |
nil t) |
284 |
(setq design-capacity (+ (or design-capacity 0) |
(setq design-capacity (+ (or design-capacity 0) |
285 |
(string-to-int (match-string 1))))) |
(string-to-int (match-string 1))))) |
286 |
(when (re-search-forward "design capacity warning: +\\([0-9]+\\) mAh$" |
(when (re-search-forward "design capacity warning: +\\([0-9]+\\) m[AW]h$" |
287 |
nil t) |
nil t) |
288 |
(setq warn (+ (or warn 0) (string-to-int (match-string 1))))) |
(setq warn (+ (or warn 0) (string-to-int (match-string 1))))) |
289 |
(when (re-search-forward "design capacity low: +\\([0-9]+\\) mAh$" |
(when (re-search-forward "design capacity low: +\\([0-9]+\\) m[AW]h$" |
290 |
nil t) |
nil t) |
291 |
(setq low (+ (or low 0) |
(setq low (+ (or low 0) |
292 |
(string-to-int (match-string 1)))))))) |
(string-to-int (match-string 1)))))))) |
293 |
(directory-files "/proc/acpi/battery/" t "BAT"))) |
(directory-files "/proc/acpi/battery/" t "BAT"))) |
294 |
(and capacity rate |
(and capacity rate |
295 |
(setq minutes (floor (* (/ (float (if (string= charging-state |
(setq minutes (if (zerop rate) 0 |
296 |
"charging") |
(floor (* (/ (float (if (string= charging-state |
297 |
(- design-capacity capacity) |
"charging") |
298 |
capacity)) rate) 60)) |
(- design-capacity capacity) |
299 |
|
capacity)) rate) 60))) |
300 |
hours (/ minutes 60))) |
hours (/ minutes 60))) |
301 |
(list (cons ?c (or (and capacity (number-to-string capacity)) "N/A")) |
(list (cons ?c (or (and capacity (number-to-string capacity)) "N/A")) |
302 |
(cons ?L (or (when (file-exists-p "/proc/acpi/ac_adapter/AC/state") |
(cons ?L (or (when (file-exists-p "/proc/acpi/ac_adapter/AC/state") |
314 |
(when (re-search-forward |
(when (re-search-forward |
315 |
"temperature: +\\([0-9]+\\) C$" nil t) |
"temperature: +\\([0-9]+\\) C$" nil t) |
316 |
(match-string 1)))) |
(match-string 1)))) |
317 |
|
(when (file-exists-p |
318 |
|
"/proc/acpi/thermal_zone/THM/temperature") |
319 |
|
(with-temp-buffer |
320 |
|
(insert-file-contents |
321 |
|
"/proc/acpi/thermal_zone/THM/temperature") |
322 |
|
(when (re-search-forward |
323 |
|
"temperature: +\\([0-9]+\\) C$" nil t) |
324 |
|
(match-string 1)))) |
325 |
"N/A")) |
"N/A")) |
326 |
(cons ?r (or (and rate (number-to-string rate)) "N/A")) |
(cons ?r (or (and rate (concat (number-to-string rate) " " |
327 |
|
rate-type)) "N/A")) |
328 |
(cons ?B (or charging-state "N/A")) |
(cons ?B (or charging-state "N/A")) |
329 |
(cons ?b (or (and (string= charging-state "charging") "+") |
(cons ?b (or (and (string= charging-state "charging") "+") |
330 |
(and low (< capacity low) "!") |
(and low (< capacity low) "!") |