[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Proposal for battery.el
From: |
Michaël Cadilhac |
Subject: |
Proposal for battery.el |
Date: |
Tue, 31 Oct 2006 16:54:52 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.90 (gnu/linux) |
Hi!
Battery.el offers nice features about laptop status, however, my Acer
Aspire 1680 gentoo 2006.1 with a 2.6.18 kernel using ACPI is breaking
some parts of the file detections in battery.el: the ac_adapter is
called AC0.
I propose the following change that factor some part of the code.
I don't think the thermometers have been put in a special order in the
code, so I believe my patch doesn't break anything.
TIA !
Index: lisp/battery.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/battery.el,v
retrieving revision 1.36
diff -c -r1.36 battery.el
*** lisp/battery.el 9 May 2006 22:43:35 -0000 1.36
--- lisp/battery.el 31 Oct 2006 15:45:47 -0000
***************
*** 355,399 ****
60)))
hours (/ minutes 60)))
(list (cons ?c (or (and capacity (number-to-string capacity)) "N/A"))
! (cons ?L (or (when (file-exists-p "/proc/acpi/ac_adapter/AC/state")
! (with-temp-buffer
! (insert-file-contents
! "/proc/acpi/ac_adapter/AC/state")
! (when (re-search-forward "state: +\\(.*\\)$" nil t)
! (match-string 1))))
"N/A"))
! (cons ?d (or (when (file-exists-p
! "/proc/acpi/thermal_zone/THRM/temperature")
! (with-temp-buffer
! (insert-file-contents
! "/proc/acpi/thermal_zone/THRM/temperature")
! (when (re-search-forward
! "temperature: +\\([0-9]+\\) C$" nil t)
! (match-string 1))))
! (when (file-exists-p
! "/proc/acpi/thermal_zone/THM/temperature")
! (with-temp-buffer
! (insert-file-contents
! "/proc/acpi/thermal_zone/THM/temperature")
! (when (re-search-forward
! "temperature: +\\([0-9]+\\) C$" nil t)
! (match-string 1))))
! (when (file-exists-p
! "/proc/acpi/thermal_zone/THM0/temperature")
! (with-temp-buffer
! (insert-file-contents
! "/proc/acpi/thermal_zone/THM0/temperature")
! (when (re-search-forward
! "temperature: +\\([0-9]+\\) C$" nil t)
! (match-string 1))))
! (when (file-exists-p
! "/proc/acpi/thermal_zone/THR2/temperature")
! (with-temp-buffer
! (insert-file-contents
! "/proc/acpi/thermal_zone/THR2/temperature")
! (when (re-search-forward
! "temperature: +\\([0-9]+\\) C$" nil t)
! (match-string 1))))
"N/A"))
(cons ?r (or (and rate (concat (number-to-string rate) " "
rate-type)) "N/A"))
--- 355,373 ----
60)))
hours (/ minutes 60)))
(list (cons ?c (or (and capacity (number-to-string capacity)) "N/A"))
! (cons ?L (or (battery-search-one-match-in-files
! (mapcar (lambda (e) (concat e "/state"))
! (directory-files "/proc/acpi/ac_adapter/"
! t "\\`[^.]"))
! "state: +\\(.*\\)$" 1)
!
"N/A"))
! (cons ?d (or (battery-search-one-match-in-files
! (mapcar (lambda (e) (concat e "/temperature"))
! (directory-files "/proc/acpi/thermal_zone/"
! t "\\`[^.]"))
! "temperature: +\\([0-9]+\\) C$" 1)
!
"N/A"))
(cons ?r (or (and rate (concat (number-to-string rate) " "
rate-type)) "N/A"))
***************
*** 478,483 ****
--- 452,474 ----
(or (cdr (assoc char alist)) ""))))
format t t))
+ (defun battery-search-one-match-in-files (files regexp &optional match-num)
+ "Search REGEXP in the list of files FILES.
+ If MATCH-NUM is non-nil, return the parenthesized expression numbered by it.
+ Otherwise, return a list starting with the first file that had a match
followed
+ by the untested files in FILES."
+ (with-temp-buffer
+ (while (and files
+ (not (or (ignore-errors
+ (insert-file-contents (car files))
+ (re-search-forward regexp))
+ (erase-buffer))))
+ (setq files (cdr files)))
+ (if match-num
+ (when files
+ (match-string match-num))
+ files)))
+
(provide 'battery)
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.10237
diff -c -0 -r1.10237 ChangeLog
*** lisp/ChangeLog 31 Oct 2006 11:07:10 -0000 1.10237
--- lisp/ChangeLog 31 Oct 2006 15:45:56 -0000
***************
*** 0 ****
--- 1,8 ----
+ 2006-10-31 Michaël Cadilhac <address@hidden>
+
+ * battery.el (battery-linux-proc-acpi): Search an ac_adapter in
+ `/proc/acpi/ac_adapter/*'. Ditto for the thermometers in
+ `/proc/acpi/thermal_zone/*'.
+ (battery-search-one-match-in-files): New. Search a regexp in
+ a list of files.
+
--
/!\ My mail address changed, please update your files accordingly.
| Michaël `Micha' Cadilhac | «Tu aimeras ton prochain.» |
| Epita/LRDE Promo 2007 | D'abord, Dieu ou pas, |
| http://michael.cadilhac.name | j'ai horreur qu'on me tutoie. |
`-- - JID: address@hidden --' -- P. Desproges - --'
pgpKbozAJvozS.pgp
Description: PGP signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Proposal for battery.el,
Michaël Cadilhac <=