Commit 0ea68311 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

* lisp/battery.el: Make it work on my MSI Wind

* lisp/battery.el (battery-echo-area-format): Simplify default.
(battery-linux-sysfs): Standardize on energy&power.  Accept ADP1
for AC adapter.
parent 25058c3a
2015-03-07 Stefan Monnier <>
* battery.el (battery-echo-area-format): Simplify default.
(battery-linux-sysfs): Standardize on energy&power. Accept ADP1
for AC adapter.
* emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Don't try to
unfold `closure's since byte-compile-unfold-lambda doesn't know how to
do it.
2015-03-06 Oscar Fuentes <>
* net/browse-url.el (browse-url-firefox): Removed outdated
* net/browse-url.el (browse-url-firefox): Remove outdated
MS-Windows limitations.
2015-03-06 Thomas Fitzsimmons <>
......@@ -16,8 +20,8 @@
(eudc-ldap-cleanup-record-filtering-addresses): Add docstring.
Don't clean up postal addresses if ldap-ignore-attribute-codings
is set. Combine mail addresses into one field. (Bug#17720)
(eudc-ldap-simple-query-internal): Call
eudc-ldap-cleanup-record-filtering-addresses instead of
Call eudc-ldap-cleanup-record-filtering-addresses instead of
(eudc-ldap-get-field-list): Likewise.
......@@ -44,27 +44,27 @@
(defcustom battery-status-function
(cond ((and (eq system-type 'gnu/linux)
(file-readable-p "/proc/apm"))
((and (eq system-type 'gnu/linux)
(file-directory-p "/proc/acpi/battery"))
((and (eq system-type 'gnu/linux)
(file-directory-p "/sys/class/power_supply/")
(directory-files "/sys/class/power_supply/" nil
((and (eq system-type 'berkeley-unix)
(file-executable-p "/usr/sbin/apm"))
((and (eq system-type 'darwin)
(condition-case nil
(and (eq (call-process "pmset" nil t nil "-g" "ps") 0)
(> (buffer-size) 0)))
(error nil)))
((fboundp 'w32-battery-status)
"Function for getting battery status information.
The function has to return an alist of conversion definitions.
Its cons cells are of the form
......@@ -77,14 +77,7 @@ introduced by a `%' character in a control string."
:group 'battery)
(defcustom battery-echo-area-format
(cond ((eq battery-status-function 'battery-linux-proc-acpi)
"Power %L, battery %B at %r (%p%% load, remaining time %t)")
((eq battery-status-function 'battery-linux-sysfs)
"Power %L, battery %B (%p%% load, remaining time %t)")
((eq battery-status-function 'battery-pmset)
"%L power, battery %B (%p%% load, remaining time %t)")
"Power %L, battery %B (%p%% load, remaining time %t)"))
"Power %L, battery %B (%p%% load, remaining time %t)"
"Control string formatting the string to display in the echo area.
Ordinary characters in the control string are printed as-is, while
conversion specifications introduced by a `%' character in the control
......@@ -436,11 +429,15 @@ The following %-sequences are provided:
%m Remaining time (to charge or discharge) in minutes
%h Remaining time (to charge or discharge) in hours
%t Remaining time (to charge or discharge) in the form `h:min'"
(let (charging-state rate temperature hours
(charge-full 0.0)
(charge-now 0.0)
(let (charging-state temperature hours
;; Some batteries report charges and current, other energy and power.
;; In order to reliably be able to combine those data, we convert them
;; all to energy/power (since we can't combine different charges if
;; they're not at the same voltage).
(energy-full 0.0)
(energy-now 0.0))
(energy-now 0.0)
(power-now 0.0)
(voltage-now 10.8)) ;Arbitrary default, in case the info is missing.
;; SysFS provides information about each battery present in the
;; system in a separate subdirectory. We are going to merge the
;; available information together.
......@@ -452,6 +449,11 @@ The following %-sequences are provided:
(ignore-errors (insert-file-contents
(expand-file-name "uevent" dir)))
(goto-char (point-min))
(when (re-search-forward
"POWER_SUPPLY_VOLTAGE_NOW=\\([0-9]*\\)$" nil t)
(setq voltage-now (/ (string-to-number (match-string 1)) 1000000.0)))
(goto-char (point-min))
(when (re-search-forward "POWER_SUPPLY_PRESENT=1$" nil t)
(goto-char (point-min))
(and (re-search-forward "POWER_SUPPLY_STATUS=\\(.*\\)$" nil t)
......@@ -461,7 +463,10 @@ The following %-sequences are provided:
(when (re-search-forward
nil t)
(setq rate (float (string-to-number (match-string 2)))))
(cl-incf power-now
(* (float (string-to-number (match-string 2)))
(if (eq (char-after (match-beginning 1)) ?C)
voltage-now 1.0))))
(goto-char (point-min))
(when (re-search-forward "POWER_SUPPLY_TEMP=\\([0-9]*\\)$" nil t)
(setq temperature (match-string 1)))
......@@ -475,10 +480,10 @@ The following %-sequences are provided:
"POWER_SUPPLY_CHARGE_NOW=\\([0-9]*\\)$" nil t)
(setq now-string (match-string 1)))
(setq charge-full (+ charge-full
(string-to-number full-string))
charge-now (+ charge-now
(string-to-number now-string))))
(cl-incf energy-full (* (string-to-number full-string)
(cl-incf energy-now (* (string-to-number now-string)
((and (progn (goto-char (point-min)) t)
"POWER_SUPPLY_ENERGY_FULL=\\([0-9]*\\)$" nil t)
......@@ -486,27 +491,20 @@ The following %-sequences are provided:
"POWER_SUPPLY_ENERGY_NOW=\\([0-9]*\\)$" nil t)
(setq now-string (match-string 1)))
(setq energy-full (+ energy-full
(string-to-number full-string))
energy-now (+ energy-now
(string-to-number now-string))))))
(cl-incf energy-full (string-to-number full-string))
(cl-incf energy-now (string-to-number now-string)))))
(goto-char (point-min))
(when (and energy-now rate (not (zerop rate))
"POWER_SUPPLY_VOLTAGE_NOW=\\([0-9]*\\)$" nil t))
(unless (zerop power-now)
(let ((remaining (if (string= charging-state "Discharging")
(- energy-full energy-now))))
(setq hours (/ (/ (* remaining (string-to-number
(match-string 1)))
(list (cons ?c (cond ((or (> charge-full 0) (> charge-now 0))
(number-to-string charge-now))
((or (> energy-full 0) (> energy-now 0))
(number-to-string energy-now))
(setq hours (/ remaining power-now)))))))
(list (cons ?c (cond ((or (> energy-full 0) (> energy-now 0))
(number-to-string (/ energy-now voltage-now)))
(t "N/A")))
(cons ?r (if rate (format "%.1f" (/ rate 1000000.0)) "N/A"))
(cons ?r (if (> power-now 0.0)
(format "%.1f" (/ power-now 1000000.0))
(cons ?m (if hours (format "%d" (* hours 60)) "N/A"))
(cons ?h (if hours (format "%d" hours) "N/A"))
(cons ?t (if hours
......@@ -514,21 +512,24 @@ The following %-sequences are provided:
(cons ?d (or temperature "N/A"))
(cons ?B (or charging-state "N/A"))
(cons ?p (cond ((and (> charge-full 0) (> charge-now 0))
(format "%.1f"
(/ (* 100 charge-now) charge-full)))
((> energy-full 0)
(cons ?p (cond ((and (> energy-full 0) (> energy-now 0))
(format "%.1f"
(/ (* 100 energy-now) energy-full)))
(t "N/A")))
(cons ?L (if (file-readable-p "/sys/class/power_supply/AC/online")
(if (battery-search-for-one-match-in-files
(list "/sys/class/power_supply/AC/online"
"1" 0)
(cons ?L (cond
(list "/sys/class/power_supply/AC/online"
"1" 0)
(list "/sys/class/power_supply/AC/online"
"0" 0)
(t "N/A"))))))
;;; `apm' interface for BSD.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment