all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Manuel Giraud <manuel@ledu-giraud.fr>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: 58307@debbugs.gnu.org
Subject: bug#58307: 29.0.50; Fix battery mode over TRAMP on *BSD
Date: Thu, 06 Oct 2022 10:17:17 +0200	[thread overview]
Message-ID: <87ilkxl62a.fsf@elite.giraud> (raw)
In-Reply-To: <CADwFkmm7_6WJEvbzEpq+hyjQn3+GNn56mzyFOBdMQSCwWBmcmg@mail.gmail.com> (Stefan Kangas's message of "Wed, 5 Oct 2022 15:51:35 -0700")

[-- Attachment #1: Type: text/plain, Size: 123 bytes --]

Thank you Stefan and Michael!

Here is an updated version.  My wording in the comment might not be
correct.  Best regards.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-BSD-battery-mode-over-TRAMP-bug-58307.patch --]
[-- Type: text/x-patch, Size: 2257 bytes --]

From f9b1ee4df0280daab91a103fde4ee3a707d4224c Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Wed, 5 Oct 2022 15:59:14 +0200
Subject: [PATCH] Fix BSD battery mode over TRAMP (bug#58307)

* lisp/battery.el (battery--call-process-to-string): Simple wrapper
  to `call-process' that outputs to a string.
  (battery-bsd-apm): Use it instead of `shell-command-to-string'.
---
 lisp/battery.el | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/battery.el b/lisp/battery.el
index 72b3dfdae7..4c83f8a7d3 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -914,6 +914,15 @@ battery-upower
 \f
 ;;; `apm' interface for BSD.
 
+;; This function is a wrapper on `call-process' that return the
+;; standard output in a string.  We are using it instead
+;; `shell-command-to-string' because this last one is trying to run
+;; PROGRAM on the remote host if the buffer is remote.
+(defun battery--call-process-to-string (program &rest args)
+  (with-output-to-string
+    (with-current-buffer standard-output
+      (apply #'call-process program nil t nil args))))
+
 (defun battery-bsd-apm ()
   "Get APM status information from BSD apm binary.
 The following %-sequences are provided:
@@ -929,13 +938,14 @@ battery-bsd-apm
 %t Remaining time (to charge or discharge) in the form `h:min'"
   (let* ((os-name (car (split-string
                         ;; FIXME: Can't we use something like `system-type'?
-                        (shell-command-to-string "/usr/bin/uname"))))
+                        (battery--call-process-to-string (executable-find "uname")))))
          (apm-flag (pcase os-name
                      ("OpenBSD" "mP")
                      ("FreeBSD" "st")
                      (_         "ms")))
-         (apm-cmd (concat "/usr/sbin/apm -abl" apm-flag))
-         (apm-output (split-string (shell-command-to-string apm-cmd)))
+         (apm-args (concat "-abl" apm-flag))
+         (apm-output (split-string
+                      (battery--call-process-to-string (executable-find "apm") apm-args)))
          (indices (pcase os-name
                     ;; FreeBSD's manpage documents that multiple
                     ;; outputs are ordered by "the order in which
-- 
2.37.3


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

  reply	other threads:[~2022-10-06  8:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05 14:52 bug#58307: 29.0.50; Fix battery mode over TRAMP on *BSD Manuel Giraud
2022-10-05 20:24 ` Michael Albinus
2022-10-05 22:51 ` Stefan Kangas
2022-10-06  8:17   ` Manuel Giraud [this message]
2022-10-06 12:47     ` Lars Ingebrigtsen
2022-10-06 14:34       ` Manuel Giraud
2022-10-06 18:20         ` Stefan Kangas

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ilkxl62a.fsf@elite.giraud \
    --to=manuel@ledu-giraud.fr \
    --cc=58307@debbugs.gnu.org \
    --cc=stefankangas@gmail.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.