Mercurial > emacs
annotate lisp/battery.el @ 96044:c1ef445563bb
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-colview.el (org-columns-next-allowed-value): Bug fix.
* org-colview-xemacs.el (org-columns-next-allowed-value): Bug fix.
* org-agenda.el (org-agenda-get-closed): Get the end time into the
agenda prefix as well.
* org-publish.el (org-publish-org-index): Make a properly indented
list.
* org.el (org-calendar-agenda-action-key): New option.
(org-get-cursor-date): New function.
(org-mark-entry-for-agenda-action): New command.
(org-overriding-default-time): New variable.
(org-read-date): Respect `org-overriding-default-time'.
* org-remember.el (org-remember-apply-template): Respect the
ovverriding default time.
* org-agenda.el (org-agenda-action-marker): New variable.
(org-agenda-action): New command.
(org-agenda-do-action): New function.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-schedule, org-deadline): Protect scheduled and
deadline tasks against changes that accidently remove the
repeater. Also show a message with the new date when done.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-beginning-of-line): Cater for the case when there
are tags but no headline text.
(org-align-tags-here): Convert to tabs only when indent-tabs-mode
it set.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-mhe.el (org-mhe-get-message-folder-from-index): Make sure
the return value is nil instead of "nil" when there is no match.
* org-exp.el (org-insert-centered): Use fill-column instead of
80.
(org-export-as-ascii): Use string-width to measure the width of
the heading.
* org.el (org-diary-to-ical-string): No longer kill buffer
FROMBUF, this is now done by the caller.
* org-exp.el (org-print-icalendar-entries): Move the call to
`org-diary-to-ical-string' out of the loop, and kill the buffer
afterwords.
* org-remember.el (org-remember-visit-immediately): Position
cursor after moving to the note.
(org-remember-apply-template): Use a text property to record the
cursor position.
(org-remember-handler): Align tags after pasting the note.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-bbdb.el (org-bbdb-follow-anniversary-link): New function.
* org-agenda.el (org-agenda-open-link): If there is an
org-bbdb-name property in the current line, jump to that bbdb
entry.
* org-bbdb.el (org-bbdb-anniversaries): Add the bbdb-name as a
text property, so that the agenda knows where this entry comes
from.
* org-agenda.el (org-agenda-clock-in): Fixed bug in the
interaction between clocking-in from the agenda, and automatic
task state switching.
* org-macs.el (org-with-point-at): Bug fix in macro defintion.
* org.el (org-beginning-of-line, org-end-of-line): Make sure the
zmacs-region stays after this command in XEmacs.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-scan-tags): Allow new values for ACTION parameter.
* org-remember.el (org-remember-templates): Fix bug in
customization type definition.
* org.el (org-map-entries): New function.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-agenda.el (org-agenda-skip-comment-trees): New option.
(org-agenda-skip): Respect `org-agenda-skip-comment-trees'.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-remember.el (org-jump-to-target-location): New variable.
(org-remember-apply-template): Set
`org-remember-apply-template' if requested by template.
(org-remember-handler): Start an idle timer to jump to
remember location.
* org-exp.el (org-get-current-options): Add the FILETAGS setting.
* org.el (org-set-regexps-and-options): Fix bug with parsing of
file tags.
(org-get-tags-at): Add the content of `org-file-tags'.
* org-exp.el (org-export-handle-comments): Fix bug with several
comment lines after each other.
(org-number-to-roman, org-number-to-counter): New functions.
(org-export-section-number-format): New option.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-exp.el (org-export-protect-examples): Catch the case of a
missing end_example line.
* org.el (org-set-regexps-and-options): Set `org-file-properties' and
`org-file-tags' to nil.
* org-colview.el (org-columns-next-allowed-value): Handle next
argument NTH to directly select a value.
* org-colview-xemacs.el (org-columns-next-allowed-value): Handle next
argument NTH to directly select a value.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-agenda.el (org-agenda-scheduled-leaders): Fix docstring.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-columns-ellipses): New option.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-colview.el (org-columns-add-ellipses): New function.
(org-columns-compact-links): New function.
(org-columns-cleanup-item): Call `org-columns-compact-links'.
(org-columns-display-here): Call `org-agenda-columns-cleanup-item'
when in agenda.
(org-columns-edit-value): Fixed bug with editing values from
agenda column view.
(org-columns-redo): Also redo the agenda itself.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-agenda.el (org-agenda-columns-remove-prefix-from-item): New
option.
* org-colview.el (org-agenda-columns-cleanup-item): New function.
* org-exp.el (org-export-ascii-preprocess): Renamed from
`org-export-ascii-clean-string'.
(org-export-kill-licensed-text)
(org-export-define-heading-targets)
(org-export-handle-invisible-targets)
(org-export-target-internal-links)
(org-export-remove-or-extract-drawers)
(org-export-remove-archived-trees)
(org-export-protect-quoted-subtrees)
(org-export-protect-verbatim, org-export-protect-examples)
(org-export-select-backend-specific-text)
(org-export-mark-blockquote-and-verse)
(org-export-remove-comment-blocks-and-subtrees)
(org-export-handle-comments, org-export-mark-radio-links)
(org-export-remove-special-table-lines)
(org-export-normalize-links)
(org-export-concatenate-multiline-links)
(org-export-concatenate-multiline-emphasis): New functions,
obtained from spliiting the export preprocessor.
* org-table.el (org-table-recalculate): Improve error message if
the row number is invalid.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-archive.el (org-archive-save-context-info): Fix bugs in
customization setup and docstring.
* org-exp.el (org-export-html-style): Changed the size of in the
<pre> element to 90%.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-find-src-example-start): Function removed.
(org-edit-src-find-region-and-lang): New function.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-edit-src-exit): New function.
(org-exit-edit-mode): New minor mode.
* org-exp.el (org-export-preprocess-string): Fix bug with removing
comment-like lines from protected examples.
* org.el (org-edit-src-example, org-find-src-example-start)
(org-protect-source-example, org-edit-special): New functions.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-publish.el (org-publish-project-alist): Fix typo in
docstring.
(org-publish-project-alist): Handle :index-title property.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-export-latex.el (org-export-as-latex): Make sure region
bounds are correct. Parse subtree properties relating to export.
* org-exp.el (org-export-add-options-to-plist): New function.
(org-infile-export-plist): Use `org-export-add-options-to-plist'.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-default-properties): Add EXPORT_FILE_NAME and
EXPORT_TITLE.
* org-exp.el (org-export-get-title-from-subtree)
(org-export-as-ascii, org-export-as-html): Make sure the original
region-beginning and region-end are used, even after moving
point.
(org-export-get-title-from-subtree): Also try the EXPORT_TITLE
property.
* org-remember.el (org-remember-last-stored-marker): New variable.
(org-remember-goto-last-stored): Use `org-goto-marker-or-bmk'.
(org-remember-handler): Also use marker to remember
last-stored position.
* org.el (org-goto-marker-or-bmk): New function.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-file-properties): Renamed from `org-local-properties'.
(org-scan-tags): Take file tags into account.
(org-tags-match-list-sublevels): Default changed to t.
* org-exp.el (org-export-as-html): Close paragraph after a
footnote.
* org.el (org-update-parent-todo-statistics): New function.
* org-exp.el (org-icalendar-store-UID): New option.
(org-icalendar-force-UID): Option removed.
(org-print-icalendar-entries): IMplement UIDs.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-mhe.el (org-mhe-follow-link): Fix bug in mhe searches.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-faces.el (org-column): Document how this face is being used
and why sometimes the background faces shine through.
* org-mhe.el (org-mhe-follow-link): Improve handling of searches.
* org-publish.el (org-publish-attachment): Create publishing
directory if it does not yet exist.
* org-table.el (org-calc-default-modes): Change default number
format to (float 8).
* org.el (org-olpath-completing-read): New function.
(org-time-clocksum-format): New option.
(org-minutes-to-hh:mm-string): Use `org-time-clocksum-format'.
* org-clock.el (org-clock-display, org-clock-out)
(org-update-mode-line): Use `org-time-clocksum-format'.
* org-colview-xemacs.el (org-columns-number-to-string): Use
`org-time-clocksum-format'.
* org-colview.el (org-columns-number-to-string): Use
`org-time-clocksum-format'.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-id.el: New file, move from contrib to core.
* org-exp.el (org-icalendar-force-UID): New option.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-exp.el (org-print-icalendar-entries): Make sure DTEND is
shifted by one day if theere is a date range without an end
time.
* org.el (org-try-structure-completion): New function.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-set-font-lock-defaults): Improve fontification of
description lists.
(org-insert-item): Handle description lists.
(org-adaptive-fill-function): Improve auto indentation in
description lists.
* org-exp.el (org-export-as-html, org-export-preprocess-string):
Implement VERSE environment.
(org-export-preprocess-string): Implement the COMMENT
environment.
* org-export-latex.el (org-export-latex-preprocess): Implement
VERSE environment.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-jsinfo.el (org-infojs-opts-table): Add entry for FIXED_TOC
option.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-table.el (orgtbl-to-tsv, orgtbl-to-csv): New functions.
* org.el (org-quote-csv-field): New functions.
* org-table.el (org-table-export-default-format): Remove :splice
from default format, we get the same effect by not specifying
:tstart and :tend.
(org-table-export): Improve setup, distinguish better between
interactive and non-interactive use, allow specifying the format
on the fly, better protection against wrong file names.
(orgtbl-to-generic): Fix documentation. Do not require :tstart
and :tend when :splice is omitted.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-clock.el (org-clock-select-task): Make sure the selection
letters are 1-9 and A-Z, no special characters.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-exp.el (org-export-htmlize): New group.
(org-export-htmlize-output-type)
(org-export-htmlize-css-font-prefix): New options.
(org-export-htmlize-region-for-paste): New function.
(org-export-htmlize-generate-css): New command.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-set-visibility-according-to-property): New function.
(org-ctrl-c-ctrl-c): Do not restart org-mode, just get the options
and compute the regular expressions, and update font-lock.
(org-property-re): Allow a dash in property names.
* org-archive.el (org-extract-archive-file): Insert the file name
without the path into the format, to allow the location format to
contain a subdirectory.
* org-agenda.el (org-agenda-post-command-hook): If point is at end
of buffer, and the `org-agenda-type' property undefined, use the
value from the character before.
* org.el (org-add-planning-info): Don't let indentation for
would-be timestamp become extra whitespace at the end of headline.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-remove-double-quotes, org-file-contents): New
functions.
* org-exp.el (org-infile-export-plist): Also parse the
contents of #+SETUPFILE files, recursively.
* org.el (org-set-regexps-and-options): Also parse the
contents of #+SETUPFILE files, recursively.
* org-exp.el (org-export-handle-include-files): New function.
(org-export-preprocess-string): Call
`org-export-handle-include-files'.
* org.el (org-delete-property-globally)
(org-delete-property, org-set-property): Ignore case during
completion.
(org-set-property): Use `org-completing-read' instead of
`completing-read'.
* org.el (org-complete-expand-structure-template): New,
experimental function.
(org-structure-template-alist): New, experimental option.
(org-complete): Call `org-complete-expand-structure-template'.
2008-06-17 Bastien Guerry <bzg@altern.org>
* org-export-latex.el (org-export-latex-preprocess): Added
support for blockquotes.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-read-date-analyze): Catch the case where only a
weekday is given.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-set-font-lock-defaults): Make the description
tag bold.
* org-exp.el (org-export-as-html, org-close-li): Implement
description lists.
2008-06-17 Jason Riedy <jason@acm.org>
* org-table.el (*orgtbl-default-fmt*): New variable.
(orgtbl-format-line): Use the value of *orgtbl-default-fmt*
when there is no other fmt available.
(orgtbl-to-generic): Allow an explicitly nil :tstart or
:tend to suppress the appropriate string.
(orgtbl-to-orgtbl): New function for translating to another orgtbl
table.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.el (org-read-date-analyze): "." as an alias for "+0" in
read date.
* org-clock.el (org-clock-save-markers-for-cut-and-paste):
New function.
* org-agenda.el (org-agenda-save-markers-for-cut-and-paste):
New function.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-clock.el (org-clock-find-position): Don't include notes
into clock drawer.
* org-archive.el (org-archive-subtree): No longer remove an
extra line after cutting the subtree. `org-cut-subtree' already
takes care of this.
* org-remember.el (org-remember-handler): Only kill the target
buffer if it does not contain the running clock.
* org.el (org-markers-to-move): New variable.
(org-save-markers-in-region, org-check-and-save-marker)
(org-reinstall-markers-in-region): New function.
(org-move-subtree-down, org-copy-subtree): Remember relative
marker positions before cutting.
(org-move-subtree-down, org-paste-subtree): Restore relative
marker positions after pasting.
* org-remember.el (org-remember-clock-out-on-exit): New option.
(org-remember-finalize): Clock out only if the setting in
`org-remember-clock-out-on-exit' requires it.
(org-remember-handler): Do the cleanup in the buffer, to make sure
that the clock marker remains in tact.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-clock.el (org-clock-goto): Widen buffer if necessary.
(org-clock-in): Make sure that also tasks outside the narrowed
region will be clocked in correctly.
(org-clock-insert-selection-line): Widen the buffer so that we can
find the correct task heading.
* org.el (org-base-buffer): New function.
* org-exp.el (org-icalendar-cleanup-string): Make sure ',"
and ";" are escaped.
(org-print-icalendar-entries): Also apply
`org-icalendar-cleanup-string' to the headline, not only to the
summary property.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org-exp.el (org-export-preprocess-hook): New hook.
(org-export-preprocess-string): Call
`org-export-preprocess-hook'.
* org.el (org-font-lock-hook): New variable.
(org-font-lock-hook): New function.
(org-set-font-lock-defaults): Call `org-font-lock-hook'.
2008-06-17 Carsten Dominik <dominik@science.uva.nl>
* org.texi: Modify license to no longer include back- and front
cover matters.
(Using the mapping API): New section.
(Agenda column view): New section.
(Moving subtrees): Document archiving to the archive
sibling.
(Agenda commands): Document columns view in the agenda.
(Using the property API): Document the API for
multi-valued properties.
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Tue, 17 Jun 2008 15:22:00 +0000 |
parents | ee5932bf781d |
children | a7ddf766669d |
rev | line source |
---|---|
93207
ba8704a0f1e5
Add file cookie coding:iso-8859-1 for the degree sign
Juri Linkov <juri@jurta.org>
parents:
79721
diff
changeset
|
1 ;;; battery.el --- display battery status information -*- coding: iso-8859-1 -*- |
18388 | 2 |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64094
diff
changeset
|
3 ;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004, |
79721 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
18388 | 5 |
30110
23cb074f9d88
Change author's mail address.
Gerd Moellmann <gerd@gnu.org>
parents:
26828
diff
changeset
|
6 ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org> |
20972
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
7 ;; Keywords: hardware |
18388 | 8 |
18685
4f3350c88e6c
Fix copyright and copying permissions.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
18388 | 10 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94449
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
18388 | 12 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94449
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94449
diff
changeset
|
14 ;; (at your option) any later version. |
18388 | 15 |
18685
4f3350c88e6c
Fix copyright and copying permissions.
Richard M. Stallman <rms@gnu.org>
parents:
18388
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
18388 | 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 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94449
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
18388 | 23 |
24 ;;; Commentary: | |
25 | |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
26 ;; There is at present support for GNU/Linux, OS X and Windows. This |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
27 ;; library supports both the `/proc/apm' file format of Linux version |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
28 ;; 1.3.58 or newer and the `/proc/acpi/' directory structure of Linux |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
29 ;; 2.4.20 and 2.6. Darwin (OS X) is supported by using the `pmset' |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
30 ;; program. Windows is supported by the GetSystemPowerStatus API call. |
18388 | 31 |
32 ;;; Code: | |
33 | |
34 (require 'timer) | |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
35 (eval-when-compile (require 'cl)) |
18388 | 36 |
37 | |
21088 | 38 (defgroup battery nil |
39 "Display battery status information." | |
40 :prefix "battery-" | |
41 :group 'hardware) | |
42 | |
43 (defcustom battery-status-function | |
18388 | 44 (cond ((and (eq system-type 'gnu/linux) |
45 (file-readable-p "/proc/apm")) | |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
46 'battery-linux-proc-apm) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
47 ((and (eq system-type 'gnu/linux) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
48 (file-directory-p "/proc/acpi/battery")) |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
49 'battery-linux-proc-acpi) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
50 ((and (eq system-type 'darwin) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
51 (condition-case nil |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
52 (with-temp-buffer |
64907
08b55dc9bcd1
(battery-status-function): Don't use ignore-errors.
Lute Kamstra <lute@gnu.org>
parents:
64762
diff
changeset
|
53 (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) |
08b55dc9bcd1
(battery-status-function): Don't use ignore-errors.
Lute Kamstra <lute@gnu.org>
parents:
64762
diff
changeset
|
54 (> (buffer-size) 0))) |
08b55dc9bcd1
(battery-status-function): Don't use ignore-errors.
Lute Kamstra <lute@gnu.org>
parents:
64762
diff
changeset
|
55 (error nil))) |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
56 'battery-pmset) |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
57 ((eq system-type 'windows-nt) |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
58 'w32-battery-status)) |
18388 | 59 "*Function for getting battery status information. |
36090
9ed7c3f74e35
(battery-status-function): Fix doc, :type.
Dave Love <fx@gnu.org>
parents:
32356
diff
changeset
|
60 The function has to return an alist of conversion definitions. |
9ed7c3f74e35
(battery-status-function): Fix doc, :type.
Dave Love <fx@gnu.org>
parents:
32356
diff
changeset
|
61 Its cons cells are of the form |
18388 | 62 |
63 (CONVERSION . REPLACEMENT-TEXT) | |
64 | |
65 CONVERSION is the character code of a \"conversion specification\" | |
21088 | 66 introduced by a `%' character in a control string." |
36090
9ed7c3f74e35
(battery-status-function): Fix doc, :type.
Dave Love <fx@gnu.org>
parents:
32356
diff
changeset
|
67 :type '(choice (const nil) function) |
21088 | 68 :group 'battery) |
18388 | 69 |
21088 | 70 (defcustom battery-echo-area-format |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
71 (cond ((eq battery-status-function 'battery-linux-proc-acpi) |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
72 "Power %L, battery %B at %r (%p%% load, remaining time %t)") |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
73 ((eq battery-status-function 'battery-pmset) |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
74 "%L power, battery %B (%p%% load, remaining time %t)") |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
75 (battery-status-function |
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
76 "Power %L, battery %B (%p%% load, remaining time %t)")) |
18388 | 77 "*Control string formatting the string to display in the echo area. |
78 Ordinary characters in the control string are printed as-is, while | |
79 conversion specifications introduced by a `%' character in the control | |
80 string are substituted as defined by the current value of the variable | |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
81 `battery-status-function'. Here are the ones generally available: |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
82 %c Current capacity (mAh or mWh) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
83 %r Current rate of charge or discharge |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
84 %B Battery status (verbose) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
85 %b Battery status: empty means high, `-' means low, |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
86 `!' means critical, and `+' means charging |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
87 %d Temperature (in degrees Celsius) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
88 %L AC line status (verbose) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
89 %p Battery load percentage |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
90 %m Remaining time (to charge or discharge) in minutes |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
91 %h Remaining time (to charge or discharge) in hours |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
92 %t Remaining time (to charge or discharge) in the form `h:min'" |
21088 | 93 :type '(choice string (const nil)) |
94 :group 'battery) | |
18388 | 95 |
96 (defvar battery-mode-line-string nil | |
97 "String to display in the mode line.") | |
59132
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
98 ;;;###autoload (put 'battery-mode-line-string 'risky-local-variable t) |
18388 | 99 |
21088 | 100 (defcustom battery-mode-line-format |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
101 (cond ((eq battery-status-function 'battery-linux-proc-acpi) |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
102 "[%b%p%%,%d°C]") |
94449
a96dda54aef3
(battery-status-function): Use w32-battery-status on Windows.
Jason Rumney <jasonr@gnu.org>
parents:
93207
diff
changeset
|
103 (battery-status-function |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
104 "[%b%p%%]")) |
18388 | 105 "*Control string formatting the string to display in the mode line. |
106 Ordinary characters in the control string are printed as-is, while | |
107 conversion specifications introduced by a `%' character in the control | |
108 string are substituted as defined by the current value of the variable | |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
109 `battery-status-function'. Here are the ones generally available: |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
110 %c Current capacity (mAh or mWh) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
111 %r Current rate of charge or discharge |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
112 %B Battery status (verbose) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
113 %b Battery status: empty means high, `-' means low, |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
114 `!' means critical, and `+' means charging |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
115 %d Temperature (in degrees Celsius) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
116 %L AC line status (verbose) |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
117 %p Battery load percentage |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
118 %m Remaining time (to charge or discharge) in minutes |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
119 %h Remaining time (to charge or discharge) in hours |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
120 %t Remaining time (to charge or discharge) in the form `h:min'" |
21088 | 121 :type '(choice string (const nil)) |
122 :group 'battery) | |
18388 | 123 |
21088 | 124 (defcustom battery-update-interval 60 |
125 "*Seconds after which the battery status will be updated." | |
126 :type 'integer | |
127 :group 'battery) | |
18388 | 128 |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
129 (defcustom battery-load-low 25 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
130 "*Upper bound of low battery load percentage. |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
131 A battery load percentage below this number is considered low." |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
132 :type 'integer |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
133 :group 'battery) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
134 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
135 (defcustom battery-load-critical 10 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
136 "*Upper bound of critical battery load percentage. |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
137 A battery load percentage below this number is considered critical." |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
138 :type 'integer |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
139 :group 'battery) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
140 |
18388 | 141 (defvar battery-update-timer nil |
142 "Interval timer object.") | |
143 | |
21076
dc82196eac58
Fixed spelling of `autoload' magic cookies.
Richard M. Stallman <rms@gnu.org>
parents:
20972
diff
changeset
|
144 ;;;###autoload |
18388 | 145 (defun battery () |
146 "Display battery status information in the echo area. | |
26828 | 147 The text being displayed in the echo area is controlled by the variables |
18388 | 148 `battery-echo-area-format' and `battery-status-function'." |
149 (interactive) | |
150 (message "%s" (if (and battery-echo-area-format battery-status-function) | |
151 (battery-format battery-echo-area-format | |
152 (funcall battery-status-function)) | |
153 "Battery status not available"))) | |
154 | |
21076
dc82196eac58
Fixed spelling of `autoload' magic cookies.
Richard M. Stallman <rms@gnu.org>
parents:
20972
diff
changeset
|
155 ;;;###autoload |
59363
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
156 (define-minor-mode display-battery-mode |
18388 | 157 "Display battery status information in the mode line. |
32346
fa3f5e8f6201
(display-battery): Doc spelling fix.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
30110
diff
changeset
|
158 The text being displayed in the mode line is controlled by the variables |
18388 | 159 `battery-mode-line-format' and `battery-status-function'. |
160 The mode line will be updated automatically every `battery-update-interval' | |
161 seconds." | |
61268
abd0d265b4ba
(display-battery-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents:
59363
diff
changeset
|
162 :global t :group 'battery |
18388 | 163 (setq battery-mode-line-string "") |
164 (or global-mode-string (setq global-mode-string '(""))) | |
165 (and battery-update-timer (cancel-timer battery-update-timer)) | |
59363
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
166 (if (not display-battery-mode) |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
167 (setq global-mode-string |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
168 (delq 'battery-mode-line-string global-mode-string)) |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
169 (add-to-list 'global-mode-string 'battery-mode-line-string t) |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
170 (setq battery-update-timer (run-at-time nil battery-update-interval |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
171 'battery-update-handler)) |
9120644ff426
(display-battery-mode): Rename from display-battery.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
59132
diff
changeset
|
172 (battery-update))) |
18388 | 173 |
174 (defun battery-update-handler () | |
175 (battery-update) | |
176 (sit-for 0)) | |
177 | |
178 (defun battery-update () | |
179 "Update battery status information in the mode line." | |
59132
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
180 (setq battery-mode-line-string |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
181 (propertize (if (and battery-mode-line-format |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
182 battery-status-function) |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
183 (battery-format |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
184 battery-mode-line-format |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
185 (funcall battery-status-function)) |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
186 "") |
38f1d5865861
(battery-mode-line-format): Remove initial spaces.
Richard M. Stallman <rms@gnu.org>
parents:
57143
diff
changeset
|
187 'help-echo "Battery status information")) |
18388 | 188 (force-mode-line-update)) |
189 | |
190 | |
191 ;;; `/proc/apm' interface for Linux. | |
192 | |
193 (defconst battery-linux-proc-apm-regexp | |
194 (concat "^\\([^ ]+\\)" ; Driver version. | |
195 " \\([^ ]+\\)" ; APM BIOS version. | |
196 " 0x\\([0-9a-f]+\\)" ; APM BIOS flags. | |
197 " 0x\\([0-9a-f]+\\)" ; AC line status. | |
198 " 0x\\([0-9a-f]+\\)" ; Battery status. | |
199 " 0x\\([0-9a-f]+\\)" ; Battery flags. | |
20972
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
200 " \\(-?[0-9]+\\)%" ; Load percentage. |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
201 " \\(-?[0-9]+\\)" ; Remaining time. |
18388 | 202 " \\(.*\\)" ; Time unit. |
203 "$") | |
204 "Regular expression matching contents of `/proc/apm'.") | |
205 | |
206 (defun battery-linux-proc-apm () | |
207 "Get APM status information from Linux kernel. | |
208 This function works only with the new `/proc/apm' format introduced | |
209 in Linux version 1.3.58. | |
210 | |
211 The following %-sequences are provided: | |
212 %v Linux driver version | |
213 %V APM BIOS version | |
214 %I APM BIOS status (verbose) | |
215 %L AC line status (verbose) | |
216 %B Battery status (verbose) | |
217 %b Battery status, empty means high, `-' means low, | |
218 `!' means critical, and `+' means charging | |
63899
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
219 %p Battery load percentage |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
220 %s Remaining time (to charge or discharge) in seconds |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
221 %m Remaining time (to charge or discharge) in minutes |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
222 %h Remaining time (to charge or discharge) in hours |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
223 %t Remaining time (to charge or discharge) in the form `h:min'" |
18388 | 224 (let (driver-version bios-version bios-interface line-status |
225 battery-status battery-status-symbol load-percentage | |
63899
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
226 seconds minutes hours remaining-time tem) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
227 (with-temp-buffer |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
228 (ignore-errors (insert-file-contents "/proc/apm")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
229 (when (re-search-forward battery-linux-proc-apm-regexp) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
230 (setq driver-version (match-string 1)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
231 (setq bios-version (match-string 2)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
232 (setq tem (string-to-number (match-string 3) 16)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
233 (if (not (logand tem 2)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
234 (setq bios-interface "not supported") |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
235 (setq bios-interface "enabled") |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
236 (cond ((logand tem 16) (setq bios-interface "disabled")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
237 ((logand tem 32) (setq bios-interface "disengaged"))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
238 (setq tem (string-to-number (match-string 4) 16)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
239 (cond ((= tem 0) (setq line-status "off-line")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
240 ((= tem 1) (setq line-status "on-line")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
241 ((= tem 2) (setq line-status "on backup"))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
242 (setq tem (string-to-number (match-string 6) 16)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
243 (if (= tem 255) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
244 (setq battery-status "N/A") |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
245 (setq tem (string-to-number (match-string 5) 16)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
246 (cond ((= tem 0) (setq battery-status "high" |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
247 battery-status-symbol "")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
248 ((= tem 1) (setq battery-status "low" |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
249 battery-status-symbol "-")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
250 ((= tem 2) (setq battery-status "critical" |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
251 battery-status-symbol "!")) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
252 ((= tem 3) (setq battery-status "charging" |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
253 battery-status-symbol "+"))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
254 (setq load-percentage (match-string 7)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
255 (setq seconds (string-to-number (match-string 8))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
256 (and (string-equal (match-string 9) "min") |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
257 (setq seconds (* 60 seconds))) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
258 (setq minutes (/ seconds 60) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
259 hours (/ seconds 3600)) |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
260 (setq remaining-time |
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
261 (format "%d:%02d" hours (- minutes (* 60 hours)))))))) |
20972
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
262 (list (cons ?v (or driver-version "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
263 (cons ?V (or bios-version "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
264 (cons ?I (or bios-interface "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
265 (cons ?L (or line-status "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
266 (cons ?B (or battery-status "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
267 (cons ?b (or battery-status-symbol "")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
268 (cons ?p (or load-percentage "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
269 (cons ?s (or (and seconds (number-to-string seconds)) "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
270 (cons ?m (or (and minutes (number-to-string minutes)) "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
271 (cons ?h (or (and hours (number-to-string hours)) "N/A")) |
9dff083ee7a9
(battery-linux-proc-apm-regexp): Load percentage
Karl Heuer <kwzh@gnu.org>
parents:
18685
diff
changeset
|
272 (cons ?t (or remaining-time "N/A"))))) |
18388 | 273 |
274 | |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
275 ;;; `/proc/acpi/' interface for Linux. |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
276 |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
277 (defun battery-linux-proc-acpi () |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
278 "Get ACPI status information from Linux kernel. |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
279 This function works only with the new `/proc/acpi/' format introduced |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
280 in Linux version 2.4.20 and 2.6.0. |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
281 |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
282 The following %-sequences are provided: |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
283 %c Current capacity (mAh) |
63899
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
284 %r Current rate |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
285 %B Battery status (verbose) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
286 %b Battery status, empty means high, `-' means low, |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
287 `!' means critical, and `+' means charging |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
288 %d Temperature (in degrees Celsius) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
289 %L AC line status (verbose) |
63899
1f503fd2046d
(battery-linux-proc-apm): Fix typo in docstring.
Lute Kamstra <lute@gnu.org>
parents:
61268
diff
changeset
|
290 %p Battery load percentage |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
291 %m Remaining time (to charge or discharge) in minutes |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
292 %h Remaining time (to charge or discharge) in hours |
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
293 %t Remaining time (to charge or discharge) in the form `h:min'" |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
294 (let ((design-capacity 0) |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
295 (last-full-capacity 0) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
296 full-capacity |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
297 (warn 0) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
298 (low 0) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
299 capacity rate rate-type charging-state minutes hours) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
300 ;; ACPI provides information about each battery present in the system in |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
301 ;; a separate subdirectory. We are going to merge the available |
57133
fd1a6df8927e
Delete superfluous empty lines.
Eli Zaretskii <eliz@gnu.org>
parents:
56663
diff
changeset
|
302 ;; information together since displaying for a variable amount of |
fd1a6df8927e
Delete superfluous empty lines.
Eli Zaretskii <eliz@gnu.org>
parents:
56663
diff
changeset
|
303 ;; batteries seems overkill for format-strings. |
fd1a6df8927e
Delete superfluous empty lines.
Eli Zaretskii <eliz@gnu.org>
parents:
56663
diff
changeset
|
304 (with-temp-buffer |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
305 (dolist (dir (ignore-errors (directory-files "/proc/acpi/battery/" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
306 t "\\`[^.]"))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
307 (erase-buffer) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
308 (ignore-errors (insert-file-contents (expand-file-name "state" dir))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
309 (when (re-search-forward "present: +yes$" nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
310 (and (re-search-forward "charging state: +\\(.*\\)$" nil t) |
69381
780bbe0dfb17
(battery-echo-area-format): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
68651
diff
changeset
|
311 (member charging-state '("unknown" "charged" nil)) |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
312 ;; On most multi-battery systems, most of the time only one |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
313 ;; battery is "charging"/"discharging", the others are |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
314 ;; "unknown". |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
315 (setq charging-state (match-string 1))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
316 (when (re-search-forward "present rate: +\\([0-9]+\\) \\(m[AW]\\)$" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
317 nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
318 (setq rate (+ (or rate 0) (string-to-number (match-string 1))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
319 rate-type (or (and rate-type |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
320 (if (string= rate-type (match-string 2)) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
321 rate-type |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
322 (error |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
323 "Inconsistent rate types (%s vs. %s)" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
324 rate-type (match-string 2)))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
325 (match-string 2)))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
326 (when (re-search-forward "remaining capacity: +\\([0-9]+\\) m[AW]h$" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
327 nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
328 (setq capacity |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
329 (+ (or capacity 0) (string-to-number (match-string 1)))))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
330 (goto-char (point-max)) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
331 (ignore-errors (insert-file-contents (expand-file-name "info" dir))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
332 (when (re-search-forward "present: +yes$" nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
333 (when (re-search-forward "design capacity: +\\([0-9]+\\) m[AW]h$" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
334 nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
335 (incf design-capacity (string-to-number (match-string 1)))) |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
336 (when (re-search-forward "last full capacity: +\\([0-9]+\\) m[AW]h$" |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
337 nil t) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
338 (incf last-full-capacity (string-to-number (match-string 1)))) |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
339 (when (re-search-forward |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
340 "design capacity warning: +\\([0-9]+\\) m[AW]h$" nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
341 (incf warn (string-to-number (match-string 1)))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
342 (when (re-search-forward "design capacity low: +\\([0-9]+\\) m[AW]h$" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
343 nil t) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
344 (incf low (string-to-number (match-string 1))))))) |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
345 (setq full-capacity (if (> last-full-capacity 0) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
346 last-full-capacity design-capacity)) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
347 (and capacity rate |
55904
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
348 (setq minutes (if (zerop rate) 0 |
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
349 (floor (* (/ (float (if (string= charging-state |
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
350 "charging") |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
351 (- full-capacity capacity) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
352 capacity)) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
353 rate) |
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
354 60))) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
355 hours (/ minutes 60))) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
356 (list (cons ?c (or (and capacity (number-to-string capacity)) "N/A")) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
357 (cons ?L (or (battery-search-for-one-match-in-files |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
358 (mapcar (lambda (e) (concat e "/state")) |
75178
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
359 (ignore-errors |
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
360 (directory-files "/proc/acpi/ac_adapter/" |
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
361 t "\\`[^.]"))) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
362 "state: +\\(.*\\)$" 1) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
363 |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
364 "N/A")) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
365 (cons ?d (or (battery-search-for-one-match-in-files |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
366 (mapcar (lambda (e) (concat e "/temperature")) |
75178
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
367 (ignore-errors |
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
368 (directory-files "/proc/acpi/thermal_zone/" |
b01847d9a51b
(battery-linux-proc-acpi): Use ignore-errors around calls to directory-files.
Richard M. Stallman <rms@gnu.org>
parents:
75139
diff
changeset
|
369 t "\\`[^.]"))) |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
370 "temperature: +\\([0-9]+\\) C$" 1) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
371 |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
372 "N/A")) |
55904
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
373 (cons ?r (or (and rate (concat (number-to-string rate) " " |
f3be7c4dc1e6
(battery-linux-proc-acpi): mA was hardcored, but some
Eli Zaretskii <eliz@gnu.org>
parents:
52470
diff
changeset
|
374 rate-type)) "N/A")) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
375 (cons ?B (or charging-state "N/A")) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
376 (cons ?b (or (and (string= charging-state "charging") "+") |
69414
a159957988d5
(battery-linux-proc-acpi): Check `capacity' for non-nil
Juri Linkov <juri@jurta.org>
parents:
69381
diff
changeset
|
377 (and capacity (< capacity low) "!") |
a159957988d5
(battery-linux-proc-acpi): Check `capacity' for non-nil
Juri Linkov <juri@jurta.org>
parents:
69381
diff
changeset
|
378 (and capacity (< capacity warn) "-") |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
379 "")) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
380 (cons ?h (or (and hours (number-to-string hours)) "N/A")) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
381 (cons ?m (or (and minutes (number-to-string minutes)) "N/A")) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
382 (cons ?t (or (and minutes |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
383 (format "%d:%02d" hours (- minutes (* 60 hours)))) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
384 "N/A")) |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
385 (cons ?p (or (and full-capacity capacity |
73599
65d9fbabd719
* battery.el (battery-linux-proc-acpi): Prevent range error when
Chong Yidong <cyd@stupidchicken.com>
parents:
70539
diff
changeset
|
386 (> full-capacity 0) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
387 (number-to-string |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
388 (floor (/ capacity |
68266
0d67eef96242
(battery-linux-proc-acpi): Handle "last full capacity".
Richard M. Stallman <rms@gnu.org>
parents:
67802
diff
changeset
|
389 (/ (float full-capacity) 100))))) |
52450
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
390 "N/A"))))) |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
391 |
d096f00804db
(battery-linux-proc-acpi): New function.
Eli Zaretskii <eliz@gnu.org>
parents:
52401
diff
changeset
|
392 |
64094
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
393 ;;; `pmset' interface for Darwin (OS X). |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
394 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
395 (defun battery-pmset () |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
396 "Get battery status information using `pmset'. |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
397 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
398 The following %-sequences are provided: |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
399 %L Power source (verbose) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
400 %B Battery status (verbose) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
401 %b Battery status, empty means high, `-' means low, |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
402 `!' means critical, and `+' means charging |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
403 %p Battery load percentage |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
404 %h Remaining time in hours |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
405 %m Remaining time in minutes |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
406 %t Remaining time in the form `h:min'" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
407 (let (power-source load-percentage battery-status battery-status-symbol |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
408 remaining-time hours minutes) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
409 (with-temp-buffer |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
410 (ignore-errors (call-process "pmset" nil t nil "-g" "ps")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
411 (goto-char (point-min)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
412 (when (re-search-forward "Currentl?y drawing from '\\(AC\\|Battery\\) Power'" nil t) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
413 (setq power-source (match-string 1)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
414 (when (re-search-forward "^ -InternalBattery-0[ \t]+" nil t) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
415 (when (looking-at "\\([0-9]\\{1,3\\}\\)%") |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
416 (setq load-percentage (match-string 1)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
417 (goto-char (match-end 0)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
418 (cond ((looking-at "; charging") |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
419 (setq battery-status "charging" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
420 battery-status-symbol "+")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
421 ((< (string-to-number load-percentage) battery-load-low) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
422 (setq battery-status "low" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
423 battery-status-symbol "-")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
424 ((< (string-to-number load-percentage) battery-load-critical) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
425 (setq battery-status "critical" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
426 battery-status-symbol "!")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
427 (t |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
428 (setq battery-status "high" |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
429 battery-status-symbol ""))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
430 (when (re-search-forward "\\(\\([0-9]+\\):\\([0-9]+\\)\\) remaining" nil t) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
431 (setq remaining-time (match-string 1)) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
432 (let ((h (string-to-number (match-string 2))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
433 (m (string-to-number (match-string 3)))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
434 (setq hours (number-to-string (+ h (if (< m 30) 0 1))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
435 minutes (number-to-string (+ (* h 60) m))))))))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
436 (list (cons ?L (or power-source "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
437 (cons ?p (or load-percentage "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
438 (cons ?B (or battery-status "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
439 (cons ?b (or battery-status-symbol "")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
440 (cons ?h (or hours "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
441 (cons ?m (or minutes "N/A")) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
442 (cons ?t (or remaining-time "N/A"))))) |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
443 |
e960506e0661
Add support for Darwin (with much debugging help from Samuel Lauber
Lute Kamstra <lute@gnu.org>
parents:
64091
diff
changeset
|
444 |
18388 | 445 ;;; Private functions. |
446 | |
447 (defun battery-format (format alist) | |
448 "Substitute %-sequences in FORMAT." | |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
449 (replace-regexp-in-string |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
450 "%." |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
451 (lambda (str) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
452 (let ((char (aref str 1))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
453 (if (eq char ?%) "%" |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
454 (or (cdr (assoc char alist)) "")))) |
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
455 format t t)) |
18388 | 456 |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
457 (defun battery-search-for-one-match-in-files (files regexp match-num) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
458 "Search REGEXP in the content of the files listed in FILES. |
75139
685bae49b575
(battery-search-for-one-match-in-files): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
73700
diff
changeset
|
459 If a match occurred, return the parenthesized expression numbered by |
73700
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
460 MATCH-NUM in the match. Otherwise, return nil." |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
461 (with-temp-buffer |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
462 (catch 'found |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
463 (dolist (file files) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
464 (and (ignore-errors (insert-file-contents file nil nil nil 'replace)) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
465 (re-search-forward regexp nil t) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
466 (throw 'found (match-string match-num))))))) |
294b1de9ac5f
2006-11-05 Micha?Cadilhac <michael.cadilhac@lrde.org>
Romain Francoise <romain@orebokech.com>
parents:
73599
diff
changeset
|
467 |
18388 | 468 |
469 (provide 'battery) | |
470 | |
57143
b628e08b0230
(battery-linux-proc-apm): Use string-to-number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57133
diff
changeset
|
471 ;; arch-tag: 65916f50-4754-4b6b-ac21-0b510f545a37 |
18388 | 472 ;;; battery.el ends here |