GNU bug report logs - #41540
Implement %b status to battery-linux-sysfs in emacs 26.3

Previous Next

Package: emacs;

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

Date: Tue, 26 May 2020 14:02:02 UTC

Severity: normal

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

Forwarded to https://debbugs.gnu.org/41542

Full log


View this message in rfc822 format

From: Ellington Santos <ellingtonsantos <at> gmail.com>
To: 41540 <at> debbugs.gnu.org
Subject: bug#41540: Implement %b status to battery-linux-sysfs in emacs 26.3
Date: Tue, 26 May 2020 11:01:18 -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..1d5969762f 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 (format "%.1f" (/ (* 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,11 @@ 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 (or percentage-now "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

This bug report was last modified 4 years and 357 days ago.

Previous Next


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