X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/01fcc3a532872b29784a4d888ab9cc1aef0eed01..f0ee9096ba9f35b9e6b85fb5c5f5f56168a67824:/lisp/battery.el diff --git a/lisp/battery.el b/lisp/battery.el index 98ba7d1b63..b49363489a 100644 --- a/lisp/battery.el +++ b/lisp/battery.el @@ -1,6 +1,6 @@ -;;; battery.el --- display battery status information -*- coding: iso-8859-1 -*- +;;; battery.el --- display battery status information -*- coding: utf-8 -*- -;; Copyright (C) 1997-1998, 2000-2013 Free Software Foundation, Inc. +;; Copyright (C) 1997-1998, 2000-2014 Free Software Foundation, Inc. ;; Author: Ralph Schleicher ;; Keywords: hardware @@ -116,7 +116,7 @@ string are substituted as defined by the current value of the variable (defcustom battery-mode-line-format (cond ((eq battery-status-function 'battery-linux-proc-acpi) - "[%b%p%%,%d°C]") + "[%b%p%%,%d°C]") (battery-status-function "[%b%p%%]")) "Control string formatting the string to display in the mode line. @@ -201,19 +201,18 @@ seconds." (defun battery-update () "Update battery status information in the mode line." - (let ((data (and battery-status-function (funcall battery-status-function)))) + (let* ((data (and battery-status-function (funcall battery-status-function))) + (percentage (car (read-from-string (cdr (assq ?p data)))))) (setq battery-mode-line-string (propertize (if (and battery-mode-line-format - (<= (car (read-from-string (cdr (assq ?p data)))) - battery-mode-line-limit)) - (battery-format - battery-mode-line-format - data) + (numberp percentage) + (<= percentage battery-mode-line-limit)) + (battery-format battery-mode-line-format data) "") 'face - (and (<= (car (read-from-string (cdr (assq ?p data)))) - battery-load-critical) - 'error) + (and (numberp percentage) + (<= percentage battery-load-critical) + 'error) 'help-echo "Battery status information"))) (force-mode-line-update)) @@ -458,12 +457,15 @@ The following %-sequences are provided: (and (re-search-forward "POWER_SUPPLY_STATUS=\\(.*\\)$" nil t) (member charging-state '("Unknown" "Full" nil)) (setq charging-state (match-string 1))) + (goto-char (point-min)) (when (re-search-forward "POWER_SUPPLY_\\(CURRENT\\|POWER\\)_NOW=\\([0-9]*\\)$" nil t) (setq rate (float (string-to-number (match-string 2))))) + (goto-char (point-min)) (when (re-search-forward "POWER_SUPPLY_TEMP=\\([0-9]*\\)$" nil t) (setq temperature (match-string 1))) + (goto-char (point-min)) (let (full-string now-string) ;; Sysfs may list either charge (mAh) or energy (mWh). ;; Keep track of both, and choose which to report later. @@ -477,7 +479,8 @@ The following %-sequences are provided: (string-to-number full-string)) charge-now (+ charge-now (string-to-number now-string)))) - ((and (re-search-forward + ((and (progn (goto-char (point-min)) t) + (re-search-forward "POWER_SUPPLY_ENERGY_FULL=\\([0-9]*\\)$" nil t) (setq full-string (match-string 1)) (re-search-forward @@ -615,7 +618,7 @@ The following %-sequences are provided: (with-temp-buffer (ignore-errors (call-process "pmset" nil t nil "-g" "ps")) (goto-char (point-min)) - (when (re-search-forward "Currentl?y drawing from '\\(AC\\|Battery\\) Power'" nil t) + (when (re-search-forward "\\(?:Currentl?y\\|Now\\) drawing from '\\(AC\\|Battery\\) Power'" nil t) (setq power-source (match-string 1)) (when (re-search-forward "^ -InternalBattery-0[ \t]+" nil t) (when (looking-at "\\([0-9]\\{1,3\\}\\)%")