Implement cygw32
[bpt/emacs.git] / lisp / battery.el
CommitLineData
d4919479 1;;; battery.el --- display battery status information -*- coding: iso-8859-1 -*-
6b279740 2
acaf905b 3;; Copyright (C) 1997-1998, 2000-2012 Free Software Foundation, Inc.
6b279740 4
3b361901 5;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org>
d5323ba0 6;; Keywords: hardware
6b279740 7
f12b0b96 8;; This file is part of GNU Emacs.
6b279740 9
eb3fa2cf 10;; GNU Emacs is free software: you can redistribute it and/or modify
6b279740 11;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
6b279740 14
f12b0b96 15;; GNU Emacs is distributed in the hope that it will be useful,
6b279740
RS
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
eb3fa2cf 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
6b279740
RS
22
23;;; Commentary:
24
20d4381e
JR
25;; There is at present support for GNU/Linux, OS X and Windows. This
26;; library supports both the `/proc/apm' file format of Linux version
27;; 1.3.58 or newer and the `/proc/acpi/' directory structure of Linux
28;; 2.4.20 and 2.6. Darwin (OS X) is supported by using the `pmset'
29;; program. Windows is supported by the GetSystemPowerStatus API call.
6b279740
RS
30
31;;; Code:
32
33(require 'timer)
f58e0fd5 34(eval-when-compile (require 'cl-lib))
6b279740 35\f
4bef9110
SE
36(defgroup battery nil
37 "Display battery status information."
38 :prefix "battery-"
39 :group 'hardware)
40
6decb6c2
SM
41;; Either BATn or yeeloong-bat, basically.
42(defconst battery--linux-sysfs-regexp "[bB][aA][tT][0-9]?$")
43
4bef9110 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 50 'battery-linux-proc-acpi)
3660b4f5
CY
51 ((and (eq system-type 'gnu/linux)
52 (file-directory-p "/sys/class/power_supply/")
6decb6c2
SM
53 (directory-files "/sys/class/power_supply/" nil
54 battery--linux-sysfs-regexp))
3660b4f5 55 'battery-linux-sysfs)
71d21198 56 ((and (eq system-type 'darwin)
785428c7
RF
57 (condition-case nil
58 (with-temp-buffer
248634e9
LK
59 (and (eq (call-process "pmset" nil t nil "-g" "ps") 0)
60 (> (buffer-size) 0)))
61 (error nil)))
20d4381e 62 'battery-pmset)
0fda9b75 63 ((fboundp 'w32-battery-status)
20d4381e 64 'w32-battery-status))
9201cc28 65 "Function for getting battery status information.
681e6b4b
DL
66The function has to return an alist of conversion definitions.
67Its cons cells are of the form
6b279740
RS
68
69 (CONVERSION . REPLACEMENT-TEXT)
70
71CONVERSION is the character code of a \"conversion specification\"
4bef9110 72introduced by a `%' character in a control string."
681e6b4b 73 :type '(choice (const nil) function)
4bef9110 74 :group 'battery)
6b279740 75
4bef9110 76(defcustom battery-echo-area-format
20d4381e 77 (cond ((eq battery-status-function 'battery-linux-proc-acpi)
71d21198 78 "Power %L, battery %B at %r (%p%% load, remaining time %t)")
3660b4f5 79 ((eq battery-status-function 'battery-linux-sysfs)
54071013 80 "Power %L, battery %B (%p%% load, remaining time %t)")
71d21198 81 ((eq battery-status-function 'battery-pmset)
20d4381e
JR
82 "%L power, battery %B (%p%% load, remaining time %t)")
83 (battery-status-function
84 "Power %L, battery %B (%p%% load, remaining time %t)"))
9201cc28 85 "Control string formatting the string to display in the echo area.
6b279740
RS
86Ordinary characters in the control string are printed as-is, while
87conversion specifications introduced by a `%' character in the control
88string are substituted as defined by the current value of the variable
76815b2a
RS
89`battery-status-function'. Here are the ones generally available:
90%c Current capacity (mAh or mWh)
91%r Current rate of charge or discharge
92%B Battery status (verbose)
93%b Battery status: empty means high, `-' means low,
94 `!' means critical, and `+' means charging
95%d Temperature (in degrees Celsius)
96%L AC line status (verbose)
97%p Battery load percentage
98%m Remaining time (to charge or discharge) in minutes
99%h Remaining time (to charge or discharge) in hours
100%t Remaining time (to charge or discharge) in the form `h:min'"
4bef9110
SE
101 :type '(choice string (const nil))
102 :group 'battery)
6b279740
RS
103
104(defvar battery-mode-line-string nil
105 "String to display in the mode line.")
f4c4fc74 106;;;###autoload (put 'battery-mode-line-string 'risky-local-variable t)
6b279740 107
43d5bf84
RS
108(defcustom battery-mode-line-limit 100
109 "Percentage of full battery load below which display battery status"
2bed3f04 110 :version "24.1"
43d5bf84
RS
111 :type 'integer
112 :group 'battery)
113
4bef9110 114(defcustom battery-mode-line-format
20d4381e 115 (cond ((eq battery-status-function 'battery-linux-proc-acpi)
71d21198 116