]> code.delx.au - gnu-emacs/blobdiff - lisp/battery.el
Merged from miles@gnu.org--gnu-2005 (patch 296-306)
[gnu-emacs] / lisp / battery.el
index 7b17232160244342b8663df98facb1c58e5f4bcf..42ceec0c90cf9f14e48b6322cf7c4766db1d575a 100644 (file)
@@ -1,6 +1,6 @@
 ;;; battery.el --- display battery status information
 
-;; Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004
+;; Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004, 2005
 ;;           Free Software Foundation, Inc.
 
 ;; Author: Ralph Schleicher <rs@nunatak.allgaeu.org>
@@ -73,12 +73,13 @@ string are substituted as defined by the current value of the variable
 
 (defvar battery-mode-line-string nil
   "String to display in the mode line.")
+;;;###autoload (put 'battery-mode-line-string 'risky-local-variable t)
 
 (defcustom battery-mode-line-format
   (cond ((eq battery-status-function 'battery-linux-proc-apm)
-        " [%b%p%%]")
+        "[%b%p%%]")
        ((eq battery-status-function 'battery-linux-proc-acpi)
-        " [%b%p%%,%d°C]"))
+        "[%b%p%%,%d°C]"))
   "*Control string formatting the string to display in the mode line.
 Ordinary characters in the control string are printed as-is, while
 conversion specifications introduced by a `%' character in the control
@@ -107,20 +108,23 @@ The text being displayed in the echo area is controlled by the variables
                  "Battery status not available")))
 
 ;;;###autoload
-(defun display-battery ()
+(define-minor-mode display-battery-mode
   "Display battery status information in the mode line.
 The text being displayed in the mode line is controlled by the variables
 `battery-mode-line-format' and `battery-status-function'.
 The mode line will be updated automatically every `battery-update-interval'
 seconds."
-  (interactive)
+  :global t :group 'battery
   (setq battery-mode-line-string "")
   (or global-mode-string (setq global-mode-string '("")))
-  (add-to-list 'global-mode-string 'battery-mode-line-string t)
   (and battery-update-timer (cancel-timer battery-update-timer))
-  (setq battery-update-timer (run-at-time nil battery-update-interval
-                                         'battery-update-handler))
-  (battery-update))
+  (if (not display-battery-mode)
+      (setq global-mode-string
+           (delq 'battery-mode-line-string global-mode-string))
+    (add-to-list 'global-mode-string 'battery-mode-line-string t)
+    (setq battery-update-timer (run-at-time nil battery-update-interval
+                                           'battery-update-handler))
+    (battery-update)))
 
 (defun battery-update-handler ()
   (battery-update)
@@ -128,13 +132,14 @@ seconds."
 
 (defun battery-update ()
   "Update battery status information in the mode line."
-  (setq battery-mode-line-string (propertize (if (and battery-mode-line-format
-                                                     battery-status-function)
-                                                (battery-format
-                                                 battery-mode-line-format
-                                                 (funcall battery-status-function))
-                                              "")
-                                            'help-echo "Battery status information"))
+  (setq battery-mode-line-string
+       (propertize (if (and battery-mode-line-format
+                            battery-status-function)
+                       (battery-format
+                        battery-mode-line-format
+                        (funcall battery-status-function))
+                     "")
+                   'help-echo "Battery status information"))
   (force-mode-line-update))
 
 \f