all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: michael@cadilhac.name (Michaël Cadilhac)
Subject: Proposal for battery.el
Date: Tue, 31 Oct 2006 16:54:52 +0100	[thread overview]
Message-ID: <87lkmwpjjn.fsf@lrde.org> (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

             reply	other threads:[~2006-10-31 15:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-31 15:54 Michaël Cadilhac [this message]
     [not found] ` <E1GfkPb-0007PW-V9@fencepost.gnu.org>
2006-11-02 22:02   ` Proposal for battery.el 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lkmwpjjn.fsf@lrde.org \
    --to=michael@cadilhac.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.