From: Ellington Santos <ellingtonsantos@gmail.com>
To: 41542@debbugs.gnu.org
Subject: bug#41542: 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 [thread overview]
Message-ID: <87eer64vyo.fsf@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 90 bytes --]
This patch implements %b battery status to battery-linux-sysfs in
emacs-26.3 battery.el
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: battery_sysfs_b_status.patch --]
[-- Type: text/x-patch, Size: 1766 bytes --]
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"
[-- Attachment #3: Type: text/plain, Size: 41 bytes --]
--
Atenciosamente,
Ellington Santos
next reply other threads:[~2020-05-26 14:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-26 14:22 Ellington Santos [this message]
2020-05-26 14:37 ` bug#41542: Diff patch wrong in my last post. Follow right one Ellington Santos
2020-06-06 7:58 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87eer64vyo.fsf@gmail.com \
--to=ellingtonsantos@gmail.com \
--cc=41542@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).