Mercurial > emacs
annotate lisp/battery.el @ 94973:c7204aaea55b
*** empty log message ***
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Wed, 14 May 2008 15:24:21 +0000 |
parents | ee5932bf781d |
children | a7ddf766669d |
rev | line source |
---|---|
93207
ba8704a0f1e5
Add file cookie coding:iso-8859-1 for the degree sign
Juri Linkov <juri@jurta.org>
parents:
79721
diff
changeset
|
1 ;;; battery.el --- display battery status information -*- coding: iso-8859-1 -*- |
18388 | 2 |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64094
diff
changeset
|
3 ;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004, |
79721 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
18388 | 5 |
30110
23cb074f9d88
Change author's mail address.
Gerd Moellmann <gerd@gnu.org>
parents:
26828
diff
changeset
|
6 ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org> |
20972
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
7 ;; Keywords: hardware |
18388 | 8 |
18685
4f3350c88e6c
Fix copyright and copying permissions.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
18388 | 10 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94449
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
18388 | 12 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94449
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94449
diff
changeset
|
14 ;; (at your option) any later version. |
18388 | 15 |
18685
4f3350c88e6c
Fix copyright and copying permissions.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
18388 | 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94449
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
18388 | 23 |
24 ;;; Commentary: | |
25 | |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
26 ;; There is at present support for GNU/Linux, OS X and Windows. This |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
27 ;; library supports both the `/proc/apm' file format of Linux version |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
28 ;; 1.3.58 or newer and the `/proc/acpi/' directory structure of Linux |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
29 ;; 2.4.20 and 2.6. Darwin (OS X) is supported by using the `pmset' |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
30 ;; program. Windows is supported by the GetSystemPowerStatus API call. |
18388 | 31 |
32 ;;; Code: | |
33 | |
34 (require 'timer) | |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
35 (eval-when-compile (require 'cl)) |
18388 | 36 |
37 | |
21088 | 38 (defgroup battery nil |
39 "Display battery status information." | |
40 :prefix "battery-" | |
41 :group 'hardware) | |
42 | |
43 (defcustom battery-status-function | |
18388 | 44 (cond ((and (eq system-type 'gnu/linux) |
45 (file-readable-p "/proc/apm")) | |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
46 'battery-linux-proc-apm) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
47 ((and (eq system-type 'gnu/linux) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
48 (file-directory-p "/proc/acpi/battery")) |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
49 'battery-linux-proc-acpi) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
50 ((and (eq system-type 'darwin) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
51 (condition-case nil |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
52 (with-temp-buffer |
64907
08b55dc9bcd1
(battery-status-function): Don't use ignore-errors.
Lute Kamstra <lute@gnu.org>
parents:
64762
diff
changeset
|
53 (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) |
08b55dc9bcd1
(battery-status-function): Don't use ignore-errors.
Lute Kamstra <lute@gnu.org>
parents:
64762
diff
changeset
|
54 (> (buffer-size) 0))) |
08b55dc9bcd1
(battery-status-function): Don't use ignore-errors.
Lute Kamstra <lute@gnu.org>
parents:
64762
diff
changeset
|
55 (error nil))) |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
56 'battery-pmset) |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
57 ((eq system-type 'windows-nt) |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
58 'w32-battery-status)) |
18388 | 59 "*Function for getting battery status information. |
36090
9ed7c3f74e35
(battery-status-function): Fix doc, :type.
Dave Love <fx@gnu.org>
parents:
32356
diff
changeset
|
60 The function has to return an alist of conversion definitions. |
9ed7c3f74e35
(battery-status-function): Fix doc, :type.
Dave Love <fx@gnu.org>
parents:
32356
diff
changeset
|
61 Its cons cells are of the form |
18388 | 62 |
63 (CONVERSION . REPLACEMENT-TEXT) | |
64 | |
65 CONVERSION is the character code of a \"conversion specification\" | |
21088 | 66 introduced by a `%' character in a control string." |
36090
9ed7c3f74e35
(battery-status-function): Fix doc, :type.
Dave Love <fx@gnu.org>
parents:
32356
diff
changeset
|
67 :type '(choice (const nil) function) |
21088 | 68 :group 'battery) |
18388 | 69 |
21088 | 70 (defcustom battery-echo-area-format |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
71 (cond ((eq battery-status-function 'battery-linux-proc-acpi) |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
72 "Power %L, battery %B at %r (%p%% load, remaining time %t)") |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
73 ((eq battery-status-function 'battery-pmset) |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
74 "%L power, battery %B (%p%% load, remaining time %t)") |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
75 (battery-status-function |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
76 "Power %L, battery %B (%p%% load, remaining time %t)")) |
18388 | 77 "*Control string formatting the string to display in the echo area. |
78 Ordinary characters in the control string are printed as-is, while | |
79 conversion specifications introduced by a `%' character in the control | |
80 string are substituted as defined by the current value of the variable | |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
81 `battery-status-function'. Here are the ones generally available: |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
82 %c Current capacity (mAh or mWh) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
83 %r Current rate of charge or discharge |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
84 %B Battery status (verbose) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
85 %b Battery status: empty means high, `-' means low, |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
86 `!' means critical, and `+' means charging |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
87 %d Temperature (in degrees Celsius) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
88 %L AC line status (verbose) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
89 %p Battery load percentage |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
90 %m Remaining time (to charge or discharge) in minutes |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
91 %h Remaining time (to charge or discharge) in hours |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
92 %t Remaining time (to charge or discharge) in the form `h:min'" |
21088 | 93 :type '(choice string (const nil)) |
94 :group 'battery) | |
18388 | 95 |
96 (defvar battery-mode-line-string nil | |
97 "String to display in the mode line.") | |
59132
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
98 ;;;###autoload (put 'battery-mode-line-string 'risky-local-variable t) |
18388 | 99 |
21088 | 100 (defcustom battery-mode-line-format |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
101 (cond ((eq battery-status-function 'battery-linux-proc-acpi) |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
102 "[%b%p%%,%d°C]") |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
103 (battery-status-function |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
104 "[%b%p%%]")) |
18388 | 105 "*Control string formatting the string to display in the mode line. |
106 Ordinary characters in the control string are printed as-is, while | |
107 conversion specifications introduced by a `%' character in the control | |
108 string are substituted as defined by the current value of the variable | |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
109 `battery-status-function'. Here are the ones generally available: |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
110 %c Current capacity (mAh or mWh) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
111 %r Current rate of charge or discharge |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
112 %B Battery status (verbose) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
113 %b Battery status: empty means high, `-' means low, |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
114 `!' means critical, and `+' means charging |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
115 %d Temperature (in degrees Celsius) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
116 %L AC line status (verbose) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
117 %p Battery load percentage |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
118 %m Remaining time (to charge or discharge) in minutes |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
119 %h Remaining time (to charge or discharge) in hours |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
120 %t Remaining time (to charge or discharge) in the form `h:min'" |
21088 | 121 :type '(choice string (const nil)) |
122 :group 'battery) | |
18388 | 123 |
21088 | 124 (defcustom battery-update-interval 60 |
125 "*Seconds after which the battery status will be updated." | |
126 :type 'integer | |
127 :group 'battery) | |
18388 | 128 |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
129 (defcustom battery-load-low 25 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
130 "*Upper bound of low battery load percentage. |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
131 A battery load percentage below this number is considered low." |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
132 :type 'integer |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
133 :group 'battery) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
134 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
135 (defcustom battery-load-critical 10 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
136 "*Upper bound of critical battery load percentage. |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
137 A battery load percentage below this number is considered critical." |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
138 :type 'integer |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
139 :group 'battery) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
140 |
18388 | 141 (defvar battery-update-timer nil |
142 "Interval timer object.") | |
143 | |
21076
dc82196eac58
Fixed spelling of `autoload' magic cookies.
Richard M. Stallman <rms@gnu.org>
parents:
20972
diff
changeset
|
144 ;;;###autoload |
18388 | 145 (defun battery () |
146 "Display battery status information in the echo area. | |
26828 | 147 The text being displayed in the echo area is controlled by the variables |
18388 | 148 `battery-echo-area-format' and `battery-status-function'." |
149 (interactive) | |
150 (message "%s" (if (and battery-echo-area-format battery-status-function) | |
151 (battery-format battery-echo-area-format | |
152 (funcall battery-status-function)) | |
153 "Battery status not available"))) | |
154 | |
21076
dc82196eac58
Fixed spelling of `autoload' magic cookies.
Richard M. Stallman <rms@gnu.org>
parents:
20972
diff
changeset
|
155 ;;;###autoload |
59363
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
156 (define-minor-mode display-battery-mode |
18388 | 157 "Display battery status information in the mode line. |
32346
fa3f5e8f6201
(display-battery): Doc spelling fix.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
30110
diff
changeset
|
158 The text being displayed in the mode line is controlled by the variables |
18388 | 159 `battery-mode-line-format' and `battery-status-function'. |
160 The mode line will be updated automatically every `battery-update-interval' | |
161 seconds." | |
61268
abd0d265b4ba
(display-battery-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents:
59363
diff
changeset
|
162 :global t :group 'battery |
18388 | 163 (setq battery-mode-line-string "") |
164 (or global-mode-string (setq global-mode-string '(""))) | |
165 (and battery-update-timer (cancel-timer battery-update-timer)) | |
59363
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
166 (if (not display-battery-mode) |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
167 (setq global-mode-string |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
168 (delq 'battery-mode-line-string global-mode-string)) |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
169 (add-to-list 'global-mode-string 'battery-mode-line-string t) |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
170 (setq battery-update-timer (run-at-time nil battery-update-interval |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
171 'battery-update-handler)) |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
172 (battery-update))) |
18388 | 173 |
174 (defun battery-update-handler () | |
175 (battery-update) | |
176 (sit-for 0)) | |
177 | |
178 (defun battery-update () | |
179 "Update battery status information in the mode line." | |
59132
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
180 (setq battery-mode-line-string |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
181 (propertize (if (and battery-mode-line-format |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
182 battery-status-function) |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
183 (battery-format |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
184 battery-mode-line-format |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
185 (funcall battery-status-function)) |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
186 "") |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
187 'help-echo "Battery status information")) |
18388 | 188 (force-mode-line-update)) |
189 | |
190 | |
191 ;;; `/proc/apm' interface for Linux. | |
192 | |
193 (defconst battery-linux-proc-apm-regexp | |
194 (concat "^\\([^ ]+\\)" ; Driver version. | |
195 " \\([^ ]+\\)" ; APM BIOS version. | |
196 " 0x\\([0-9a-f]+\\)" ; APM BIOS flags. | |
197 " 0x\\([0-9a-f]+\\)" ; AC line status. | |
198 " 0x\\([0-9a-f]+\\)" ; Battery status. | |
199 " 0x\\([0-9a-f]+\\)" ; Battery flags. | |
20972
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
200 " \\(-?[0-9]+\\)%" ; Load percentage. |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
201 " \\(-?[0-9]+\\)" ; Remaining time. |
18388 | 202 " \\(.*\\)" ; Time unit. |
203 "$") | |
204 "Regular expression matching contents of `/proc/apm'.") | |
205 | |
206 (defun battery-linux-proc-apm () | |
207 "Get APM status information from Linux kernel. | |
208 This function works only with the new `/proc/apm' format introduced | |
209 in Linux version 1.3.58. | |
210 | |
211 The following %-sequences are provided: | |
212 %v Linux driver version | |
213 %V APM BIOS version | |
214 %I APM BIOS status (verbose) | |
215 %L AC line status (verbose) | |
216 %B Battery status (verbose) | |
217 %b Battery status, empty means high, `-' means low, | |
218 `!' means critical, and `+' means charging | |
63899
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
219 %p Battery load percentage |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
220 %s Remaining time (to charge or discharge) in seconds |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
221 %m Remaining time (to charge or discharge) in minutes |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
222 %h Remaining time (to charge or discharge) in hours |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
223 %t Remaining time (to charge or discharge) in the form `h:min'" |
18388 | 224 (let (driver-version bios-version bios-interface line-status |
225 battery-status battery-status-symbol load-percentage | |
63899
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
226 seconds minutes hours remaining-time tem) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
227 (with-temp-buffer |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
228 (ignore-errors (insert-file-contents "/proc/apm")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
229 (when (re-search-forward battery-linux-proc-apm-regexp) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
230 (setq driver-version (match-string 1)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
231 (setq bios-version (match-string 2)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
232 (setq tem (string-to-number (match-string 3) 16)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
233 (if (not (logand tem 2)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
234 (setq bios-interface "not supported") |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
235 (setq bios-interface "enabled") |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
236 (cond ((logand tem 16) (setq bios-interface "disabled")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
237 ((logand tem 32) (setq bios-interface "disengaged"))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
238 (setq tem (string-to-number (match-string 4) 16)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
239 (cond ((= tem 0) (setq line-status "off-line")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
240 ((= tem 1) (setq line-status "on-line")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
241 ((= tem 2) (setq line-status "on backup"))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
242 (setq tem (string-to-number (match-string 6) 16)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
243 (if (= tem 255) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
244 (setq battery-status "N/A") |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
245 (setq tem (string-to-number (match-string 5) 16)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
246 (cond ((= tem 0) (setq battery-status "high" |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
247 battery-status-symbol "")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
248 ((= tem 1) (setq battery-status "low" |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
249 battery-status-symbol "-")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
250 ((= tem 2) (setq battery-status "critical" |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
251 battery-status-symbol "!")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
252 ((= tem 3) (setq battery-status "charging" |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
253 battery-status-symbol "+"))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
254 (setq load-percentage (match-string 7)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
255 (setq seconds (string-to-number (match-string 8))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
256 (and (string-equal (match-string 9) "min") |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
257 (setq seconds (* 60 seconds))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
258 (setq minutes (/ seconds 60) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
259 hours (/ seconds 3600)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
260 (setq remaining-time |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
261 (format "%d:%02d" hours (- minutes (* 60 hours)))))))) |
20972
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
262 (list (cons ?v (or driver-version "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
263 (cons ?V (or bios-version "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
264 (cons ?I (or bios-interface "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
265 (cons ?L (or line-status "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
266 (cons ?B (or battery-status "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
267 (cons ?b (or battery-status-symbol "")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
268 (cons ?p (or load-percentage "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
269 (cons ?s (or (and seconds (number-to-string seconds)) "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
270 (cons ?m (or (and minutes (number-to-string minutes)) "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
271 (cons ?h (or (and hours (number-to-string hours)) "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
272 (cons ?t (or remaining-time "N/A"))))) |
18388 | 273 |
274 | |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
275 ;;; `/proc/acpi/' interface for Linux. |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
276 |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
277 (defun battery-linux-proc-acpi () |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
278 "Get ACPI status information from Linux kernel. |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
279 This function works only with the new `/proc/acpi/' format introduced |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
280 in Linux version 2.4.20 and 2.6.0. |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
281 |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
282 The following %-sequences are provided: |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
283 %c Current capacity (mAh) |
63899
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
284 %r Current rate |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
285 %B Battery status (verbose) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
286 %b Battery status, empty means high, `-' means low, |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
287 `!' means critical, and `+' means charging |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
288 %d Temperature (in degrees Celsius) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
289 %L AC line status (verbose) |
63899
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
290 %p Battery load percentage |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
291 %m Remaining time (to charge or discharge) in minutes |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
292 %h Remaining time (to charge or discharge) in hours |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
293 %t Remaining time (to charge or discharge) in the form `h:min'" |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
294 (let ((design-capacity 0) |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
295 (last-full-capacity 0) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
296 full-capacity |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
297 (warn 0) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
298 (low 0) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
299 capacity rate rate-type charging-state minutes hours) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
300 ;; ACPI provides information about each battery present in the system in |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
301 ;; a separate subdirectory. We are going to merge the available |
57133
fd1a6df8927e
Delete superfluous empty lines.
Eli Zaretskii <eliz@gnu.org>
parents:
56663
diff
changeset
|
302 ;; information together since displaying for a variable amount of |
fd1a6df8927e
Delete superfluous empty lines.
Eli Zaretskii <eliz@gnu.org>
parents:
56663
diff
changeset
|
303 ;; batteries seems overkill for format-strings. |
fd1a6df8927e
Delete superfluous empty lines.
Eli Zaretskii <eliz@gnu.org>
parents:
56663
diff
changeset
|
304 (with-temp-buffer |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
305 (dolist (dir (ignore-errors (directory-files "/proc/acpi/battery/" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
306 t "\\`[^.]"))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
307 (erase-buffer) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
308 (ignore-errors (insert-file-contents (expand-file-name "state" dir))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
309 (when (re-search-forward "present: +yes$" nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
310 (and (re-search-forward "charging state: +\\(.*\\)$" nil t) |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
311 (member charging-state '("unknown" "charged" nil)) |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
312 ;; On most multi-battery systems, most of the time only one |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
313 ;; battery is "charging"/"discharging", the others are |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
314 ;; "unknown". |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
315 (setq charging-state (match-string 1))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
316 (when (re-search-forward "present rate: +\\([0-9]+\\) \\(m[AW]\\)$" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
317 nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
318 (setq rate (+ (or rate 0) (string-to-number (match-string 1))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
319 rate-type (or (and rate-type |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
320 (if (string= rate-type (match-string 2)) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
321 rate-type |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
322 (error |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
323 "Inconsistent rate types (%s vs. %s)" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
324 rate-type (match-string 2)))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
325 (match-string 2)))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
326 (when (re-search-forward "remaining capacity: +\\([0-9]+\\) m[AW]h$" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
327 nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
328 (setq capacity |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
329 (+ (or capacity 0) (string-to-number (match-string 1)))))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
330 (goto-char (point-max)) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
331 (ignore-errors (insert-file-contents (expand-file-name "info" dir))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
332 (when (re-search-forward "present: +yes$" nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
333 (when (re-search-forward "design capacity: +\\([0-9]+\\) m[AW]h$" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
334 nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
335 (incf design-capacity (string-to-number (match-string 1)))) |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
336 (when (re-search-forward "last full capacity: +\\([0-9]+\\) m[AW]h$" |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
337 nil t) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
338 (incf last-full-capacity (string-to-number (match-string 1)))) |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
339 (when (re-search-forward |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
340 "design capacity warning: +\\([0-9]+\\) m[AW]h$" nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
341 (incf warn (string-to-number (match-string 1)))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
342 (when (re-search-forward "design capacity low: +\\([0-9]+\\) m[AW]h$" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
343 nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
344 (incf low (string-to-number (match-string 1))))))) |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
345 (setq full-capacity (if (> last-full-capacity 0) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
346 last-full-capacity design-capacity)) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
347 (and capacity rate |
55904
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
348 (setq minutes (if (zerop rate) 0 |
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
349 (floor (* (/ (float (if (string= charging-state |
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
350 "charging") |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
351 (- full-capacity capacity) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
352 capacity)) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
353 rate) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
354 60))) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
355 hours (/ minutes 60))) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
356 (list (cons ?c (or (and capacity (number-to-string capacity)) "N/A")) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
357 (cons ?L (or (battery-search-for-one-match-in-files |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
358 (mapcar (lambda (e) (concat e "/state")) |
75178
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
359 (ignore-errors |
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
360 (directory-files "/proc/acpi/ac_adapter/" |
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
361 t "\\`[^.]"))) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
362 "state: +\\(.*\\)$" 1) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
363 |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
364 "N/A")) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
365 (cons ?d (or (battery-search-for-one-match-in-files |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
366 (mapcar (lambda (e) (concat e "/temperature")) |
75178
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
367 (ignore-errors |
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
368 (directory-files "/proc/acpi/thermal_zone/" |
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
369 t "\\`[^.]"))) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
370 "temperature: +\\([0-9]+\\) C$" 1) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
371 |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
372 "N/A")) |
55904
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
373 (cons ?r (or (and rate (concat (number-to-string rate) " " |
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
374 rate-type)) "N/A")) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
375 (cons ?B (or charging-state "N/A")) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
376 (cons ?b (or (and (string= charging-state "charging") "+") |
69414
a159957988d5
(battery-linux-proc-acpi): Check `capacity' for non-nil
Juri Linkov <juri@jurta.org>
parents:
69381
diff
changeset
|
377 (and capacity (< capacity low) "!") |
a159957988d5
(battery-linux-proc-acpi): Check `capacity' for non-nil
Juri Linkov <juri@jurta.org>
parents:
69381
diff
changeset
|
378 (and capacity (< capacity warn) "-") |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
379 "")) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
380 (cons ?h (or (and hours (number-to-string hours)) "N/A")) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
381 (cons ?m (or (and minutes (number-to-string minutes)) "N/A")) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
382 (cons ?t (or (and minutes |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
383 (format "%d:%02d" hours (- minutes (* 60 hours)))) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
384 "N/A")) |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
385 (cons ?p (or (and full-capacity capacity |
73599
65d9fbabd719
* battery.el (battery-linux-proc-acpi): Prevent range error when
Chong Yidong <cyd@stupidchicken.com>
parents:
70539
diff
changeset
|
386 (> full-capacity 0) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
387 (number-to-string |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
388 (floor (/ capacity |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
389 (/ (float full-capacity) 100))))) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
390 "N/A"))))) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
391 |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
392 |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
393 ;;; `pmset' interface for Darwin (OS X). |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
394 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
395 (defun battery-pmset () |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
396 "Get battery status information using `pmset'. |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
397 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
398 The following %-sequences are provided: |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
399 %L Power source (verbose) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
400 %B Battery status (verbose) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
401 %b Battery status, empty means high, `-' means low, |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
402 `!' means critical, and `+' means charging |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
403 %p Battery load percentage |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
404 %h Remaining time in hours |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
405 %m Remaining time in minutes |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
406 %t Remaining time in the form `h:min'" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
407 (let (power-source load-percentage battery-status battery-status-symbol |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
408 remaining-time hours minutes) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
409 (with-temp-buffer |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
410 (ignore-errors (call-process "pmset" nil t nil "-g" "ps")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
411 (goto-char (point-min)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
412 (when (re-search-forward "Currentl?y drawing from '\\(AC\\|Battery\\) Power'" nil t) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
413 (setq power-source (match-string 1)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
414 (when (re-search-forward "^ -InternalBattery-0[ \t]+" nil t) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
415 (when (looking-at "\\([0-9]\\{1,3\\}\\)%") |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
416 (setq load-percentage (match-string 1)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
417 (goto-char (match-end 0)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
418 (cond ((looking-at "; charging") |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
419 (setq battery-status "charging" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
420 battery-status-symbol "+")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
421 ((< (string-to-number load-percentage) battery-load-low) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
422 (setq battery-status "low" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
423 battery-status-symbol "-")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
424 ((< (string-to-number load-percentage) battery-load-critical) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
425 (setq battery-status "critical" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
426 battery-status-symbol "!")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
427 (t |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
428 (setq battery-status "high" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
429 battery-status-symbol ""))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
430 (when (re-search-forward "\\(\\([0-9]+\\):\\([0-9]+\\)\\) remaining" nil t) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
431 (setq remaining-time (match-string 1)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
432 (let ((h (string-to-number (match-string 2))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
433 (m (string-to-number (match-string 3)))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
434 (setq hours (number-to-string (+ h (if (< m 30) 0 1))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
435 minutes (number-to-string (+ (* h 60) m))))))))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
436 (list (cons ?L (or power-source "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
437 (cons ?p (or load-percentage "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
438 (cons ?B (or battery-status "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
439 (cons ?b (or battery-status-symbol "")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
440 (cons ?h (or hours "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
441 (cons ?m (or minutes "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
442 (cons ?t (or remaining-time "N/A"))))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
443 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
444 |
18388 | 445 ;;; Private functions. |
446 | |
447 (defun battery-format (format alist) | |
448 "Substitute %-sequences in FORMAT." | |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
449 (replace-regexp-in-string |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
450 "%." |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
451 (lambda (str) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
452 (let ((char (aref str 1))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
453 (if (eq char ?%) "%" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
454 (or (cdr (assoc char alist)) "")))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
455 format t t)) |
18388 | 456 |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
457 (defun battery-search-for-one-match-in-files (files regexp match-num) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
458 "Search REGEXP in the content of the files listed in FILES. |
75139
685bae49b575
(battery-search-for-one-match-in-files): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
73700
diff
changeset
|
459 If a match occurred, return the parenthesized expression numbered by |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
460 MATCH-NUM in the match. Otherwise, return nil." |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
461 (with-temp-buffer |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
462 (catch 'found |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
463 (dolist (file files) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
464 (and (ignore-errors (insert-file-contents file nil nil nil 'replace)) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
465 (re-search-forward regexp nil t) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
466 (throw 'found (match-string match-num))))))) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
467 |
18388 | 468 |
469 (provide 'battery) | |
470 | |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
471 ;; arch-tag: 65916f50-4754-4b6b-ac21-0b510f545a37 |
18388 | 472 ;;; battery.el ends here |