Subject: Re: bug#18157: 24.4.50; battery-pmset fails to report critical battery state

From: Sebastian Wiesner <[email-masked]>
Date: Tue, 16 Feb 2016 19:41:25 +0100

> Am 16.02.2016 um 15:56 schrieb Marcin Borkowski <[email-masked]>:
> 
> On 2014-07-31, at 16:16, Sebastian Wiesner <[email-masked]> wrote:
> 
>> `battery-pmset' fails to correctly report critical battery state:  Even
>> if the battery charge level is below `battery-load-critical', it reports
>> "low" battery state only.
>> 
>> The culprit is the `cond' expression in the body of `battery-pmset'
>> which compares the reported `load-percentage' against `battery-load-low'
>> first, and then against `battery-load-critical'.
>> 
>> Since the latter is typically lower, it will never be reached, because
>> `cond' already returns after the former succeeded.
>> 
>> To fix this issue, `batter-pmset' needs to check `battery-load-critical'
>> *first*, and then `battery-load-low'.
> 
> Does this patch help?

I'm sorry, are you asking me?  It would be bold to believe that I still cared for this issue now, almost *two years* after I reported it.  

At a cursory look the fix surely looks correct, but I hope you understand that Emacs taking two years for what seems to be a trivial issue to fix does not particularly contribute to my enthusiasm, nor does it motivate me to test this patch.

> --8<---------------cut here---------------start------------->8---
> diff -u --label /usr/local/share/emacs/25.1.50/lisp/battery.el.gz --label \#\<buffer\ battery.el.gz\> /tmp/jka-com1889YvM /tmp/buffer-content-1889yDZ
> --- /usr/local/share/emacs/25.1.50/lisp/battery.el.gz
> +++ #<buffer battery.el.gz>
> @@ -628,12 +628,12 @@
> 	    (cond ((looking-at "; charging")
> 		   (setq battery-status "charging"
> 			 battery-status-symbol "+"))
> -		  ((< (string-to-number load-percentage) battery-load-low)
> -		   (setq battery-status "low"
> -			 battery-status-symbol "-"))
> 		  ((< (string-to-number load-percentage) battery-load-critical)
> 		   (setq battery-status "critical"
> 			 battery-status-symbol "!"))
> +		  ((< (string-to-number load-percentage) battery-load-low)
> +		   (setq battery-status "low"
> +			 battery-status-symbol "-"))
> 		  (t
> 		   (setq battery-status "high"
> 			 battery-status-symbol "")))
> 
> Diff finished.  Tue Feb 16 15:56:03 2016
> --8<---------------cut here---------------end--------------->8---
> 
> Best,
> 
> --
> mb