From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Ellington Santos Newsgroups: gmane.emacs.bugs 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 Message-ID: <87eer64vyo.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="61651"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.7; emacs 26.3 To: 41542@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 26 16:27:29 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jdaYD-000G0R-DD for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 May 2020 16:27:29 +0200 Original-Received: from localhost ([::1]:52528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdaYC-0003mI-AM for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 26 May 2020 10:27:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdaTv-0001V6-4J for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 10:23:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34509) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdaTt-0000QG-U3 for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 10:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jdaTt-0001le-R3 for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 10:23:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ellington Santos Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 May 2020 14:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41542 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15905029676759 (code B ref -1); Tue, 26 May 2020 14:23:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 May 2020 14:22:47 +0000 Original-Received: from localhost ([127.0.0.1]:46055 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jdaTf-0001kx-Dz for submit@debbugs.gnu.org; Tue, 26 May 2020 10:22:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:50980) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jdaTd-0001ko-JU for submit@debbugs.gnu.org; Tue, 26 May 2020 10:22:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdaTd-0001Qn-E6 for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 10:22:45 -0400 Original-Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]:36908) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdaTc-0000Ac-Id for bug-gnu-emacs@gnu.org; Tue, 26 May 2020 10:22:45 -0400 Original-Received: by mail-qt1-x82e.google.com with SMTP id x29so3010794qtv.4 for ; Tue, 26 May 2020 07:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:message-id:date:mime-version; bh=4PxTvOeN7J4oLupX747UJHPsR5n7QKWBU2gaS9bi1UI=; b=igNJ0bDjfzzv9lYbPyJmZL1ikgtHI2WcUpbMO4L9cmMug73z6onb5+8aWk2j8SAmh0 Sc9Gk65XPx7Pftp46CAty7+cdUNmkhZfc9MIihht0UHdZgkTmg/7WC3pcOrYgaOJLcA7 jbqrwlh/TK9IsyI+cnvefoK0czd3CO3+9RAritEVBvJE8frPTs61Ke1nCMrQE/rS751/ ct0iK63XItUIQVD//oNdCh0oyDKLHt3fDh0XjTlm757A7wSb/SR7sVPCedgea59xyZV+ 2DYmegeQb76IIa/i3Yqq13dGlIvwFa1Qn+Jt7WGicStFfRBaAbSWtF6jy9KA3tNjggLg ZYvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:message-id:date :mime-version; bh=4PxTvOeN7J4oLupX747UJHPsR5n7QKWBU2gaS9bi1UI=; b=pyO2pNQlADYi3AeE7bEUCRMHS5+LPZId1gTP/6zOed4II/U2V8gtoghr5FmC+CJF/Z qD6x+QvcuH7Irzfd2UBg1vFuAd9v7QrVRaSdCFoUNUepCXxTGzriFdTu3ym7SS3SvfYt SUUdt0H853pnbiRC+4EJWeCXpHXJ8mtMG8gXHllo1QkXse4wmLoCvEJOGzdqmjodCySH uM34ZsHMAH6xlVEQs7l+rfcU6KxyWFpMQ90Ax7wo60TDWrYHCHJS77Kpq1nmq9zXRGoa /hv4rC9gcCR+WjMIU9CHuKgpAaI2hlGbpZJRPtNX3eSZ4diM6C9oHG8wx2PXpbofgvX5 mf2A== X-Gm-Message-State: AOAM531Jalq5hAjC5KV1ZALKXRa+TM+kxi7wi+JzrFCugiKGUGlpB7o3 HFL6+yW3jbcSU5coitYKkw97EY+S X-Google-Smtp-Source: ABdhPJxyCKcCrc4r0IUPtbcZMFeWNEmulioj5kXtiskl/ftmhi7a3GrmLOsVao0/pZZVVxtY9iNjmA== X-Received: by 2002:ac8:2df9:: with SMTP id q54mr1438117qta.215.1590502962487; Tue, 26 May 2020 07:22:42 -0700 (PDT) Original-Received: from x250.gmail.com ([201.17.106.129]) by smtp.gmail.com with ESMTPSA id m6sm16785884qkc.4.2020.05.26.07.22.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 07:22:41 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::82e; envelope-from=ellingtonsantos@gmail.com; helo=mail-qt1-x82e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181035 Archived-At: --=-=-= Content-Type: text/plain; format=flowed This patch implements %b battery status to battery-linux-sysfs in emacs-26.3 battery.el --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=battery_sysfs_b_status.patch 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" --=-=-= Content-Type: text/plain; format=flowed -- Atenciosamente, Ellington Santos --=-=-=--