Mercurial > emacs
comparison lisp/battery.el @ 73700:294b1de9ac5f
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.
author | Romain Francoise <romain@orebokech.com> |
---|---|
date | Sun, 05 Nov 2006 13:22:30 +0000 |
parents | 65d9fbabd719 |
children | 685bae49b575 02cf29720f31 |
comparison
equal
deleted
inserted
replaced
73699:164c2027bc04 | 73700:294b1de9ac5f |
---|---|
47 'battery-linux-proc-apm) | 47 'battery-linux-proc-apm) |
48 ((and (eq system-type 'gnu/linux) | 48 ((and (eq system-type 'gnu/linux) |
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))) |
57 'battery-pmset)) | 57 'battery-pmset)) |
58 "*Function for getting battery status information. | 58 "*Function for getting battery status information. |
353 capacity)) | 353 capacity)) |
354 rate) | 354 rate) |
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")) |
400 (cons ?B (or charging-state "N/A")) | 374 (cons ?B (or charging-state "N/A")) |
401 (cons ?b (or (and (string= charging-state "charging") "+") | 375 (cons ?b (or (and (string= charging-state "charging") "+") |
477 (let ((char (aref str 1))) | 451 (let ((char (aref str 1))) |
478 (if (eq char ?%) "%" | 452 (if (eq char ?%) "%" |
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. | |
458 If a match occured, return the parenthesized expression numbered by | |
459 MATCH-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 |
485 ;; arch-tag: 65916f50-4754-4b6b-ac21-0b510f545a37 | 470 ;; arch-tag: 65916f50-4754-4b6b-ac21-0b510f545a37 |
486 ;;; battery.el ends here | 471 ;;; battery.el ends here |