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

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

[nongnu] elpa/bash-completion f6e1c44057 013/313: put everything togethe


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion f6e1c44057 013/313: put everything together
Date: Sat, 3 Dec 2022 10:59:11 -0500 (EST)

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

    put everything together
---
 bash-complete.el      | 34 ++++++++++++++++++++++------------
 bash-complete_test.el |  4 ++++
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/bash-complete.el b/bash-complete.el
index 0a2547d2f3..78f2d96980 100644
--- a/bash-complete.el
+++ b/bash-complete.el
@@ -28,18 +28,23 @@ Call bash to do the completion."
     (bash-complete-dynamic-complete-0)))
 
 (defun bash-complete-dynamic-complete-0 ()
-  (save-excursion
     (let* ( (pos (point))
            (start (comint-line-beginning-position))
            (end (line-end-position))
            (line (buffer-substring-no-properties start end))
-           (wordsplit (bash-complete-split start end pos))
-           (words (car wordsplit))
-           (cword (cdr wordsplit))
-           (stub (nth cword words)) )
-      (comint-simple-complete stub
-                             (bash-complete-comm
-                              line pos words cword)))))
+           (wordsplit)
+           (cword)
+           (words)
+           (stub) )
+      (save-excursion
+       (setq wordsplit (bash-complete-split start end pos))
+       (setq cword (car wordsplit))
+       (setq words (cdr wordsplit))
+       (setq stub (nth cword words)))
+      (comint-dynamic-simple-complete
+       stub
+       (bash-complete-comm
+       line (- pos start) words cword))))
 
 (defun bash-complete-join (words)
   "Join WORDS into a shell line, escaped all words with single quotes"
@@ -126,7 +131,12 @@ calls compgen.
 The result is a list of candidates, which might be empty."
   (bash-complete-send (concat (bash-complete-generate-line line pos words 
cword) " 2>/dev/null"))
   (with-current-buffer (bash-complete-buffer)
-    (split-string (buffer-string) "\n" t)))
+    (mapcar 'bash-complete-trim (split-string (buffer-string) "\n" t))))
+
+(defun bash-complete-trim (str)
+  (if (string-match "^ *\\(.*[^ ]\\) *$" str)
+      (match-string 1 str)
+    str))
 
 (defun bash-complete-require-process ()
   ;; TODO(szermatt): if this fails, kill process and complain
@@ -157,13 +167,13 @@ The result is a list of candidates, which might be empty."
            (let ((function-name (car (cdr function))))
              (setcar function "-F")
              (setcar (cdr function) "__bash_complete_wrapper")
-             (format "__BASH_COMPLETE_WRAPPER=%s compgen %s %s"
-                     (bash-complete-quote (format "COMP_LINE=%s; COMP_POS=%s; 
COMP_CWORD=%s; COMP_WORDS=( %s ); %s \"$@\""
+             (format "__BASH_COMPLETE_WRAPPER=%s compgen %s -- %s"
+                     (bash-complete-quote (format "COMP_LINE=%s; 
COMP_POINT=%s; COMP_CWORD=%s; COMP_WORDS=( %s ); %s \"$@\""
                                                   (bash-complete-quote line) 
pos cword (bash-complete-join words)
                                                   (bash-complete-quote 
function-name)))
                      (bash-complete-join args)
                      (bash-complete-quote (nth cword words))))
-         (format "compgen %s %s" (bash-complete-join args) (nth cword 
words)))))))
+         (format "compgen %s -- %s" (bash-complete-join args) (nth cword 
words)))))))
 
 (defun bash-complete-kill-process ()
   (when (bash-complete-is-running)
diff --git a/bash-complete_test.el b/bash-complete_test.el
index 3969b7303c..3a77c25ba7 100644
--- a/bash-complete_test.el
+++ b/bash-complete_test.el
@@ -187,6 +187,10 @@ garbage
        (bash-complete-generate-line "zorg worl" 7 '("zorg" "worl") 1))
       "__BASH_COMPLETE_WRAPPER='COMP_LINE='\\''zorg worl'\\''; COMP_POS=7; 
COMP_CWORD=1; COMP_WORDS=( zorg worl ); __zorg \"$@\"' compgen -F 
__bash_complete_wrapper worl")
 
+     ("bash-complete-trim"
+      (mapcar 'bash-complete-trim '("  hello " "  world   " "x"))
+      '("hello" "world" "x"))
+
       )))
 
 



reply via email to

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