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

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

[nongnu] elpa/bash-completion 208cb5ab76 007/313: Join


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 208cb5ab76 007/313: Join
Date: Sat, 3 Dec 2022 10:59:00 -0500 (EST)

branch: elpa/bash-completion
commit 208cb5ab76d6f24acf6f484f4d67bdd91d92d32e
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>

    Join
---
 bash-complete.el      | 16 ++++++++++------
 bash-complete_test.el |  8 ++++++++
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/bash-complete.el b/bash-complete.el
index d12720c2b0..f769d14afa 100644
--- a/bash-complete.el
+++ b/bash-complete.el
@@ -24,12 +24,16 @@ Call bash to do the completion."
                              (bash-complete-comm
                               line pos words cword)))))
 
-;; "hell o" wor\ ld 'baa baaaa'a"hell o"world a
-
-;; (progn
-;;   (load-library "~/.emacs.d/bash-complete.el")
-;;   (let ((start 64) (end 108))
-;;     (bash-complete-split start end 80)))
+(defun bash-complete-join (words)
+  "Join WORDS into a shell line, escaped all words with single quotes"
+  (if words
+      (concat "'"
+             (mapconcat
+              (lambda (word)
+                (replace-regexp-in-string "'" "\\\'" word :literal t))
+              words "' '")
+             "'")
+    ""))
 
 (defun bash-complete-split (start end pos)
   "Split LINE like bash would do, keep track of current word at POS.
diff --git a/bash-complete_test.el b/bash-complete_test.el
index ed832ec4b4..7f7efe2f71 100644
--- a/bash-complete_test.el
+++ b/bash-complete_test.el
@@ -28,6 +28,14 @@
      ;;   GRADER - the desired result or a sexp which determines
      ;;   how we did
 
+     ("bash-complete-join simple"
+      (bash-complete-join '("a" "hello" "world" "b" "c"))
+      "'a' 'hello' 'world' 'b' 'c'")
+
+     ("bash-complete-join escape quote"
+      (bash-complete-join '("a" "hel'lo" "world" "b" "c"))
+      "'a' 'hel\\'lo' 'world' 'b' 'c'")
+
      ("bash-complete-split simple"
       (sz-testutils-with-buffer
        '("a hello world b c")



reply via email to

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