emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 07b2e9b909: Fix BSD battery mode over TRAMP (bug#58307)


From: Lars Ingebrigtsen
Subject: master 07b2e9b909: Fix BSD battery mode over TRAMP (bug#58307)
Date: Thu, 6 Oct 2022 08:47:31 -0400 (EDT)

branch: master
commit 07b2e9b9092df57f454386e54491420fb4b5f303
Author: Manuel Giraud <manuel@ledu-giraud.fr>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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'
    (bug#58307).
---
 lisp/battery.el | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lisp/battery.el b/lisp/battery.el
index 72b3dfdae7..a874f0640e 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -914,6 +914,15 @@ The following %-sequences are provided:
 
 ;;; `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,16 @@ The following %-sequences are provided:
 %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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]