Skip to content

Commit 7965b91

Browse files
committed
Re-enable directory expansion for custom completion. fixes #23
I tured off directory expansion (adding a trailing /) by mistake when refactoring the expansion code. While doing directory expansion is not necessarily always the right thing to do with custom completion, it usually is. This commit turns it back on. issue #19 should allow properly configuring this behavior command-by-command.
1 parent 1c2153d commit 7965b91

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

bash-completion.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ for directory name detection to work."
837837
(eq ?/ last-char))
838838
(setq suffix ""))
839839
((and
840-
(memq completion-type '(command default wordbreak))
840+
(memq completion-type '(command default wordbreak custom))
841841
(file-accessible-directory-p
842842
(expand-file-name (bash-completion-unescape
843843
open-quote (concat parsed-prefix rest))

test/bash-completion-test.el

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ before calling `bash-completion-dynamic-complete-nocomint'.
915915
'("--color=")
916916
(nth 2 (bash-completion-dynamic-complete-nocomint 3 (point))))))))
917917

918-
(ert-deftest bash-completion-single-custom-completion-as-directory ()
918+
(ert-deftest bash-completion-single-custom-completion-as-directory-explicit ()
919919
(--with-fake-bash-completion-send
920920
(setq bash-completion-alist '(("ls" "compgen" "args")))
921921
(push "somedir/\n" --send-results)
@@ -925,6 +925,19 @@ before calling `bash-completion-dynamic-complete-nocomint'.
925925
'("somedir/")
926926
(nth 2 (bash-completion-dynamic-complete-nocomint 3 (point))))))))
927927

928+
(ert-deftest bash-completion-single-custom-completion-as-directory-implicit ()
929+
(--with-fake-bash-completion-send
930+
(setq bash-completion-alist '(("ls" "compgen" "args")))
931+
;; note that adding a / after a completion is not always the right thing
932+
;; to do. See github issue #19.
933+
(push "/tmp/test/somedir" --directories)
934+
(push "somedir\n" --send-results)
935+
(insert "$ ls some")
936+
(let ((bash-completion-nospace nil))
937+
(should (equal
938+
'("somedir/")
939+
(nth 2 (bash-completion-dynamic-complete-nocomint 3 (point))))))))
940+
928941
(ert-deftest bash-completion-custom-completion-with-fallback ()
929942
(--with-fake-bash-completion-send
930943
(setq bash-completion-alist '(("ls" "compgen" "args")))

0 commit comments

Comments
 (0)