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