Update years in copyright notice; nfc.
[bpt/emacs.git] / lisp / battery.el
CommitLineData
e8af40ee 1;;; battery.el --- display battery status information
6b279740 2
0d30b337 3;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004,
aaef169d 4;; 2005, 2006 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)
248634e9
LK
52 (condition-case nil
53 (with-temp-buffer
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
59The function has to return an alist of conversion definitions.
60Its cons cells are of the form
6b279740
RS
61
62 (CONVERSION . REPLACEMENT-TEXT)
63
64CONVERSION is the character code of a \"conversion specification\"
4bef9110 65introduced 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.
77Ordinary characters in the control string are printed as-is, while
78conversion specifications introduced by a `%' character in the control
79string are substituted as defined by the current value of the variable
4bef9110
SE
80`battery-status-function'."
81 :type '(choice string (const nil))
82 :group 'battery)
6b279740
RS
83
84(defvar battery-mode-line-string nil
85 "String to display in the mode line.")
f4c4fc74 86;;;###autoload (put 'battery-mode-line-string 'risky-local-variable t)
6b279740 87
4bef9110 88(defcustom battery-mode-line-format
6b279740 89 (cond ((eq battery-status-function 'battery-linux-proc-apm)
f4c4fc74 90 "[%b%p%%]")
2b3cb60a 91 ((eq battery-status-function 'battery-linux-proc-acpi)
71d21198
LK
92