emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/exec-path-from-shell f8e39d754c 023/114: Tidier code for d


From: ELPA Syncer
Subject: [nongnu] elpa/exec-path-from-shell f8e39d754c 023/114: Tidier code for double-quoting printf args
Date: Tue, 5 Sep 2023 03:59:58 -0400 (EDT)

branch: elpa/exec-path-from-shell
commit f8e39d754ca944d56f7a86463dd78de76da0a41d
Author: Steve Purcell <steve@sanityinc.com>
Commit: Steve Purcell <steve@sanityinc.com>

    Tidier code for double-quoting printf args
---
 exec-path-from-shell.el | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/exec-path-from-shell.el b/exec-path-from-shell.el
index 188c18cb2b..b8decdf75a 100644
--- a/exec-path-from-shell.el
+++ b/exec-path-from-shell.el
@@ -66,6 +66,10 @@
   "List of environment variables which are copied from the shell."
   :group 'exec-path-from-shell)
 
+(defun exec-path-from-shell--double-quote (s)
+  "Double-quote S, escaping any double-quotes already contained in it."
+  (concat "\"" (replace-regexp-in-string "\"" "\\\\\"" s) "\""))
+
 (defun exec-path-from-shell-printf (str &optional args)
   "Return the result of printing STR in the user's shell.
 
@@ -77,11 +81,10 @@ by printf.
 
 ARGS is an optional list of args which will be inserted by printf
 in place of any % placeholders in STR.  ARGS are not automatically
-shell-escaped, so that may contain $ etc."
-  (let ((printf-command (concat "printf '__RESULT\\000" str "' "
-                                (mapconcat (lambda (a) (concat "\"" a "\""))
-                                           args
-                                           " "))))
+shell-escaped, so they may contain $ etc."
+  (let ((printf-command
+         (concat "printf '__RESULT\\000" str "' "
+                 (mapconcat #'exec-path-from-shell--double-quote args " "))))
     (with-temp-buffer
       (call-process (getenv "SHELL") nil (current-buffer) nil
                     "--login" "-i" "-c" printf-command)



reply via email to

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