diff options
| author | Stefan Monnier | 2015-03-06 23:42:10 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2015-03-06 23:42:10 -0500 |
| commit | 0ea68311a5597f0a74c902519ae7a5f1920ed2e9 (patch) | |
| tree | 66e0110de0bf78d1958712a6e43daa27d82fe7f3 /lisp | |
| parent | 25058c3ab82cff0105c31de0c1934da6602c6bee (diff) | |
| download | emacs-0ea68311a5597f0a74c902519ae7a5f1920ed2e9.tar.gz emacs-0ea68311a5597f0a74c902519ae7a5f1920ed2e9.zip | |
* 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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/battery.el | 103 |
2 files changed, 59 insertions, 54 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1bd45c07c3e..0b277c7c518 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,12 +1,16 @@ | |||
| 1 | 2015-03-07 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2015-03-07 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * battery.el (battery-echo-area-format): Simplify default. | ||
| 4 | (battery-linux-sysfs): Standardize on energy&power. Accept ADP1 | ||
| 5 | for AC adapter. | ||
| 6 | |||
| 3 | * emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Don't try to | 7 | * emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Don't try to |
| 4 | unfold `closure's since byte-compile-unfold-lambda doesn't know how to | 8 | unfold `closure's since byte-compile-unfold-lambda doesn't know how to |
| 5 | do it. | 9 | do it. |
| 6 | 10 | ||
| 7 | 2015-03-06 Oscar Fuentes <ofv@wanadoo.es> | 11 | 2015-03-06 Oscar Fuentes <ofv@wanadoo.es> |
| 8 | 12 | ||
| 9 | * net/browse-url.el (browse-url-firefox): Removed outdated | 13 | * net/browse-url.el (browse-url-firefox): Remove outdated |
| 10 | MS-Windows limitations. | 14 | MS-Windows limitations. |
| 11 | 15 | ||
| 12 | 2015-03-06 Thomas Fitzsimmons <fitzsim@fitzsim.org> | 16 | 2015-03-06 Thomas Fitzsimmons <fitzsim@fitzsim.org> |
| @@ -16,8 +20,8 @@ | |||
| 16 | (eudc-ldap-cleanup-record-filtering-addresses): Add docstring. | 20 | (eudc-ldap-cleanup-record-filtering-addresses): Add docstring. |
| 17 | Don't clean up postal addresses if ldap-ignore-attribute-codings | 21 | Don't clean up postal addresses if ldap-ignore-attribute-codings |
| 18 | is set. Combine mail addresses into one field. (Bug#17720) | 22 | is set. Combine mail addresses into one field. (Bug#17720) |
| 19 | (eudc-ldap-simple-query-internal): Call | 23 | (eudc-ldap-simple-query-internal): |
| 20 | eudc-ldap-cleanup-record-filtering-addresses instead of | 24 | Call eudc-ldap-cleanup-record-filtering-addresses instead of |
| 21 | eudc-ldap-cleanup-record-simple. | 25 | eudc-ldap-cleanup-record-simple. |
| 22 | (eudc-ldap-get-field-list): Likewise. | 26 | (eudc-ldap-get-field-list): Likewise. |
| 23 | 27 | ||
diff --git a/lisp/battery.el b/lisp/battery.el index 41e5979f1f2..b9ce5b49093 100644 --- a/lisp/battery.el +++ b/lisp/battery.el | |||
| @@ -44,27 +44,27 @@ | |||
| 44 | (defcustom battery-status-function | 44 | (defcustom battery-status-function |
| 45 | (cond ((and (eq system-type 'gnu/linux) | 45 | (cond ((and (eq system-type 'gnu/linux) |
| 46 | (file-readable-p "/proc/apm")) | 46 | (file-readable-p "/proc/apm")) |
| 47 | 'battery-linux-proc-apm) | 47 | #'battery-linux-proc-apm) |
| 48 | ((and (eq system-type 'gnu/linux) | 48 | ((and (eq system-type 'gnu/linux) |
| 49 | (file-directory-p "/proc/acpi/battery")) | 49 | (file-directory-p "/proc/acpi/battery")) |
| 50 | 'battery-linux-proc-acpi) | 50 | #'battery-linux-proc-acpi) |
| 51 | ((and (eq system-type 'gnu/linux) | 51 | ((and (eq system-type 'gnu/linux) |
| 52 | (file-directory-p "/sys/class/power_supply/") | 52 | (file-directory-p "/sys/class/power_supply/") |
| 53 | (directory-files "/sys/class/power_supply/" nil | 53 | (directory-files "/sys/class/power_supply/" nil |
| 54 | battery--linux-sysfs-regexp)) | 54 | battery--linux-sysfs-regexp)) |
| 55 | 'battery-linux-sysfs) | 55 | #'battery-linux-sysfs) |
| 56 | ((and (eq system-type 'berkeley-unix) | 56 | ((and (eq system-type 'berkeley-unix) |
| 57 | (file-executable-p "/usr/sbin/apm")) | 57 | (file-executable-p "/usr/sbin/apm")) |
| 58 | 'battery-bsd-apm) | 58 | #'battery-bsd-apm) |
| 59 | ((and (eq system-type 'darwin) | 59 | ((and (eq system-type 'darwin) |
| 60 | (condition-case nil | 60 | (condition-case nil |
| 61 | (with-temp-buffer | 61 | (with-temp-buffer |
| 62 | (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) | 62 | (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) |
| 63 | (> (buffer-size) 0))) | 63 | (> (buffer-size) 0))) |
| 64 | (error nil))) | 64 | (error nil))) |
| 65 | 'battery-pmset) | 65 | #'battery-pmset) |
| 66 | ((fboundp 'w32-battery-status) | 66 | ((fboundp 'w32-battery-status) |
| 67 | 'w32-battery-status)) | 67 | #'w32-battery-status)) |
| 68 | "Function for getting battery status information. | 68 | "Function for getting battery status information. |
| 69 | The function has to return an alist of conversion definitions. | 69 | The function has to return an alist of conversion definitions. |
| 70 | Its cons cells are of the form | 70 | Its cons cells are of the form |
| @@ -77,14 +77,7 @@ introduced by a `%' character in a control string." | |||
| 77 | :group 'battery) | 77 | :group 'battery) |
| 78 | 78 | ||
| 79 | (defcustom battery-echo-area-format | 79 | (defcustom battery-echo-area-format |
| 80 | (cond ((eq battery-status-function 'battery-linux-proc-acpi) | 80 | "Power %L, battery %B (%p%% load, remaining time %t)" |
| 81 | "Power %L, battery %B at %r (%p%% load, remaining time %t)") | ||
| 82 | ((eq battery-status-function 'battery-linux-sysfs) | ||
| 83 | "Power %L, battery %B (%p%% load, remaining time %t)") | ||
| 84 | ((eq battery-status-function 'battery-pmset) | ||
| 85 | "%L power, battery %B (%p%% load, remaining time %t)") | ||
| 86 | (battery-status-function | ||
| 87 | "Power %L, battery %B (%p%% load, remaining time %t)")) | ||
| 88 | "Control string formatting the string to display in the echo area. | 81 | "Control string formatting the string to display in the echo area. |
| 89 | Ordinary characters in the control string are printed as-is, while | 82 | Ordinary characters in the control string are printed as-is, while |
| 90 | conversion specifications introduced by a `%' character in the control | 83 | conversion specifications introduced by a `%' character in the control |
| @@ -436,11 +429,15 @@ The following %-sequences are provided: | |||
| 436 | %m Remaining time (to charge or discharge) in minutes | 429 | %m Remaining time (to charge or discharge) in minutes |
| 437 | %h Remaining time (to charge or discharge) in hours | 430 | %h Remaining time (to charge or discharge) in hours |
| 438 | %t Remaining time (to charge or discharge) in the form `h:min'" | 431 | %t Remaining time (to charge or discharge) in the form `h:min'" |
| 439 | (let (charging-state rate temperature hours | 432 | (let (charging-state temperature hours |
| 440 | (charge-full 0.0) | 433 | ;; Some batteries report charges and current, other energy and power. |
| 441 | (charge-now 0.0) | 434 | ;; In order to reliably be able to combine those data, we convert them |
| 435 | ;; all to energy/power (since we can't combine different charges if | ||
| 436 | ;; they're not at the same voltage). | ||
| 442 | (energy-full 0.0) | 437 | (energy-full 0.0) |
| 443 | (energy-now 0.0)) | 438 | (energy-now 0.0) |
| 439 | (power-now 0.0) | ||
| 440 | (voltage-now 10.8)) ;Arbitrary default, in case the info is missing. | ||
| 444 | ;; SysFS provides information about each battery present in the | 441 | ;; SysFS provides information about each battery present in the |
| 445 | ;; system in a separate subdirectory. We are going to merge the | 442 | ;; system in a separate subdirectory. We are going to merge the |
| 446 | ;; available information together. | 443 | ;; available information together. |
| @@ -452,6 +449,11 @@ The following %-sequences are provided: | |||
| 452 | (erase-buffer) | 449 | (erase-buffer) |
| 453 | (ignore-errors (insert-file-contents | 450 | (ignore-errors (insert-file-contents |
| 454 | (expand-file-name "uevent" dir))) | 451 | (expand-file-name "uevent" dir))) |
| 452 | (goto-char (point-min)) | ||
| 453 | (when (re-search-forward | ||
| 454 | "POWER_SUPPLY_VOLTAGE_NOW=\\([0-9]*\\)$" nil t) | ||
| 455 | (setq voltage-now (/ (string-to-number (match-string 1)) 1000000.0))) | ||
| 456 | (goto-char (point-min)) | ||
| 455 | (when (re-search-forward "POWER_SUPPLY_PRESENT=1$" nil t) | 457 | (when (re-search-forward "POWER_SUPPLY_PRESENT=1$" nil t) |
| 456 | (goto-char (point-min)) | 458 | (goto-char (point-min)) |
| 457 | (and (re-search-forward "POWER_SUPPLY_STATUS=\\(.*\\)$" nil t) | 459 | (and (re-search-forward "POWER_SUPPLY_STATUS=\\(.*\\)$" nil t) |
| @@ -461,7 +463,10 @@ The following %-sequences are provided: | |||
| 461 | (when (re-search-forward | 463 | (when (re-search-forward |
| 462 | "POWER_SUPPLY_\\(CURRENT\\|POWER\\)_NOW=\\([0-9]*\\)$" | 464 | "POWER_SUPPLY_\\(CURRENT\\|POWER\\)_NOW=\\([0-9]*\\)$" |
| 463 | nil t) | 465 | nil t) |
| 464 | (setq rate (float (string-to-number (match-string 2))))) | 466 | (cl-incf power-now |
| 467 | (* (float (string-to-number (match-string 2))) | ||
| 468 | (if (eq (char-after (match-beginning 1)) ?C) | ||
| 469 | voltage-now 1.0)))) | ||
| 465 | (goto-char (point-min)) | 470 | (goto-char (point-min)) |
| 466 | (when (re-search-forward "POWER_SUPPLY_TEMP=\\([0-9]*\\)$" nil t) | 471 | (when (re-search-forward "POWER_SUPPLY_TEMP=\\([0-9]*\\)$" nil t) |
| 467 | (setq temperature (match-string 1))) | 472 | (setq temperature (match-string 1))) |
| @@ -475,10 +480,10 @@ The following %-sequences are provided: | |||
| 475 | (re-search-forward | 480 | (re-search-forward |
| 476 | "POWER_SUPPLY_CHARGE_NOW=\\([0-9]*\\)$" nil t) | 481 | "POWER_SUPPLY_CHARGE_NOW=\\([0-9]*\\)$" nil t) |
| 477 | (setq now-string (match-string 1))) | 482 | (setq now-string (match-string 1))) |
| 478 | (setq charge-full (+ charge-full | 483 | (cl-incf energy-full (* (string-to-number full-string) |
| 479 | (string-to-number full-string)) | 484 | voltage-now)) |
| 480 | charge-now (+ charge-now | 485 | (cl-incf energy-now (* (string-to-number now-string) |
| 481 | (string-to-number now-string)))) | 486 | voltage-now))) |
| 482 | ((and (progn (goto-char (point-min)) t) | 487 | ((and (progn (goto-char (point-min)) t) |
| 483 | (re-search-forward | 488 | (re-search-forward |
| 484 | "POWER_SUPPLY_ENERGY_FULL=\\([0-9]*\\)$" nil t) | 489 | "POWER_SUPPLY_ENERGY_FULL=\\([0-9]*\\)$" nil t) |
| @@ -486,27 +491,20 @@ The following %-sequences are provided: | |||
| 486 | (re-search-forward | 491 | (re-search-forward |
| 487 | "POWER_SUPPLY_ENERGY_NOW=\\([0-9]*\\)$" nil t) | 492 | "POWER_SUPPLY_ENERGY_NOW=\\([0-9]*\\)$" nil t) |
| 488 | (setq now-string (match-string 1))) | 493 | (setq now-string (match-string 1))) |
| 489 | (setq energy-full (+ energy-full | 494 | (cl-incf energy-full (string-to-number full-string)) |
| 490 | (string-to-number full-string)) | 495 | (cl-incf energy-now (string-to-number now-string))))) |
| 491 | energy-now (+ energy-now | ||
| 492 | (string-to-number now-string)))))) | ||
| 493 | (goto-char (point-min)) | 496 | (goto-char (point-min)) |
| 494 | (when (and energy-now rate (not (zerop rate)) | 497 | (unless (zerop power-now) |
| 495 | (re-search-forward | ||
| 496 | "POWER_SUPPLY_VOLTAGE_NOW=\\([0-9]*\\)$" nil t)) | ||
| 497 | (let ((remaining (if (string= charging-state "Discharging") | 498 | (let ((remaining (if (string= charging-state "Discharging") |
| 498 | energy-now | 499 | energy-now |
| 499 | (- energy-full energy-now)))) | 500 | (- energy-full energy-now)))) |
| 500 | (setq hours (/ (/ (* remaining (string-to-number | 501 | (setq hours (/ remaining power-now))))))) |
| 501 | (match-string 1))) | 502 | (list (cons ?c (cond ((or (> energy-full 0) (> energy-now 0)) |
| 502 | rate) | 503 | (number-to-string (/ energy-now voltage-now))) |
| 503 | 10000000.0))))))) | ||
| 504 | (list (cons ?c (cond ((or (> charge-full 0) (> charge-now 0)) | ||
| 505 | (number-to-string charge-now)) | ||
| 506 | ((or (> energy-full 0) (> energy-now 0)) | ||
| 507 | (number-to-string energy-now)) | ||
| 508 | (t "N/A"))) | 504 | (t "N/A"))) |
| 509 | (cons ?r (if rate (format "%.1f" (/ rate 1000000.0)) "N/A")) | 505 | (cons ?r (if (> power-now 0.0) |
| 506 | (format "%.1f" (/ power-now 1000000.0)) | ||
| 507 | "N/A")) | ||
| 510 | (cons ?m (if hours (format "%d" (* hours 60)) "N/A")) | 508 | (cons ?m (if hours (format "%d" (* hours 60)) "N/A")) |
| 511 | (cons ?h (if hours (format "%d" hours) "N/A")) | 509 | (cons ?h (if hours (format "%d" hours) "N/A")) |
| 512 | (cons ?t (if hours | 510 | (cons ?t (if hours |
| @@ -514,21 +512,24 @@ The following %-sequences are provided: | |||
| 514 | "N/A")) | 512 | "N/A")) |
| 515 | (cons ?d (or temperature "N/A")) | 513 | (cons ?d (or temperature "N/A")) |
| 516 | (cons ?B (or charging-state "N/A")) | 514 | (cons ?B (or charging-state "N/A")) |
| 517 | (cons ?p (cond ((and (> charge-full 0) (> charge-now 0)) | 515 | (cons ?p (cond ((and (> energy-full 0) (> energy-now 0)) |
| 518 | (format "%.1f" | ||
| 519 | (/ (* 100 charge-now) charge-full))) | ||
| 520 | ((> energy-full 0) | ||
| 521 | (format "%.1f" | 516 | (format "%.1f" |
| 522 | (/ (* 100 energy-now) energy-full))) | 517 | (/ (* 100 energy-now) energy-full))) |
| 523 | (t "N/A"))) | 518 | (t "N/A"))) |
| 524 | (cons ?L (if (file-readable-p "/sys/class/power_supply/AC/online") | 519 | (cons ?L (cond |
| 525 | (if (battery-search-for-one-match-in-files | 520 | ((battery-search-for-one-match-in-files |
| 526 | (list "/sys/class/power_supply/AC/online" | 521 | (list "/sys/class/power_supply/AC/online" |
| 527 | "/sys/class/power_supply/ACAD/online") | 522 | "/sys/class/power_supply/ACAD/online" |
| 528 | "1" 0) | 523 | "/sys/class/power_supply/ADP1/online") |
| 529 | "AC" | 524 | "1" 0) |
| 530 | "BAT") | 525 | "AC") |
| 531 | "N/A"))))) | 526 | ((battery-search-for-one-match-in-files |
| 527 | (list "/sys/class/power_supply/AC/online" | ||
| 528 | "/sys/class/power_supply/ACAD/online" | ||
| 529 | "/sys/class/power_supply/ADP1/online") | ||
| 530 | "0" 0) | ||
| 531 | "BAT") | ||
| 532 | (t "N/A")))))) | ||
| 532 | 533 | ||
| 533 | 534 | ||
| 534 | ;;; `apm' interface for BSD. | 535 | ;;; `apm' interface for BSD. |