From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: michael@cadilhac.name (=?iso-8859-1?Q?Micha=EBl?= Cadilhac) Newsgroups: gmane.emacs.devel Subject: Re: Proposal for battery.el Date: Sun, 05 Nov 2006 13:53:03 +0100 Organization: Epita/LRDE Message-ID: <87bqnm5a34.fsf@lrde.org> References: <87lkmwpjjn.fsf@lrde.org> <87u01hy0bk.fsf@lrde.org> <877iybm7ni.fsf@lrde.org> <87k62b9il8.fsf@pacem.orebokech.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0490424096==" X-Trace: sea.gmane.org 1162731198 18111 80.91.229.2 (5 Nov 2006 12:53:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 5 Nov 2006 12:53:18 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Nov 05 13:53:16 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GghUw-0000xW-Tb for ged-emacs-devel@m.gmane.org; Sun, 05 Nov 2006 13:53:15 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GghUw-0004m0-8g for ged-emacs-devel@m.gmane.org; Sun, 05 Nov 2006 07:53:14 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GghUW-0004h4-V7 for emacs-devel@gnu.org; Sun, 05 Nov 2006 07:52:49 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GghUV-0004dU-AJ for emacs-devel@gnu.org; Sun, 05 Nov 2006 07:52:48 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GghUU-0004d5-SK for emacs-devel@gnu.org; Sun, 05 Nov 2006 07:52:47 -0500 Original-Received: from [62.39.139.2] (helo=kualalumpur.lrde.epita.fr) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GghUO-0001AK-T3; Sun, 05 Nov 2006 07:52:41 -0500 Original-Received: from mahaena.lrde.epita.fr ([192.168.101.66] helo=mahaena.lrde) by kualalumpur.lrde.epita.fr with esmtp (Exim 4.50) id 1GghUM-0005rD-Oi; Sun, 05 Nov 2006 13:52:38 +0100 Original-To: Romain Francoise Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEVWPh+Tai+5r5YKBAEU CQQzGAtiq7gjAAACR0lEQVQ4jW2UzW7lIAyFzVW8BzTZX5DmCZLuU2H2pMXv/ypzbK7aSh2kRCRf /HNsE0q7Sg+RQ7JFKaqtrRNAl5AIIKe6D5DBqgbmUAe5hBI1wIRFAHjeM0RKtZi7XVVEpb0BSNfA IddChChT5DildSLWOWhY5IEItMnncZgFcUAc/5jjwCMsDosRNdfKPDTFEdVBW8C+RebDb4N5Orio RhM1+11IJyx0ng2+LryFHBMPDQDYHrY6IfGuU3ouiXTQNE8LIJDKOWpNxERTFrggQwRPd7USUsTW fJ0XbR3bdj5KgBYy4SACpxDeUYEUAzLmtJ1iIrD2gczPq8Qomjhsh/RjGIgKIO8p7NITjwlx7WID nsnQe5NeuTvoBpi8LX6vLLOh5icjOHqBypgnuSp7M+RE1agbQKHQr5E2z1WObhYW4gMqeGQL7joM jCf2DxSk5ApADSYHfFF4igNfJZL1z0GKP0FN02s4XiDXr7V5P94W6I9v8MfBOQDmfwAaVYt+x8Da v4DJvX8BAdin3Knm5yMZYAO4ABDkDniZLLfi4P40gP1F0TPGZOu0CGwA1lcowxwlGy6A9705mD0V jHCxwVZT/hYdRJVUGZNlx6l7ScQBTluof6Wj6bsPYlvpwoTvXFD9gHPn2TZPF3ntI2ecxVrW5MrV XiCie5EeNa7BlWu/HNSkprDUva163PHxAv5jyGV7gVzyAghSKOTnat85UIYFICXbD2NV9rRiv0BS tKQsg6OHH4A15F1WW+UHKHHa32h6aPnAm3/pUcWp+WYnTQAAAABJRU5ErkJggg== In-Reply-To: <87k62b9il8.fsf@pacem.orebokech.com> (Romain Francoise's message of "Sat\, 04 Nov 2006 19\:23\:31 +0100") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.90 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:61819 Archived-At: --===============0490424096== Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Romain Francoise writes: > michael@cadilhac.name (Micha=EBl 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. --=-=-= Content-Type: text/x-patch; charset=iso-8859-1 Content-Disposition: inline; filename=battery.patch Content-Transfer-Encoding: quoted-printable Index: lisp/battery.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 =2D-- 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=20=20 ! (with-temp-buffer=20 (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) (> (buffer-size) 0))) (error nil))) =2D-- 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")) =2D-- 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) !=20 "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) !=20 "N/A")) (cons ?r (or (and rate (concat (number-to-string rate) " " rate-type)) "N/A")) *************** *** 478,483 **** =2D-- 452,468 ---- (or (cdr (assoc char alist)) "")))) format t t)) =20=20 + (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))))))) +=20 (provide 'battery) =20=20 Index: lisp/ChangeLog =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 =2D-- lisp/ChangeLog 5 Nov 2006 12:46:41 -0000 *************** *** 0 **** =2D-- 1,8 ---- + 2006-10-31 Micha=EBl Cadilhac +=20 + * 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. +=20 --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable =2D-=20 /!\ My mail address changed, please update your files accordingly. | Micha=EBl `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 --' - -= -' --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQFFTd6yUJhDmOfFA3URAvK5AJ4yAEjTKaK+kiBy0M3AfQTHsL49YwCeL5Ol Rmqwcgjl1yYlHIrbpimTQIM= =gQQ5 -----END PGP SIGNATURE----- --==-=-=-- --===============0490424096== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --===============0490424096==--