X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/0f4a15f89c4363a259741ddaebd36db5d43fb76c..892f9671ada52150f280915fb34970b7acb0312a:/lisp/battery.el diff --git a/lisp/battery.el b/lisp/battery.el index 7b17232160..42ceec0c90 100644 --- a/lisp/battery.el +++ b/lisp/battery.el @@ -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 @@ -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))