[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 6b38e34: Have `M-x battery' list all batteries unde
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] master 6b38e34: Have `M-x battery' list all batteries under GNU/Linux |
Date: |
Thu, 22 Aug 2019 20:40:35 -0400 (EDT) |
branch: master
commit 6b38e34a11a85d50fa384b90ed21ea60d6d646d5
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
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.
---
etc/NEWS | 5 +++++
lisp/battery.el | 23 +++++++++++------------
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 3fdc185..da3c29b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -507,6 +507,11 @@ current and the previous or the next line, as before.
* Changes in Specialized Modes and Packages in Emacs 27.1
+---
+** On GNU/Linux, `M-x battery' will now list all batteries, no matter
+what they're named, and the `battery-linux-sysfs-regexp' variable has
+been removed.
+
** The 'list-processes' command now includes port numbers in the
network connection information (in addition to the host name).
diff --git a/lisp/battery.el b/lisp/battery.el
index 7037d07..0ef6d37 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -38,19 +38,21 @@
:prefix "battery-"
:group 'hardware)
-(defcustom battery-linux-sysfs-regexp "[bB][aA][tT][0-9]?$"
- "Regexp for folder names to be searched under
- /sys/class/power_supply/ that contain battery information."
- :version "26.1"
- :type 'regexp
- :group 'battery)
-
(defcustom battery-upower-device "battery_BAT1"
"Upower battery device name."
:version "26.1"
:type 'string
:group 'battery)
+(defun battery--find-linux-sysfs-batteries ()
+ (let ((dirs nil))
+ (dolist (file (directory-files "/sys/class/power_supply/" t))
+ (when (and (or (file-directory-p file)
+ (file-symlink-p file))
+ (file-exists-p (expand-file-name "capacity" file)))
+ (push file dirs)))
+ (nreverse dirs)))
+
(defcustom battery-status-function
(cond ((and (eq system-type 'gnu/linux)
(file-readable-p "/proc/apm"))
@@ -60,8 +62,7 @@
#'battery-linux-proc-acpi)
((and (eq system-type 'gnu/linux)
(file-directory-p "/sys/class/power_supply/")
- (directory-files "/sys/class/power_supply/" nil
- battery-linux-sysfs-regexp))
+ (battery--find-linux-sysfs-batteries))
#'battery-linux-sysfs)
((and (eq system-type 'berkeley-unix)
(file-executable-p "/usr/sbin/apm"))
@@ -449,9 +450,7 @@ The following %-sequences are provided:
;; available information together.
(with-temp-buffer
(dolist (dir (ignore-errors
- (directory-files
- "/sys/class/power_supply/" t
- battery-linux-sysfs-regexp)))
+ (battery--find-linux-sysfs-batteries)))
(erase-buffer)
(ignore-errors (insert-file-contents
(expand-file-name "uevent" dir)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 6b38e34: Have `M-x battery' list all batteries under GNU/Linux,
Lars Ingebrigtsen <=