[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)
- [nongnu] elpa/bash-completion 3eb77ec9c4 086/313: Moved shell configuration into config. Got rid of */init.el, going, (continued)
- [nongnu] elpa/bash-completion 3eb77ec9c4 086/313: Moved shell configuration into config. Got rid of */init.el, going, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion abeee42e65 112/313: Set comint-completion-addsuffix again in pre-emacs-24.1 mode., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 920bbc25bf 121/313: Run integration tests successfully on system where "hel" expand to more, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion bac0fb55f1 124/313: More integration test cleanup made possible by the move to ert., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b49dbe1457 127/313: Don't require obsolete and unused cl., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0af9a70ff9 130/313: Merge pull request #16 from tarsius/master, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion d673bf1ed0 132/313: Merge pull request #17 from svend/bash-flags, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1659c7ca38 126/313: Quoting fix: fix parentheses in a file name, improve double quoting within, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 432c2d15c9 142/313: Add a space after the completion candidate for single completion., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0f3f8c22b4 146/313: Add a space after a single custom completion., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion eacb8061e3 147/313: Fallback to filename completion when custom completion didn't find,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 081d03bedc 156/313: Fix issue #21 completion bug, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1c2153d287 159/313: Call make-obsolete with three arguments, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 7965b914da 160/313: Re-enable directory expansion for custom completion. fixes #23, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2c0b8d6a6e 163/313: Merge pull request #27 from vorburger/patch-1, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 0c77c64b50 174/313: Disable bash-completion-enable-caching if completion-table-with-cache, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b281e1e181 008/313: bash-complete-add-to-alist, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1144ae69a9 056/313: documented the tokenizer, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 376dd532e2 057/313: modre documentation, up until wordbreak, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion fd7e0e6fbe 078/313: added documentation, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion dd34b278bf 069/313: stopping at point; the easy way, ELPA Syncer, 2022/12/03