Commit | Line | Data |
---|---|---|
e8af40ee | 1 | ;;; battery.el --- display battery status information |
6b279740 | 2 | |
0d30b337 | 3 | ;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004, |
d7a0267c | 4 | ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
6b279740 | 5 | |
3b361901 | 6 | ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org> |
d5323ba0 | 7 | ;; Keywords: hardware |
6b279740 | 8 | |
f12b0b96 | 9 | ;; This file is part of GNU Emacs. |
6b279740 | 10 | |
f12b0b96 | 11 | ;; GNU Emacs is free software; you can redistribute it and/or modify |
6b279740 RS |
12 | ;; it under the terms of the GNU General Public License as published by |
13 | ;; the Free Software Foundation; either version 2, or (at your option) | |
14 | ;; any later version. | |
15 | ||
f12b0b96 | 16 | ;; GNU Emacs is distributed in the hope that it will be useful, |
6b279740 RS |
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 | |
f12b0b96 | 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
086add15 LK |
23 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | ;; Boston, MA 02110-1301, USA. | |
6b279740 RS |
25 | |
26 | ;;; Commentary: | |
27 | ||
71d21198 LK |
28 | ;; There is at present support for GNU/Linux and OS X. This library |
29 | ;; supports both the `/proc/apm' file format of Linux version 1.3.58 | |
30 | ;; or newer and the `/proc/acpi/' directory structure of Linux 2.4.20 | |
31 | ;; and 2.6. Darwin (OS X) is supported by using the `pmset' program. | |
6b279740 RS |
32 | |
33 | ;;; Code: | |
34 | ||
35 | (require 'timer) | |
0f4a15f8 | 36 | (eval-when-compile (require 'cl)) |
6b279740 RS |
37 | |
38 | \f | |
4bef9110 SE |
39 | (defgroup battery nil |
40 | "Display battery status information." | |
41 | :prefix "battery-" | |
42 | :group 'hardware) | |
43 | ||
44 | (defcustom battery-status-function | |
6b279740 RS |
45 | (cond ((and (eq system-type 'gnu/linux) |
46 | (file-readable-p "/proc/apm")) | |
2b3cb60a EZ |
47 | 'battery-linux-proc-apm) |
48 | ((and (eq system-type 'gnu/linux) | |
49 | (file-directory-p "/proc/acpi/battery")) | |
71d21198 LK |
50 | 'battery-linux-proc-acpi) |
51 | ((and (eq system-type 'darwin) | |
785428c7 RF |
52 | (condition-case nil |
53 | (with-temp-buffer | |
248634e9 LK |
54 | (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) |
55 | (> (buffer-size) 0))) | |
56 | (error nil))) | |
71d21198 | 57 | 'battery-pmset)) |
6b279740 | 58 | "*Function for getting battery status information. |
681e6b4b DL |
59 | The function has to return an alist of conversion definitions. |
60 | Its cons cells are of the form | |
6b279740 RS |
61 | |
62 | (CONVERSION . REPLACEMENT-TEXT) | |
63 | ||
64 | CONVERSION is the character code of a \"conversion specification\" | |
4bef9110 | 65 | introduced by a `%' character in a control string." |
681e6b4b | 66 | :type '(choice (const nil) function) |
4bef9110 | 67 | :group 'battery) |
6b279740 | 68 | |
4bef9110 | 69 | (defcustom battery-echo-area-format |
6b279740 | 70 | (cond ((eq battery-status-function 'battery-linux-proc-apm) |
2b3cb60a EZ |
71 | "Power %L, battery %B (%p%% load, remaining time %t)") |
72 | ((eq battery-status-function 'battery-linux-proc-acpi) | |
71d21198 LK |
73 | "Power %L, battery %B at %r (%p%% load, remaining time %t)") |
74 | ((eq battery-status-function 'battery-pmset) | |
75 | "%L power, battery %B (%p%% load, remaining time %t)")) | |
6b279740 RS |
76 | "*Control string formatting the string to display in the echo area. |
77 | Ordinary characters in the control string are printed as-is, while | |
78 | conversion specifications introduced by a `%' character in the control | |
79 | string are substituted as defined by the current value of the variable | |
76815b2a RS |
80 | `battery-status-function'. Here are the ones generally available: |
81 | %c Current capacity (mAh or mWh) | |
82 | %r Current rate of charge or discharge | |
83 | %B Battery status (verbose) | |
84 | %b Battery status: empty means high, `-' means low, | |
85 | `!' means critical, and `+' means charging | |
86 | %d Temperature (in degrees Celsius) | |
87 | %L AC line status (verbose) | |
88 | %p Battery load percentage | |
89 | %m Remaining time (to charge or discharge) in minutes | |
90 | %h Remaining time (to charge or discharge) in hours | |
91 | %t Remaining time (to charge or discharge) in the form `h:min'" | |
4bef9110 SE |
92 | :type '(choice string (const nil)) |
93 | :group 'battery) | |
6b279740 RS |
94 | |
95 | (defvar battery-mode-line-string nil | |
96 | "String to display in the mode line.") | |
f4c4fc74 | 97 | ;;;###autoload (put 'battery-mode-line-string 'risky-local-variable t) |
6b279740 | 98 | |
4bef9110 | 99 | (defcustom battery-mode-line-format |
6b279740 | 100 | (cond ((eq battery-status-function 'battery-linux-proc-apm) |
f4c4fc74 | 101 | "[%b%p%%]") |
2b3cb60a | 102 | ((eq battery-status-function 'battery-linux-proc-acpi) |
71d21198 LK |
103 |