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

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

[nongnu] elpa/bash-completion eacb8061e3 147/313: Fallback to filename c


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion eacb8061e3 147/313: Fallback to filename completion when custom completion didn't find
Date: Sat, 3 Dec 2022 10:59:25 -0500 (EST)

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

    Fallback to filename completion when custom completion didn't find
    anything.
    
    b475788 fixed what looked like a bug, where wordbreak completion was run
    even when there was no word breaks. Turns out, this was a feature, even
    though it was introduced by mistake: it ran filename completion as a
    fallback, when the first attempt didn't find anything.
    
    This commit puts the feature back explicitly, but only runs filename
    completion as fallback after custom completion, since the other
    completion types already ran filename completion.
    
    issue #19 should eventually make that behavior configurable.
---
 bash-completion-test.el | 10 ++++++++++
 bash-completion.el      | 42 +++++++++++++++++++++++++++++-------------
 2 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/bash-completion-test.el b/bash-completion-test.el
index a9f18d6b71..f9a5b2ee1f 100644
--- a/bash-completion-test.el
+++ b/bash-completion-test.el
@@ -906,5 +906,15 @@ before calling `bash-completion-dynamic-complete-nocomint'.
               '("somedir/")
               (nth 2 (bash-completion-dynamic-complete-nocomint 3 
(point))))))))
 
+(ert-deftest bash-completion-custom-completion-with-fallback ()
+  (--with-fake-bash-completion-send
+   (setq bash-completion-alist '(("ls" "compgen" "args")))
+   (setq --send-results '("" "foo\nfoobar\n"))
+   (insert "$ ls fo")
+   (let ((bash-completion-nospace nil))
+     (should (equal
+              '("foo" "foobar")
+              (nth 2 (bash-completion-dynamic-complete-nocomint 3 
(point))))))))
+
 
 ;;; bash-completion_test.el ends here
diff --git a/bash-completion.el b/bash-completion.el
index 6b644bcbf2..0c44a8121b 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -383,16 +383,26 @@ This function is not meant to be called outside of
                      separator-pos-in-unparsed
                      (length unparsed-stub))))
     (when (> (length before-wordbreak) 0)
-      (bash-completion-send (concat
-                            (bash-completion-cd-command-prefix)
-                            "compgen -o default -- "
-                            (bash-completion-quote after-wordbreak)))
-      (let ((completions
-            (bash-completion-extract-candidates
-              after-wordbreak unparsed-after-wordbreak open-quote 'wordbreak)))
-       (list (+ stub-start separator-pos-in-unparsed)
-              pos
-             completions)))))
+      (list (+ stub-start separator-pos-in-unparsed)
+            pos
+            (bash-completion--default-completion
+             after-wordbreak unparsed-after-wordbreak
+             open-quote 'wordbreak)))))
+
+(defun bash-completion--default-completion
+    (stub unparsed-stub open-quote completion-type)
+  "Do default completion on the given STUB.
+
+Return the extracted candidate, with STUB replaced with
+UNPARSED-STUB, taking OPEN-QUOTE into account. COMPLETION-TYPE is
+passed, eventually, to `bash-completion-fix'"
+  (when (eq 0 (bash-completion-send (concat
+                                     (bash-completion-cd-command-prefix)
+                                     "compgen -o default -- "
+                                     (bash-completion-quote stub))))
+    (bash-completion-extract-candidates
+     stub unparsed-stub open-quote
+     (or completion-type 'default))))
          
 ;;; ---------- Functions: parsing and tokenizing
 
@@ -684,6 +694,7 @@ The result is a list of candidates, which might be empty."
   
   (let ((process (bash-completion-require-process))
         (cmdline)
+        (candidates)
         (completion-status))
     (setq cmdline (bash-completion-generate-line line pos words cword t))
     (setq completion-status (bash-completion-send (cdr cmdline)))
@@ -696,9 +707,14 @@ The result is a list of candidates, which might be empty."
       (bash-completion-build-alist (process-buffer process))
       (setq cmdline (bash-completion-generate-line line pos words cword nil))
       (setq completion-status (bash-completion-send (cdr cmdline))))
-    (when (eq 0 completion-status)
-      (bash-completion-extract-candidates
-       (nth cword words) unparsed-stub open-quote (car cmdline)))))
+    (setq candidates
+          (when (eq 0 completion-status)
+            (bash-completion-extract-candidates
+             (nth cword words) unparsed-stub open-quote (car cmdline))))
+    (if (and (not candidates) (eq 'custom (car cmdline)))
+        (bash-completion--default-completion
+         (nth cword words) unparsed-stub open-quote 'default)
+      candidates)))
 
 (defun bash-completion-extract-candidates
     (parsed-stub unparsed-stub open-quote completion-type)



reply via email to

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