aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Francoise2006-11-05 13:22:30 +0000
committerRomain Francoise2006-11-05 13:22:30 +0000
commit785428c709c8c0c292909785aa84ea469e50bdb3 (patch)
tree8ca72d596bbfbe9e84406fc9c31b4d0fad0bedd8
parent107709d449c2488ccb802f59449391b25aab6dc6 (diff)
downloademacs-785428c709c8c0c292909785aa84ea469e50bdb3.tar.gz
emacs-785428c709c8c0c292909785aa84ea469e50bdb3.zip
2006-11-05 Micha�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.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/battery.el65
2 files changed, 33 insertions, 40 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5d1136a945f..b699521bf4b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12006-11-05 Micha,Ak(Bl Cadilhac <michael.cadilhac@lrde.org>
2
3 * battery.el (battery-linux-proc-acpi): Search an ac_adapter in
4 `/proc/acpi/ac_adapter/*'. Ditto for the thermometers in
5 `/proc/acpi/thermal_zone/*'.
6 (battery-search-for-one-match-in-files): New. Search a regexp in
7 the content of some files.
8
12006-11-05 Martin Rudalics <rudalics@gmx.at> 92006-11-05 Martin Rudalics <rudalics@gmx.at>
2 10
3 * window.el (mouse-autoselect-window-now): Remove variable. 11 * window.el (mouse-autoselect-window-now): Remove variable.
diff --git a/lisp/battery.el b/lisp/battery.el
index ec35e04e1ab..a4c72df0bbb 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -49,8 +49,8 @@
49 (file-directory-p "/proc/acpi/battery")) 49 (file-directory-p "/proc/acpi/battery"))
50 'battery-linux-proc-acpi) 50 'battery-linux-proc-acpi)
51 ((and (eq system-type 'darwin) 51 ((and (eq system-type 'darwin)
52 (condition-case nil 52 (condition-case nil
53 (with-temp-buffer 53 (with-temp-buffer
54 (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) 54 (and (eq (call-process "pmset" nil t nil "-g" "ps") 0)
55 (> (buffer-size) 0))) 55 (> (buffer-size) 0)))
56 (error nil))) 56 (error nil)))
@@ -355,45 +355,19 @@ The following %-sequences are provided:
355 60))) 355 60)))
356 hours (/ minutes 60))) 356 hours (/ minutes 60)))
357 (list (cons ?c (or (and capacity (number-to-string capacity)) "N/A")) 357 (list (cons ?c (or (and capacity (number-to-string capacity)) "N/A"))
358 (cons ?L (or (when (file-exists-p "/proc/acpi/ac_adapter/AC/state") 358 (cons ?L (or (battery-search-for-one-match-in-files
359 (with-temp-buffer 359 (mapcar (lambda (e) (concat e "/state"))
360 (insert-file-contents 360 (directory-files "/proc/acpi/ac_adapter/"
361 "/proc/acpi/ac_adapter/AC/state") 361 t "\\`[^.]"))
362 (when (re-search-forward "state: +\\(.*\\)$" nil t) 362 "state: +\\(.*\\)$" 1)
363 (match-string 1)))) 363
364 "N/A")) 364 "N/A"))
365 (cons ?d (or (when (file-exists-p 365 (cons ?d (or (battery-search-for-one-match-in-files
366 "/proc/acpi/thermal_zone/THRM/temperature") 366 (mapcar (lambda (e) (concat e "/temperature"))
367 (with-temp-buffer 367 (directory-files "/proc/acpi/thermal_zone/"
368 (insert-file-contents 368 t "\\`[^.]"))
369 "/proc/acpi/thermal_zone/THRM/temperature") 369 "temperature: +\\([0-9]+\\) C$" 1)
370 (when (re-search-forward 370
371 "temperature: +\\([0-9]+\\) C$" nil t)
372 (match-string 1))))
373 (when (file-exists-p
374 "/proc/acpi/thermal_zone/THM/temperature")
375 (with-temp-buffer
376 (insert-file-contents
377 "/proc/acpi/thermal_zone/THM/temperature")
378 (when (re-search-forward
379 "temperature: +\\([0-9]+\\) C$" nil t)
380 (match-string 1))))
381 (when (file-exists-p
382 "/proc/acpi/thermal_zone/THM0/temperature")
383 (with-temp-buffer
384 (insert-file-contents
385 "/proc/acpi/thermal_zone/THM0/temperature")
386 (when (re-search-forward
387 "temperature: +\\([0-9]+\\) C$" nil t)
388 (match-string 1))))
389 (when (file-exists-p
390 "/proc/acpi/thermal_zone/THR2/temperature")
391 (with-temp-buffer
392 (insert-file-contents
393 "/proc/acpi/thermal_zone/THR2/temperature")
394 (when (re-search-forward
395 "temperature: +\\([0-9]+\\) C$" nil t)
396 (match-string 1))))
397 "N/A")) 371 "N/A"))
398 (cons ?r (or (and rate (concat (number-to-string rate) " " 372 (cons ?r (or (and rate (concat (number-to-string rate) " "
399 rate-type)) "N/A")) 373 rate-type)) "N/A"))
@@ -479,6 +453,17 @@ The following %-sequences are provided:
479 (or (cdr (assoc char alist)) "")))) 453 (or (cdr (assoc char alist)) ""))))
480 format t t)) 454 format t t))
481 455
456(defun battery-search-for-one-match-in-files (files regexp match-num)
457 "Search REGEXP in the content of the files listed in FILES.
458If a match occured, return the parenthesized expression numbered by
459MATCH-NUM in the match. Otherwise, return nil."
460 (with-temp-buffer
461 (catch 'found
462 (dolist (file files)
463 (and (ignore-errors (insert-file-contents file nil nil nil 'replace))
464 (re-search-forward regexp nil t)
465 (throw 'found (match-string match-num)))))))
466
482 467
483(provide 'battery) 468(provide 'battery)
484 469