From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Joakim Jalap Newsgroups: gmane.emacs.bugs Subject: bug#24919: 24.5; battery.el not working in FreeBSD Date: Fri, 11 Nov 2016 18:58:39 +0100 Message-ID: <86twbd525s.fsf@fastmail.com> References: <86lgyq2k1l.fsf@gaia.hq.xin.cat> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1478880161 5962 195.159.176.226 (11 Nov 2016 16:02:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 11 Nov 2016 16:02:41 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (berkeley-unix) Cc: 24919@debbugs.gnu.org To: Ignacio Torres Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Nov 11 17:02:35 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c5EHM-00076l-K5 for geb-bug-gnu-emacs@m.gmane.org; Fri, 11 Nov 2016 17:02:12 +0100 Original-Received: from localhost ([::1]:53737 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5EHP-0003DC-PN for geb-bug-gnu-emacs@m.gmane.org; Fri, 11 Nov 2016 11:02:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5EHG-0003D6-FU for bug-gnu-emacs@gnu.org; Fri, 11 Nov 2016 11:02:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c5EHC-0006RI-Is for bug-gnu-emacs@gnu.org; Fri, 11 Nov 2016 11:02:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c5EHC-0006Qm-CF for bug-gnu-emacs@gnu.org; Fri, 11 Nov 2016 11:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1c5EHC-0008Dh-1K for bug-gnu-emacs@gnu.org; Fri, 11 Nov 2016 11:02:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Joakim Jalap Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 11 Nov 2016 16:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24919 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24919-submit@debbugs.gnu.org id=B24919.147888009931567 (code B ref 24919); Fri, 11 Nov 2016 16:02:01 +0000 Original-Received: (at 24919) by debbugs.gnu.org; 11 Nov 2016 16:01:39 +0000 Original-Received: from localhost ([127.0.0.1]:54096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c5EGo-0008D5-T2 for submit@debbugs.gnu.org; Fri, 11 Nov 2016 11:01:39 -0500 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:39413) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c5EGn-0008Cx-AD for 24919@debbugs.gnu.org; Fri, 11 Nov 2016 11:01:37 -0500 Original-Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 04E032067C; Fri, 11 Nov 2016 11:01:37 -0500 (EST) Original-Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Fri, 11 Nov 2016 11:01:37 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h=cc :content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=YyNTNGvT632lv86W6jXn/OiArDU=; b=5/kfCN M64H8z/DORfxuk3r1BqPT2ax97hrLaTjDucge/FgmJNG2tGgzfA13Cu+BVTubHEs I1KtoNzJWxPIam8fC/vZkr2qjt7ho/u9zUZcQhpOpJASJm/ZTKwsv8Gcnj6kaaF0 wkKMx8LJUDgV0Suo/AdnMSiLiRL21jenqWx/g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=YyNTNGvT632lv8 6W6jXn/OiArDU=; b=JA5LRCMM0oZ+kr39W/ALT86ou55+X+dotcCr26YZ+dKGc5 Ibo8A2SMLWTCkxbYxbZQ6nLgAUkic0K1EOavuoL0oZbv1LpJXFSGYs1MD4/4Vbkm gQOgbOVdZhNg425VzbZ8eD1WzDthT2BvtSZSpX18Kn5Rs9yPqkAP8NfTH9Y2I= X-ME-Sender: X-Sasl-enc: 0ah51GriacpeHj2gIGh+7NWDQyI2ltgxapuWDVAfuo6E 1478880096 Original-Received: from serv (unknown [5.150.202.248]) by mail.messagingengine.com (Postfix) with ESMTPA id 1DED925081; Fri, 11 Nov 2016 11:01:36 -0500 (EST) In-Reply-To: <86lgyq2k1l.fsf@gaia.hq.xin.cat> (Ignacio Torres's message of "Sun, 18 Sep 2016 01:17:26 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:125626 Archived-At: --=-=-= Content-Type: text/plain Ignacio Torres writes: > Running M-x battery in FreeBSD returns: > > Power disconnected, battery high (illegal% load, remaining time 0:00) > Here's a patch witch makes it return something else :) Unfortunately I can't tets it on an actual laptop atm, but I /think/ it might work. -- Joakim --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Fix-M-x-battery-on-FreeBSD.patch Content-Description: patch >From 8af54346db52ce1939632a60cac0cbd5c5f77063 Mon Sep 17 00:00:00 2001 From: Joakim Jalap Date: Fri, 11 Nov 2016 18:00:22 +0100 Subject: [PATCH] Fix M-x battery on FreeBSD * lisp/battery.el (battery-bsd-apm): Fix to work with FreeBSD's apm(8) --- lisp/battery.el | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lisp/battery.el b/lisp/battery.el index e6e79b0..ddb0114 100644 --- a/lisp/battery.el +++ b/lisp/battery.el @@ -552,30 +552,40 @@ battery-bsd-apm %t Remaining battery charge time in the form `h:min'" (let* ((os-name (car (split-string (shell-command-to-string "/usr/bin/uname")))) - (apm-flag (if (equal os-name "OpenBSD") "P" "s")) - (apm-cmd (concat "/usr/sbin/apm -ablm" apm-flag)) + (os-freebsd (string= os-name "FreeBSD")) + (os-openbsd (string= os-name "OpenBSD")) + (battery-status-idx (if os-freebsd 1 0)) + (percentage-idx (if os-freebsd 2 1)) + (life-idx (if os-freebsd 4 2)) + (line-status-idx (if os-freebsd 0 3)) + (mode-idx (if os-freebsd 3 4)) + (apm-flags + (cond (os-freebsd "-ablts") + (os-openbsd "-ablmP") + (t "-ablms"))) + (apm-cmd (concat "/usr/sbin/apm " apm-flags)) (apm-output (split-string (shell-command-to-string apm-cmd))) ;; Battery status (battery-status - (let ((stat (string-to-number (nth 0 apm-output)))) + (let ((stat (string-to-number (nth battery-status-idx apm-output)))) (cond ((eq stat 0) '("high" . "")) ((eq stat 1) '("low" . "-")) ((eq stat 2) '("critical" . "!")) ((eq stat 3) '("charging" . "+")) ((eq stat 4) '("absent" . nil))))) ;; Battery percentage - (battery-percentage (nth 1 apm-output)) + (battery-percentage (nth percentage-idx apm-output)) ;; Battery life - (battery-life (nth 2 apm-output)) + (battery-life (nth life-idx apm-output)) ;; AC status (line-status - (let ((ac (string-to-number (nth 3 apm-output)))) + (let ((ac (string-to-number (nth line-status-idx apm-output)))) (cond ((eq ac 0) "disconnected") ((eq ac 1) "connected") ((eq ac 2) "backup power")))) ;; Advanced power savings mode (apm-mode - (let ((apm (string-to-number (nth 4 apm-output)))) + (let ((apm (string-to-number (nth mode-idx apm-output)))) (if (string= os-name "OpenBSD") (cond ((eq apm 0) "manual") ((eq apm 1) "automatic") -- 2.9.2 --=-=-=--