* Proposal for battery.el @ 2006-10-31 15:54 Michaël Cadilhac [not found] ` <E1GfkPb-0007PW-V9@fencepost.gnu.org> 0 siblings, 1 reply; 10+ messages in thread From: Michaël Cadilhac @ 2006-10-31 15:54 UTC (permalink / raw) [-- Attachment #1.1.1: Type: text/plain, Size: 423 bytes --] 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 ! [-- Attachment #1.1.2: battery.patch --] [-- Type: text/x-patch, Size: 4273 bytes --] 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))) + \f (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 <michael.cadilhac@lrde.org> + + * 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. + [-- Attachment #1.1.3: Type: text/plain, Size: 393 bytes --] -- /!\ 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: micha@amessage.be --' -- P. Desproges - --' [-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --] [-- Attachment #2: Type: text/plain, Size: 142 bytes --] _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <E1GfkPb-0007PW-V9@fencepost.gnu.org>]
* Re: Proposal for battery.el [not found] ` <E1GfkPb-0007PW-V9@fencepost.gnu.org> @ 2006-11-02 22:02 ` Michaël Cadilhac 2006-11-04 6:36 ` Richard Stallman 0 siblings, 1 reply; 10+ messages in thread From: Michaël Cadilhac @ 2006-11-02 22:02 UTC (permalink / raw) Cc: emacs-devel [-- Attachment #1.1.1: Type: text/plain, Size: 277 bytes --] Richard Stallman <rms@gnu.org> writes: > What is the purpose of making battery-search-one-match-in-files > return a list of files? To see if you read the proposals ;-) I used that in the elaboration of the patch, but it's indeed useless now. Please consider this version. [-- Attachment #1.1.2: battery.patch --] [-- Type: text/x-patch, Size: 4110 bytes --] 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 2 Nov 2006 21:56:48 -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-for-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-for-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,470 ---- (or (cdr (assoc char alist)) "")))) format t t)) + (defun battery-search-for-one-match-in-files (files regexp match-num) + "Search REGEXP in the list of files FILES. + Return the parenthesized expression numbered by MATCH-NUM." + (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))) + (when files + (match-string match-num)))) + \f (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 2 Nov 2006 21:56:57 -0000 *************** *** 0 **** --- 1,8 ---- + 2006-10-31 Michaël Cadilhac <michael.cadilhac@lrde.org> + + * 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-for-one-match-in-files): New. Search a regexp in + a list of files. + [-- Attachment #1.1.3: Type: text/plain, Size: 391 bytes --] -- /!\ My mail address changed, please update your files accordingly. | Michaël `Micha' Cadilhac | I cannot reproduce this bug, | | Epita/LRDE Promo 2007 | but I have installed a change | | http://michael.cadilhac.name | which I think will fix it. | `-- - JID: micha@amessage.be --' -- Kim F. Storm - --' [-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --] [-- Attachment #2: Type: text/plain, Size: 142 bytes --] _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Proposal for battery.el 2006-11-02 22:02 ` Michaël Cadilhac @ 2006-11-04 6:36 ` Richard Stallman 2006-11-04 17:41 ` Michaël Cadilhac 0 siblings, 1 reply; 10+ messages in thread From: Richard Stallman @ 2006-11-04 6:36 UTC (permalink / raw) Cc: emacs-devel + (defun battery-search-for-one-match-in-files (files regexp match-num) + "Search REGEXP in the list of files FILES. + Return the parenthesized expression numbered by MATCH-NUM." It does need to say that (1) it matches the _contents_ of the files, and (2) that it returns nil if there is no match. With that change, it seems good. Please install it. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Proposal for battery.el 2006-11-04 6:36 ` Richard Stallman @ 2006-11-04 17:41 ` Michaël Cadilhac 2006-11-04 18:23 ` Romain Francoise 2006-11-05 19:22 ` Richard Stallman 0 siblings, 2 replies; 10+ messages in thread From: Michaël Cadilhac @ 2006-11-04 17:41 UTC (permalink / raw) Cc: emacs-devel [-- Attachment #1.1.1: Type: text/plain, Size: 424 bytes --] Richard Stallman <rms@gnu.org> writes: > + (defun battery-search-for-one-match-in-files (files regexp match-num) > + "Search REGEXP in the list of files FILES. > + Return the parenthesized expression numbered by MATCH-NUM." > > It does need to say that (1) it matches the _contents_ of the files, > and (2) that it returns nil if there is no match. > With that change, it seems good. Fair enough ! Attached. [-- Attachment #1.1.2: battery.patch --] [-- Type: text/x-patch, Size: 4183 bytes --] 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 2 Nov 2006 21:56:48 -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-for-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-for-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,471 ---- (or (cdr (assoc char alist)) "")))) format t t)) + (defun battery-search-for-one-match-in-files (files regexp match-num) + "Search REGEXP in content of the files listed in FILES. + If a match occured, return the parenthesized expression numbered by + MATCH-NUM in the match. Otherwise, return nil." + (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))) + (when files + (match-string match-num)))) + \f (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 2 Nov 2006 21:56:57 -0000 *************** *** 0 **** --- 1,8 ---- + 2006-11-04 Michaël Cadilhac <michael.cadilhac@lrde.org> + + * 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-for-one-match-in-files): New. Search a regexp in + a list of files. + [-- Attachment #1.1.3: Type: text/plain, Size: 445 bytes --] > Please install it. Please someone do! TIA! -- /!\ My mail address changed, please update your files accordingly. | Michaël `Micha' Cadilhac | La culture c'est comme la confiture, | | Epita/LRDE Promo 2007 | c'est meilleur avec du pain. | | http://michael.cadilhac.name | -- MOI59 | `-- - JID: micha@amessage.be --' - --' [-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --] [-- Attachment #2: Type: text/plain, Size: 142 bytes --] _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Proposal for battery.el 2006-11-04 17:41 ` Michaël Cadilhac @ 2006-11-04 18:23 ` Romain Francoise 2006-11-04 18:31 ` martin rudalics 2006-11-05 12:53 ` Michaël Cadilhac 2006-11-05 19:22 ` Richard Stallman 1 sibling, 2 replies; 10+ messages in thread From: Romain Francoise @ 2006-11-04 18:23 UTC (permalink / raw) Cc: rms, emacs-devel michael@cadilhac.name (Michaël Cadilhac) writes: + (defun battery-search-for-one-match-in-files (files regexp match-num) + "Search REGEXP in content of the files listed in FILES. + If a match occured, return the parenthesized expression numbered by + MATCH-NUM in the match. Otherwise, return nil." + (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))) + (when files + (match-string match-num)))) How about the following instead? Since battery.el requires cl at compilation time, you can safely use `dolist'... (defun battery-search-for-one-match-in-files (files regexp match-num) "Search REGEXP in content of the files listed in FILES. If a match occured, return the parenthesized expression numbered by MATCH-NUM in the match. Otherwise, return nil." (catch 'found (dolist (file files) (with-temp-buffer (insert-file-contents file) (when (re-search-forward regexp nil t) (throw 'found (match-string match-num))))))) -- Romain Francoise <romain@orebokech.com> | The sea! the sea! the open it's a miracle -- http://orebokech.com/ | sea! The blue, the fresh, the | ever free! --Bryan W. Procter ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Proposal for battery.el 2006-11-04 18:23 ` Romain Francoise @ 2006-11-04 18:31 ` martin rudalics 2006-11-04 20:04 ` Romain Francoise 2006-11-05 12:53 ` Michaël Cadilhac 1 sibling, 1 reply; 10+ messages in thread From: martin rudalics @ 2006-11-04 18:31 UTC (permalink / raw) Cc: emacs-devel > How about the following instead? Since battery.el requires cl at > compilation time, you can safely use `dolist'... ... `dolist' is in subr.el. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Proposal for battery.el 2006-11-04 18:31 ` martin rudalics @ 2006-11-04 20:04 ` Romain Francoise 0 siblings, 0 replies; 10+ messages in thread From: Romain Francoise @ 2006-11-04 20:04 UTC (permalink / raw) Cc: emacs-devel martin rudalics <rudalics@gmx.at> writes: > ... `dolist' is in subr.el. Right, it is in Emacs 21/22. So that's two reasons to use it here. -- Romain Francoise <romain@orebokech.com> | The sea! the sea! the open it's a miracle -- http://orebokech.com/ | sea! The blue, the fresh, the | ever free! --Bryan W. Procter ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Proposal for battery.el 2006-11-04 18:23 ` Romain Francoise 2006-11-04 18:31 ` martin rudalics @ 2006-11-05 12:53 ` Michaël Cadilhac 2006-11-05 13:23 ` Romain Francoise 1 sibling, 1 reply; 10+ messages in thread From: Michaël Cadilhac @ 2006-11-05 12:53 UTC (permalink / raw) Cc: rms, emacs-devel [-- Attachment #1.1.1: Type: text/plain, Size: 864 bytes --] Romain Francoise <romain@orebokech.com> writes: > michael@cadilhac.name (Michaël Cadilhac) writes: > > + (defun battery-search-for-one-match-in-files (files regexp match-num) > + "Search REGEXP in content of the files listed in FILES. > + If a match occured, return the parenthesized expression numbered by > + MATCH-NUM in the match. Otherwise, return nil." > + (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))) > + (when files > + (match-string match-num)))) > > Since battery.el requires cl at compilation time, you can safely use > `dolist'... You're right, it'd enhance the readability of the code. Please consider this (hopefully) final version. [-- Attachment #1.1.2: battery.patch --] [-- Type: text/x-patch, Size: 4787 bytes --] 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 5 Nov 2006 12:46:37 -0000 *************** *** 49,56 **** (file-directory-p "/proc/acpi/battery")) 'battery-linux-proc-acpi) ((and (eq system-type 'darwin) ! (condition-case nil ! (with-temp-buffer (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) (> (buffer-size) 0))) (error nil))) --- 49,56 ---- (file-directory-p "/proc/acpi/battery")) 'battery-linux-proc-acpi) ((and (eq system-type 'darwin) ! (condition-case nil ! (with-temp-buffer (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) (> (buffer-size) 0))) (error nil))) *************** *** 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-for-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-for-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,468 ---- (or (cdr (assoc char alist)) "")))) format t t)) + (defun battery-search-for-one-match-in-files (files regexp match-num) + "Search REGEXP in the content of the files listed in FILES. + If a match occured, return the parenthesized expression numbered by + MATCH-NUM in the match. Otherwise, return nil." + (with-temp-buffer + (catch 'found + (dolist (file files) + (and (ignore-errors (insert-file-contents file nil nil nil 'replace)) + (re-search-forward regexp nil t) + (throw 'found (match-string match-num))))))) + \f (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 5 Nov 2006 12:46:41 -0000 *************** *** 0 **** --- 1,8 ---- + 2006-10-31 Michaël Cadilhac <michael.cadilhac@lrde.org> + + * 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-for-one-match-in-files): New. Search a regexp in + the content of some files. + [-- Attachment #1.1.3: Type: text/plain, Size: 389 bytes --] -- /!\ My mail address changed, please update your files accordingly. | Michaël `Micha' Cadilhac | In a World without Walls and Fences, | | Epita/LRDE Promo 2007 | who needs Windows and Gates? | | http://michael.cadilhac.name | -- Dino Esposito | `-- - JID: micha@amessage.be --' - --' [-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --] [-- Attachment #2: Type: text/plain, Size: 142 bytes --] _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Proposal for battery.el 2006-11-05 12:53 ` Michaël Cadilhac @ 2006-11-05 13:23 ` Romain Francoise 0 siblings, 0 replies; 10+ messages in thread From: Romain Francoise @ 2006-11-05 13:23 UTC (permalink / raw) Cc: rms, emacs-devel michael@cadilhac.name (Michaël Cadilhac) writes: > Please consider this (hopefully) final version. Ok, installed. Thanks! -- Romain Francoise <romain@orebokech.com> | The sea! the sea! the open it's a miracle -- http://orebokech.com/ | sea! The blue, the fresh, the | ever free! --Bryan W. Procter ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Proposal for battery.el 2006-11-04 17:41 ` Michaël Cadilhac 2006-11-04 18:23 ` Romain Francoise @ 2006-11-05 19:22 ` Richard Stallman 1 sibling, 0 replies; 10+ messages in thread From: Richard Stallman @ 2006-11-05 19:22 UTC (permalink / raw) Cc: emacs-devel Thanks. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2006-11-05 19:22 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-10-31 15:54 Proposal for battery.el Michaël Cadilhac [not found] ` <E1GfkPb-0007PW-V9@fencepost.gnu.org> 2006-11-02 22:02 ` Michaël Cadilhac 2006-11-04 6:36 ` Richard Stallman 2006-11-04 17:41 ` Michaël Cadilhac 2006-11-04 18:23 ` Romain Francoise 2006-11-04 18:31 ` martin rudalics 2006-11-04 20:04 ` Romain Francoise 2006-11-05 12:53 ` Michaël Cadilhac 2006-11-05 13:23 ` Romain Francoise 2006-11-05 19:22 ` Richard Stallman
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.