diff options
| author | Lars Ingebrigtsen | 2019-08-23 02:40:26 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-08-23 02:40:26 +0200 |
| commit | 6b38e34a11a85d50fa384b90ed21ea60d6d646d5 (patch) | |
| tree | e1f624d1cf99c5dbfbb82fc5f406466f501ddce1 | |
| parent | 4982fd95c7d1e099f50d875ca58e92d0c24bb0df (diff) | |
| download | emacs-6b38e34a11a85d50fa384b90ed21ea60d6d646d5.tar.gz emacs-6b38e34a11a85d50fa384b90ed21ea60d6d646d5.zip | |
Have `M-x battery' list all batteries under GNU/Linux
* lisp/battery.el (battery-upower-device): Remove (bug#25559).
(battery--find-linux-sysfs-batteries): New function.
(battery-status-function, battery-linux-sysfs): Use it to list all
batteries, no matter what they're called.
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/battery.el | 23 |
2 files changed, 16 insertions, 12 deletions
| @@ -507,6 +507,11 @@ current and the previous or the next line, as before. | |||
| 507 | 507 | ||
| 508 | * Changes in Specialized Modes and Packages in Emacs 27.1 | 508 | * Changes in Specialized Modes and Packages in Emacs 27.1 |
| 509 | 509 | ||
| 510 | --- | ||
| 511 | ** On GNU/Linux, `M-x battery' will now list all batteries, no matter | ||
| 512 | what they're named, and the `battery-linux-sysfs-regexp' variable has | ||
| 513 | been removed. | ||
| 514 | |||
| 510 | ** The 'list-processes' command now includes port numbers in the | 515 | ** The 'list-processes' command now includes port numbers in the |
| 511 | network connection information (in addition to the host name). | 516 | network connection information (in addition to the host name). |
| 512 | 517 | ||
diff --git a/lisp/battery.el b/lisp/battery.el index 7037d07dcf0..0ef6d37b406 100644 --- a/lisp/battery.el +++ b/lisp/battery.el | |||
| @@ -38,19 +38,21 @@ | |||
| 38 | :prefix "battery-" | 38 | :prefix "battery-" |
| 39 | :group 'hardware) | 39 | :group 'hardware) |
| 40 | 40 | ||
| 41 | (defcustom battery-linux-sysfs-regexp "[bB][aA][tT][0-9]?$" | ||
| 42 | "Regexp for folder names to be searched under | ||
| 43 | /sys/class/power_supply/ that contain battery information." | ||
| 44 | :version "26.1" | ||
| 45 | :type 'regexp | ||
| 46 | :group 'battery) | ||
| 47 | |||
| 48 | (defcustom battery-upower-device "battery_BAT1" | 41 | (defcustom battery-upower-device "battery_BAT1" |
| 49 | "Upower battery device name." | 42 | "Upower battery device name." |
| 50 | :version "26.1" | 43 | :version "26.1" |
| 51 | :type 'string | 44 | :type 'string |
| 52 | :group 'battery) | 45 | :group 'battery) |
| 53 | 46 | ||
| 47 | (defun battery--find-linux-sysfs-batteries () | ||
| 48 | (let ((dirs nil)) | ||
| 49 | (dolist (file (directory-files "/sys/class/power_supply/" t)) | ||
| 50 | (when (and (or (file-directory-p file) | ||
| 51 | (file-symlink-p file)) | ||
| 52 | (file-exists-p (expand-file-name "capacity" file))) | ||
| 53 | (push file dirs))) | ||
| 54 | (nreverse dirs))) | ||
| 55 | |||
| 54 | (defcustom battery-status-function | 56 | (defcustom battery-status-function |
| 55 | (cond ((and (eq system-type 'gnu/linux) | 57 | (cond ((and (eq system-type 'gnu/linux) |
| 56 | (file-readable-p "/proc/apm")) | 58 | (file-readable-p "/proc/apm")) |
| @@ -60,8 +62,7 @@ | |||
| 60 | #'battery-linux-proc-acpi) | 62 | #'battery-linux-proc-acpi) |
| 61 | ((and (eq system-type 'gnu/linux) | 63 | ((and (eq system-type 'gnu/linux) |
| 62 | (file-directory-p "/sys/class/power_supply/") | 64 | (file-directory-p "/sys/class/power_supply/") |
| 63 | (directory-files "/sys/class/power_supply/" nil | 65 | (battery--find-linux-sysfs-batteries)) |
| 64 | battery-linux-sysfs-regexp)) | ||
| 65 | #'battery-linux-sysfs) | 66 | #'battery-linux-sysfs) |
| 66 | ((and (eq system-type 'berkeley-unix) | 67 | ((and (eq system-type 'berkeley-unix) |
| 67 | (file-executable-p "/usr/sbin/apm")) | 68 | (file-executable-p "/usr/sbin/apm")) |
| @@ -449,9 +450,7 @@ The following %-sequences are provided: | |||
| 449 | ;; available information together. | 450 | ;; available information together. |
| 450 | (with-temp-buffer | 451 | (with-temp-buffer |
| 451 | (dolist (dir (ignore-errors | 452 | (dolist (dir (ignore-errors |
| 452 | (directory-files | 453 | (battery--find-linux-sysfs-batteries))) |
| 453 | "/sys/class/power_supply/" t | ||
| 454 | battery-linux-sysfs-regexp))) | ||
| 455 | (erase-buffer) | 454 | (erase-buffer) |
| 456 | (ignore-errors (insert-file-contents | 455 | (ignore-errors (insert-file-contents |
| 457 | (expand-file-name "uevent" dir))) | 456 | (expand-file-name "uevent" dir))) |