unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#17319: 24.3.50; Error when battery-status-function reports "N/A"
@ 2014-04-23  5:29 Nicolas Richard
  2014-04-25 18:02 ` Stefan Monnier
  2014-04-28  0:23 ` Glenn Morris
  0 siblings, 2 replies; 3+ messages in thread
From: Nicolas Richard @ 2014-04-23  5:29 UTC (permalink / raw)
  To: 17319

Hello,

When I open the lid of my laptop, it might happen that the percentage is
"N/A". battery.el assumed it is a number. I suggest the following patch
to avoid the lisp error (sorry I did not save the backtrace).

In GNU Emacs 24.3.50.7 (i686-pc-linux-gnu, GTK+ Version 2.24.20)
 of 2014-04-10 on LDLC-portable
Windowing system distributor `The X.Org Foundation', version 11.0.11405000
System Description:	Ubuntu 13.10

Configured using:
 `configure 'CFLAGS=-g3 -O2''

Important settings:
  value of $LANG: fr_BE.UTF-8
  locale-coding-system: utf-8-unix



2 files changed, 16 insertions(+), 9 deletions(-)
 lisp/ChangeLog  |  4 ++++
 lisp/battery.el | 21 ++++++++++++---------

	Modified   lisp/ChangeLog
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a31aa5d..d81712f 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2014-04-11  Nicolas Richard  <theonewiththeevillook@yahoo.fr>
+
+	* battery.el (battery-update): Handle the case where battery
+	status is "N/A".
 2014-04-23  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* simple.el (completion-list-mode-map): Use choose-completion for the
	Modified   lisp/battery.el
diff --git a/lisp/battery.el b/lisp/battery.el
index 1eef80a..768ed78 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -201,19 +201,22 @@ 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)
+			       (or
+                                (not (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)
+		      (or
+                       (not (numberp percentage))
+                       (and (<= percentage
+                                battery-load-critical)
+                            'error))
 		      'help-echo "Battery status information")))
   (force-mode-line-update))
 \f
-- 
Nico.





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#17319: 24.3.50; Error when battery-status-function reports "N/A"
  2014-04-23  5:29 bug#17319: 24.3.50; Error when battery-status-function reports "N/A" Nicolas Richard
@ 2014-04-25 18:02 ` Stefan Monnier
  2014-04-28  0:23 ` Glenn Morris
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2014-04-25 18:02 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: 17319-done

> When I open the lid of my laptop, it might happen that the percentage is
> "N/A". battery.el assumed it is a number. I suggest the following patch
> to avoid the lisp error (sorry I did not save the backtrace).

Thanks, installed in emacs-24.


        Stefan





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#17319: 24.3.50; Error when battery-status-function reports "N/A"
  2014-04-23  5:29 bug#17319: 24.3.50; Error when battery-status-function reports "N/A" Nicolas Richard
  2014-04-25 18:02 ` Stefan Monnier
@ 2014-04-28  0:23 ` Glenn Morris
  1 sibling, 0 replies; 3+ messages in thread
From: Glenn Morris @ 2014-04-28  0:23 UTC (permalink / raw)
  To: 17319-done

Version: 24.4

Looks like this was applied.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-28  0:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-23  5:29 bug#17319: 24.3.50; Error when battery-status-function reports "N/A" Nicolas Richard
2014-04-25 18:02 ` Stefan Monnier
2014-04-28  0:23 ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).