From 6a8c9eafb92f15fd9194cb38499008f1f4579e20 Mon Sep 17 00:00:00 2001 From: Dan Nicolaescu Date: Wed, 11 Apr 2012 01:24:31 +0200 Subject: [PATCH] battery.el not working when multiple batteries are present * battery.el (battery-linux-proc-acpi): Only one battery is discharged at a time, but that seems to confuse battery.el when computing `rate-type' for the battery not being discharged. Fixes: debbugs:10332 --- lisp/ChangeLog | 7 +++++++ lisp/battery.el | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 135f01d6268..8cdff58369f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2012-04-10 Dan Nicolaescu + + * battery.el (battery-linux-proc-acpi): Only one battery is + discharged at a time, but that seems to confuse battery.el when + computing `rate-type' for the battery not being discharged + (bug#10332). + 2012-04-10 Stefan Monnier * emacs-lisp/autoload.el (autoload-make-program): Remove, unused. diff --git a/lisp/battery.el b/lisp/battery.el index 586be9e8938..5cb10252539 100644 --- a/lisp/battery.el +++ b/lisp/battery.el @@ -344,14 +344,15 @@ The following %-sequences are provided: (setq charging-state (match-string 1))) (when (re-search-forward "present rate: +\\([0-9]+\\) \\(m[AW]\\)$" nil t) - (setq rate (+ (or rate 0) (string-to-number (match-string 1))) - rate-type (or (and rate-type + (setq rate (+ (or rate 0) (string-to-number (match-string 1)))) + (when (> rate 0) + (setq rate-type (or (and rate-type (if (string= rate-type (match-string 2)) rate-type (error "Inconsistent rate types (%s vs. %s)" rate-type (match-string 2)))) - (match-string 2)))) + (match-string 2))))) (when (re-search-forward "remaining capacity: +\\([0-9]+\\) m[AW]h$" nil t) (setq capacity -- 2.11.4.GIT