GNU bug report logs - #41542
Implement %b status to battery-linux-sysfs in emacs 26.3 (with better percentage-now treatment)

Previous Next

Package: emacs;

Reported by: Ellington Santos <ellingtonsantos <at> gmail.com>

Date: Tue, 26 May 2020 14:23:01 UTC

Severity: wishlist

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 41542 in the body.
You can then email your comments to 41542 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#41542; Package emacs. (Tue, 26 May 2020 14:23:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ellington Santos <ellingtonsantos <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 26 May 2020 14:23:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ellington Santos <ellingtonsantos <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Implement %b status to battery-linux-sysfs in emacs 26.3 (with better
 percentage-now treatment)
Date: Tue, 26 May 2020 11:22:39 -0300
[Message part 1 (text/plain, inline)]
This patch implements %b battery status to battery-linux-sysfs in 
emacs-26.3 battery.el

[battery_sysfs_b_status.patch (text/x-patch, inline)]
diff --git a/lisp/battery.el b/lisp/battery.el
index e23dab4c91..b5c12653e1 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -433,13 +433,15 @@ The following %-sequences are provided:
 %c Current capacity (mAh or mWh)
 %r Current rate
 %B Battery status (verbose)
+%b Battery status, empty means high, `-' means low,
+   `!' means critical, and `+' means charging
 %d Temperature (in degrees Celsius)
 %p Battery load percentage
 %L AC line status (verbose)
 %m Remaining time (to charge or discharge) in minutes
 %h Remaining time (to charge or discharge) in hours
 %t Remaining time (to charge or discharge) in the form `h:min'"
-  (let (charging-state temperature hours
+  (let (charging-state temperature hours percentage-now
         ;; Some batteries report charges and current, other energy and power.
         ;; In order to reliably be able to combine those data, we convert them
         ;; all to energy/power (since we can't combine different charges if
@@ -522,10 +524,13 @@ The following %-sequences are provided:
 		     "N/A"))
 	  (cons ?d (or temperature "N/A"))
 	  (cons ?B (or charging-state "N/A"))
-	  (cons ?p (cond ((and (> energy-full 0) (> energy-now 0))
-			  (format "%.1f"
-				  (/ (* 100 energy-now) energy-full)))
-			 (t "N/A")))
+	  (cons ?b (or (and (string= charging-state "Charging") "+")
+		       (and percentage-now (< percentage-now battery-load-critical) "!")
+		       (and percentage-now (< percentage-now battery-load-low) "-")
+		       ""))
+	  (cons ?p (cond
+                    ((and percentage-now (format "%.1f" percentage-now)))
+                    (t "N/A")))
 	  (cons ?L (cond
                     ((battery-search-for-one-match-in-files
                       (list "/sys/class/power_supply/AC/online"
[Message part 3 (text/plain, inline)]

-- 

Atenciosamente,

Ellington Santos

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#41542; Package emacs. (Tue, 26 May 2020 14:38:02 GMT) Full text and rfc822 format available.

Message #8 received at 41542 <at> debbugs.gnu.org (full text, mbox):

From: Ellington Santos <ellingtonsantos <at> gmail.com>
To: 41542 <at> debbugs.gnu.org
Subject: Diff patch wrong in my last post. Follow right one
Date: Tue, 26 May 2020 11:37:04 -0300
[battery_sysfs_b_status.patch (text/x-patch, inline)]
diff --git a/lisp/battery.el b/lisp/battery.el
index e23dab4c91..309f43f8cd 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -433,13 +433,15 @@ The following %-sequences are provided:
 %c Current capacity (mAh or mWh)
 %r Current rate
 %B Battery status (verbose)
+%b Battery status, empty means high, `-' means low,
+   `!' means critical, and `+' means charging
 %d Temperature (in degrees Celsius)
 %p Battery load percentage
 %L AC line status (verbose)
 %m Remaining time (to charge or discharge) in minutes
 %h Remaining time (to charge or discharge) in hours
 %t Remaining time (to charge or discharge) in the form `h:min'"
-  (let (charging-state temperature hours
+  (let (charging-state temperature hours percentage-now
         ;; Some batteries report charges and current, other energy and power.
         ;; In order to reliably be able to combine those data, we convert them
         ;; all to energy/power (since we can't combine different charges if
@@ -509,6 +511,8 @@ The following %-sequences are provided:
 				 energy-now
 			       (- energy-full energy-now))))
 	      (setq hours (/ remaining power-now)))))))
+    (when (and (> energy-full 0) (> energy-now 0))
+      (setq percentage-now (/ (* 100 energy-now) energy-full)))
     (list (cons ?c (cond ((or (> energy-full 0) (> energy-now 0))
 			  (number-to-string (/ energy-now voltage-now)))
 			 (t "N/A")))
@@ -522,10 +526,13 @@ The following %-sequences are provided:
 		     "N/A"))
 	  (cons ?d (or temperature "N/A"))
 	  (cons ?B (or charging-state "N/A"))
-	  (cons ?p (cond ((and (> energy-full 0) (> energy-now 0))
-			  (format "%.1f"
-				  (/ (* 100 energy-now) energy-full)))
-			 (t "N/A")))
+	  (cons ?b (or (and (string= charging-state "Charging") "+")
+		       (and percentage-now (< percentage-now battery-load-critical) "!")
+		       (and percentage-now (< percentage-now battery-load-low) "-")
+		       ""))
+	  (cons ?p (cond
+                    ((and percentage-now (format "%.1f" percentage-now)))
+                    (t "N/A")))
 	  (cons ?L (cond
                     ((battery-search-for-one-match-in-files
                       (list "/sys/class/power_supply/AC/online"
[Message part 2 (text/plain, inline)]
-- 

Atenciosamente,

Ellington Santos

Severity set to 'wishlist' from 'normal' Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 27 May 2020 21:29:02 GMT) Full text and rfc822 format available.

Added tag(s) patch. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 27 May 2020 21:29:03 GMT) Full text and rfc822 format available.

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 06 Jun 2020 07:59:03 GMT) Full text and rfc822 format available.

Notification sent to Ellington Santos <ellingtonsantos <at> gmail.com>:
bug acknowledged by developer. (Sat, 06 Jun 2020 07:59:03 GMT) Full text and rfc822 format available.

Message #17 received at 41542-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ellington Santos <ellingtonsantos <at> gmail.com>
Cc: 41542-done <at> debbugs.gnu.org
Subject: Re: bug#41542: Diff patch wrong in my last post. Follow right one
Date: Sat, 06 Jun 2020 10:58:33 +0300
> From: Ellington Santos <ellingtonsantos <at> gmail.com>
> Date: Tue, 26 May 2020 11:37:04 -0300
> 
> diff --git a/lisp/battery.el b/lisp/battery.el
> index e23dab4c91..309f43f8cd 100644
> --- a/lisp/battery.el
> +++ b/lisp/battery.el

Thanks, I installed this on the master branch.

In the future, please also provide a ChangeLog-style commit log
message, as described in CONTRIBUTE.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 04 Jul 2020 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 356 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.