diff options
| author | Eli Zaretskii | 2004-09-18 11:50:18 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2004-09-18 11:50:18 +0000 |
| commit | d66fe3340cdd422dbb07a4a7f33a8830d85144e9 (patch) | |
| tree | aa66d95fb514b051af986629446e88e75e77e3a3 | |
| parent | 5dc59f2e6264116c628100d28da4df8725910c5a (diff) | |
| download | emacs-d66fe3340cdd422dbb07a4a7f33a8830d85144e9.tar.gz emacs-d66fe3340cdd422dbb07a4a7f33a8830d85144e9.zip | |
Delete superfluous empty lines.
(battery-linux-proc-acpi): Attempt to gather information from all
battery subdirectories regardless of their file name.
(battery-linux-proc-apm): Replace all occurrences of
battery-hex-to-int-2 with string-to-int (base 16).
(battery-hex-to-int-2, battery-hex-to-int): Delete functions.
(battery-hex-map): Delete variable.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/battery.el | 137 |
2 files changed, 70 insertions, 77 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3f85d16834c..6fd4579c785 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2004-09-18 Ralph Schleicher <rs@nunatak.allgaeu.org> | ||
| 2 | |||
| 3 | * battery.el: Delete superfluous empty lines. | ||
| 4 | (battery-linux-proc-acpi): Attempt to gather information from all | ||
| 5 | battery subdirectories regardless of their file name. | ||
| 6 | (battery-linux-proc-apm): Replace all occurrences of | ||
| 7 | battery-hex-to-int-2 with string-to-int (base 16). | ||
| 8 | (battery-hex-to-int-2, battery-hex-to-int): Delete functions. | ||
| 9 | (battery-hex-map): Delete variable. | ||
| 10 | |||
| 1 | 2004-09-18 John Paul Wallington <jpw@gnu.org> | 11 | 2004-09-18 John Paul Wallington <jpw@gnu.org> |
| 2 | 12 | ||
| 3 | * calc/calc-units.el (calc-quick-units): Fix overzealous | 13 | * calc/calc-units.el (calc-quick-units): Fix overzealous |
diff --git a/lisp/battery.el b/lisp/battery.el index 3b44ff891f9..2c7254be939 100644 --- a/lisp/battery.el +++ b/lisp/battery.el | |||
| @@ -33,7 +33,6 @@ | |||
| 33 | (require 'timer) | 33 | (require 'timer) |
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | |||
| 37 | (defgroup battery nil | 36 | (defgroup battery nil |
| 38 | "Display battery status information." | 37 | "Display battery status information." |
| 39 | :prefix "battery-" | 38 | :prefix "battery-" |
| @@ -182,20 +181,20 @@ The following %-sequences are provided: | |||
| 182 | (re-search-forward battery-linux-proc-apm-regexp) | 181 | (re-search-forward battery-linux-proc-apm-regexp) |
| 183 | (setq driver-version (match-string 1)) | 182 | (setq driver-version (match-string 1)) |
| 184 | (setq bios-version (match-string 2)) | 183 | (setq bios-version (match-string 2)) |
| 185 | (setq tem (battery-hex-to-int-2 (match-string 3))) | 184 | (setq tem (string-to-int (match-string 3) 16)) |
| 186 | (if (not (logand tem 2)) | 185 | (if (not (logand tem 2)) |
| 187 | (setq bios-interface "not supported") | 186 | (setq bios-interface "not supported") |
| 188 | (setq bios-interface "enabled") | 187 | (setq bios-interface "enabled") |
| 189 | (cond ((logand tem 16) (setq bios-interface "disabled")) | 188 | (cond ((logand tem 16) (setq bios-interface "disabled")) |
| 190 | ((logand tem 32) (setq bios-interface "disengaged"))) | 189 | ((logand tem 32) (setq bios-interface "disengaged"))) |
| 191 | (setq tem (battery-hex-to-int-2 (match-string 4))) | 190 | (setq tem (string-to-int (match-string 4) 16)) |
| 192 | (cond ((= tem 0) (setq line-status "off-line")) | 191 | (cond ((= tem 0) (setq line-status "off-line")) |
| 193 | ((= tem 1) (setq line-status "on-line")) | 192 | ((= tem 1) (setq line-status "on-line")) |
| 194 | ((= tem 2) (setq line-status "on backup"))) | 193 | ((= tem 2) (setq line-status "on backup"))) |
| 195 | (setq tem (battery-hex-to-int-2 (match-string 6))) | 194 | (setq tem (string-to-int (match-string 6) 16)) |
| 196 | (if (= tem 255) | 195 | (if (= tem 255) |
| 197 | (setq battery-status "N/A") | 196 | (setq battery-status "N/A") |
| 198 | (setq tem (battery-hex-to-int-2 (match-string 5))) | 197 | (setq tem (string-to-int (match-string 5) 16)) |
| 199 | (cond ((= tem 0) (setq battery-status "high" | 198 | (cond ((= tem 0) (setq battery-status "high" |
| 200 | battery-status-symbol "")) | 199 | battery-status-symbol "")) |
| 201 | ((= tem 1) (setq battery-status "low" | 200 | ((= tem 1) (setq battery-status "low" |
| @@ -245,52 +244,62 @@ The following %-sequences are provided: | |||
| 245 | %t Remaining time in the form `h:min'" | 244 | %t Remaining time in the form `h:min'" |
| 246 | (let (capacity design-capacity rate rate-type charging-state warn low | 245 | (let (capacity design-capacity rate rate-type charging-state warn low |
| 247 | minutes hours) | 246 | minutes hours) |
| 248 | (when (file-directory-p "/proc/acpi/battery/") | 247 | ;; ACPI provides information about each battery present in the system |
| 249 | ;; ACPI provides information about each battery present in the system in | 248 | ;; in a separate subdirectory. We are going to merge the available |
| 250 | ;; a separate subdirectory. We are going to merge the available | 249 | ;; information together since displaying for a variable amount of |
| 251 | ;; information together since displaying for a variable amount of | 250 | ;; batteries seems overkill for format-strings. |
| 252 | ;; batteries seems overkill for format-strings. | 251 | (with-temp-buffer |
| 253 | (mapc | 252 | (mapc (lambda (dir) |
| 254 | (lambda (dir) | 253 | (if (string-match "/\\.\\.?\\'" dir) |
| 255 | (with-temp-buffer | 254 | nil |
| 256 | (insert-file-contents (expand-file-name "state" dir)) | 255 | (delete-region (point-min) (point-max)) |
| 257 | (when (re-search-forward "present: +yes$" nil t) | 256 | (condition-case nil |
| 258 | (and (re-search-forward "charging state: +\\(.*\\)$" nil t) | 257 | (insert-file-contents (expand-file-name "state" dir)) |
| 259 | (or (null charging-state) (string= charging-state | 258 | (error nil)) |
| 260 | "unknown")) | 259 | (when (re-search-forward "present: +yes$" nil t) |
| 261 | ;; On most multi-battery systems, most of the time only one | 260 | (and (re-search-forward |
| 262 | ;; battery is "charging"/"discharging", the others are | 261 | "charging state: +\\(.*\\)$" nil t) |
| 263 | ;; "unknown". | 262 | (or (null charging-state) |
| 264 | (setq charging-state (match-string 1))) | 263 | (string= charging-state "unknown")) |
| 265 | (when (re-search-forward "present rate: +\\([0-9]+\\) \\(m[AW]\\)$" | 264 | ;; On most multi-battery systems, most of the time |
| 266 | nil t) | 265 | ;; only one battery is "charging/discharging", the |
| 267 | (setq rate (+ (or rate 0) (string-to-int (match-string 1))) | 266 | ;; others are "unknown". |
| 268 | rate-type (or (and rate-type | 267 | (setq charging-state (match-string 1))) |
| 269 | (if (string= rate-type (match-string 2)) | 268 | (when (re-search-forward |
| 270 | rate-type | 269 | "present rate: +\\([0-9]+\\) \\(m[AW]\\)$" nil t) |
| 271 | (error | 270 | (setq rate (+ (or rate 0) |
| 272 | "Inconsistent rate types (%s vs. %s)" | 271 | (string-to-int (match-string 1))) |
| 273 | rate-type (match-string 2)))) | 272 | rate-type (or (and rate-type |
| 274 | (match-string 2)))) | 273 | (if (string= rate-type (match-string 2)) |
| 275 | (when (re-search-forward "remaining capacity: +\\([0-9]+\\) m[AW]h$" | 274 | rate-type |
| 276 | nil t) | 275 | (error |
| 277 | (setq capacity | 276 | "Inconsistent rate types (%s vs. %s)" |
| 278 | (+ (or capacity 0) (string-to-int (match-string 1)))))) | 277 | rate-type (match-string 2)))) |
| 279 | (goto-char (point-max)) | 278 | (match-string 2)))) |
| 280 | (insert-file-contents (expand-file-name "info" dir)) | 279 | (when (re-search-forward |
| 281 | (when (re-search-forward "present: +yes$" nil t) | 280 | "remaining capacity: +\\([0-9]+\\) m[AW]h$" nil t) |
| 282 | (when (re-search-forward "design capacity: +\\([0-9]+\\) m[AW]h$" | 281 | (setq capacity (+ (or capacity 0) |
| 283 | nil t) | 282 | (string-to-int (match-string 1)))))) |
| 284 | (setq design-capacity (+ (or design-capacity 0) | 283 | (goto-char (point-max)) |
| 285 | (string-to-int (match-string 1))))) | 284 | (condition-case nil |
| 286 | (when (re-search-forward "design capacity warning: +\\([0-9]+\\) m[AW]h$" | 285 | (insert-file-contents (expand-file-name "info" dir)) |
| 287 | nil t) | 286 | (error nil)) |
| 288 | (setq warn (+ (or warn 0) (string-to-int (match-string 1))))) | 287 | (when (re-search-forward "present: +yes$" nil t) |
| 289 | (when (re-search-forward "design capacity low: +\\([0-9]+\\) m[AW]h$" | 288 | (when (re-search-forward |
| 290 | nil t) | 289 | "design capacity: +\\([0-9]+\\) m[AW]h$" nil t) |
| 291 | (setq low (+ (or low 0) | 290 | (setq design-capacity (+ (or design-capacity 0) |
| 292 | (string-to-int (match-string 1)))))))) | 291 | (string-to-int (match-string 1))))) |
| 293 | (directory-files "/proc/acpi/battery/" t "\\(BAT\\|CMB\\)"))) | 292 | (when (re-search-forward |
| 293 | "design capacity warning: +\\([0-9]+\\) m[AW]h$" nil t) | ||
| 294 | (setq warn (+ (or warn 0) | ||
| 295 | (string-to-int (match-string 1))))) | ||
| 296 | (when (re-search-forward | ||
| 297 | "design capacity low: +\\([0-9]+\\) m[AW]h$" nil t) | ||
| 298 | (setq low (+ (or low 0) | ||
| 299 | (string-to-int (match-string 1)))))))) | ||
| 300 | (condition-case nil | ||
| 301 | (directory-files "/proc/acpi/battery/" t) | ||
| 302 | (error nil)))) | ||
| 294 | (and capacity rate | 303 | (and capacity rate |
| 295 | (setq minutes (if (zerop rate) 0 | 304 | (setq minutes (if (zerop rate) 0 |
| 296 | (floor (* (/ (float (if (string= charging-state | 305 | (floor (* (/ (float (if (string= charging-state |
| @@ -366,32 +375,6 @@ The following %-sequences are provided: | |||
| 366 | (setq result (concat result "%"))) | 375 | (setq result (concat result "%"))) |
| 367 | result)) | 376 | result)) |
| 368 | 377 | ||
| 369 | (defconst battery-hex-map '((?0 . 0) (?1 . 1) (?2 . 2) (?3 . 3) | ||
| 370 | (?4 . 4) (?5 . 5) (?6 . 6) (?7 . 7) | ||
| 371 | (?8 . 8) (?9 . 9) (?a . 10) (?b . 11) | ||
| 372 | (?c . 12) (?d . 13) (?e . 14) (?f . 15))) | ||
| 373 | |||
| 374 | (defun battery-hex-to-int (string) | ||
| 375 | "Convert a hexadecimal number (a string) into a number." | ||
| 376 | (save-match-data | ||
| 377 | (and (string-match "^[ \t]+" string) | ||
| 378 | (setq string (substring string (match-end 0)))) | ||
| 379 | (and (string-match "^0[xX]" string) | ||
| 380 | (setq string (substring string (match-end 0))))) | ||
| 381 | (battery-hex-to-int-2 string)) | ||
| 382 | |||
| 383 | (defun battery-hex-to-int-2 (string) | ||
| 384 | (let ((index 0) | ||
| 385 | (length (length string)) | ||
| 386 | (value 0) | ||
| 387 | (elem nil)) | ||
| 388 | (while (and (< index length) | ||
| 389 | (setq elem (assoc (downcase (aref string index)) | ||
| 390 | battery-hex-map))) | ||
| 391 | (setq value (+ (* 16 value) (cdr elem)) | ||
| 392 | index (1+ index))) | ||
| 393 | value)) | ||
| 394 | |||
| 395 | 378 | ||
| 396 | (provide 'battery) | 379 | (provide 'battery) |
| 397 | 380 | ||