[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 68f7d937b7 175/313: Make wordbreak complet
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 68f7d937b7 175/313: Make wordbreak completion work with bash-completion-enable-caching. |
Date: |
Sat, 3 Dec 2022 10:59:28 -0500 (EST) |
branch: elpa/bash-completion
commit 68f7d937b790caf370b7175c2fd98081a373c590
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
Make wordbreak completion work with bash-completion-enable-caching.
With this commit, wordbreak completion works even when caching is
enabled, though it will look slightly different, as completion appears
to start at the beginning of the argument, instead of the beginning of
the word.
This commit also extends integration test to cover the case where
bash-completion-enable-caching is set.
bash-completion-enable-caching is kept as an option, since it changes
visible behavior.
fixes #30
---
bash-completion.el | 36 +++++++++++++++++++++-----------
test/bash-completion-integration-test.el | 32 ++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 12 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index a742d5ab18..cb262173d3 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -210,9 +210,10 @@ When caching is enabled,
`bash-completion-dynamic-complete-nocomint' returns a function
instead of the list of all possible completions. Enabling caching
improves performance because less calls will be made to
-`bash-completion-comm' which is an expensive function but it has
-one downside: wordbreak completion will not be attempted when a
-compspec returns no matches."
+`bash-completion-comm' which is an expensive function.
+
+Wordbreak completions behaves slightly differently when this operation is
+enabled."
:type 'boolean
:group 'bash-completion)
(defconst bash-completion-enable-caching nil))
@@ -378,23 +379,35 @@ Returns (list stub-start stub-end completions) with
comp-pos
(bash-completion--completion-table-with-cache
(lambda (_)
- (bash-completion-comm line point words cword open-quote
- unparsed-stub))))
- (let ((completions (bash-completion-comm line point words cword
open-quote
- unparsed-stub)))
+ (or (bash-completion-comm line point words cword open-quote
+ unparsed-stub)
+ (pcase-let ((`(,wordbreak-start _ ,wordbreak-collection)
+ (bash-completion--try-wordbreak-complete
+ stub unparsed-stub stub-start comp-pos
+ open-quote)))
+ (if wordbreak-collection
+ ;; prepend the part of unparsed-stub before
+ ;; the wordbreak.
+ (let ((before-wordbreak
+ (substring unparsed-stub 0
+ (- wordbreak-start stub-start))))
+ (mapcar (lambda (c) (concat before-wordbreak c))
+ wordbreak-collection))))))))
+ (let ((completions (bash-completion-comm line point words cword
+ open-quote unparsed-stub)))
(if completions
(list stub-start comp-pos completions)
(bash-completion--try-wordbreak-complete
- stub stub-start comp-pos open-quote)))))))
+ stub unparsed-stub stub-start comp-pos open-quote)))))))
(defun bash-completion--try-wordbreak-complete
- (parsed-stub stub-start pos open-quote)
+ (parsed-stub unparsed-stub stub-start pos open-quote)
"Try wordbreak completion on PARSED-STUB if the complete completion failed.
Split PARSED-STUB using the wordbreak list and apply compgen
default completion on the last part. Return non-nil if a match
-was found. The original version of the stub can be found on the
-buffer, between STUB-START and POS.
+was found. The original version of the stub is UNPARSED-STUB. It
+can be found on the buffer, between STUB-START and POS.
If PARSED-STUB is quoted, the quote character, ' or \", should be
passed to the parameter OPEN-QUOTE.
@@ -405,7 +418,6 @@ This function is not meant to be called outside of
(before-wordbreak (nth 0 wordbreak-split))
(after-wordbreak (nth 1 wordbreak-split))
(separator (nth 2 wordbreak-split))
- (unparsed-stub (buffer-substring-no-properties stub-start pos))
(after-wordbreak-in-unparsed-pos
(1+ (or (bash-completion--find-last separator unparsed-stub) -1)))
(unparsed-after-wordbreak
diff --git a/test/bash-completion-integration-test.el
b/test/bash-completion-integration-test.el
index e949affe8a..f43232edd7 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -101,6 +101,14 @@ for testing completion."
(dired-delete-file test-env-dir 'always))))
(ert-deftest bash-completion-integration-test ()
+ (let ((bash-completion-enable-caching nil))
+ (bash-completion_test-integration)))
+
+(ert-deftest bash-completion-integration-test-with-caching ()
+ (let ((bash-completion-enable-caching t))
+ (bash-completion_test-integration)))
+
+(defun bash-completion_test-integration ()
(if (file-executable-p bash-completion-prog)
(bash-completion_test-harness
(should-not (bash-completion-is-running))
@@ -114,6 +122,14 @@ for testing completion."
(should-not (bash-completion-is-running)))))
(ert-deftest bash-completion-integration-setenv-test ()
+ (let ((bash-completion-enable-caching nil))
+ (bash-completion_test-integration-setenv-test)))
+
+(ert-deftest bash-completion-integration-setenv-test-with-caching ()
+ (let ((bash-completion-enable-caching t))
+ (bash-completion_test-integration-setenv-test)))
+
+(defun bash-completion_test-integration-setenv-test ()
(if (file-executable-p bash-completion-prog)
(bash-completion_test-harness
(bash-completion-send "echo $EMACS_BASH_COMPLETE")
@@ -121,11 +137,27 @@ for testing completion."
(should (equal "t\n" (buffer-string)))))))
(ert-deftest bash-completion-integration-one-completion-test ()
+ (let ((bash-completion-enable-caching nil))
+ (bash-completion_test-integration-one-completion-test)))
+
+(ert-deftest bash-completion-integration-one-completion-test-with-caching ()
+ (let ((bash-completion-enable-caching t))
+ (bash-completion_test-integration-one-completion-test)))
+
+(defun bash-completion_test-integration-one-completion-test ()
(if (file-executable-p bash-completion-prog)
(should (equal "somefunction "
(bash-completion_test-with-shell "somef")))))
(ert-deftest bash-completion-integration-wordbreak-completion-test ()
+ (let ((bash-completion-enable-caching nil))
+ (bash-completion_test-integration-wordbreak-completion-test)))
+
+(ert-deftest
bash-completion-integration-wordbreak-completion-test-with-caching ()
+ (let ((bash-completion-enable-caching t))
+ (bash-completion_test-integration-wordbreak-completion-test)))
+
+(defun bash-completion_test-integration-wordbreak-completion-test ()
(if (file-executable-p bash-completion-prog)
(should (equal "export SOMEPATH=some/directory:some/other/"
(bash-completion_test-with-shell
- [nongnu] elpa/bash-completion b4757884b0 145/313: Expand the tests to better cover wordbreak and command argument, (continued)
- [nongnu] elpa/bash-completion b4757884b0 145/313: Expand the tests to better cover wordbreak and command argument, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6ab1fe406b 148/313: Always quote the stub before passing it to compgen., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a789093cd3 155/313: Run tests on older versions of Emacs., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5e05365dc8 153/313: Cleanup tests, split them into unit and integration tests., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 09c93ffbdb 165/313: Explicitly disable support for Emacs version older than 24.1., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 62c6567af6 158/313: Complete argument rename, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5eb85cf1fc 166/313: Remove obsolete functions bash-completion-dynamic-complete-0 and, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9b94818f88 167/313: Remove support for pre-Emacs24.1 backward compatibility., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 912e1e8153 170/313: Add an option to disable default Readline completion when no matches are found (#29), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 959e27dae3 171/313: Add remote shell support, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 68f7d937b7 175/313: Make wordbreak completion work with bash-completion-enable-caching.,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 2cf76221c2 178/313: Rely on compgen for default completion, instead of doing it with, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f01d8726de 179/313: Remove support filenames options., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5171866b65 180/313: Simplify options a bit, since the only useful option is nospace., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a223260f2d 181/313: Get rid of bash-completion-alist completely., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 4f13e00702 183/313: Execute wordbreak completion "properly", as part of the normal, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 34221c1fdd 185/313: Make bash-completion-enable-caching the default, remove the, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8c3995aa98 187/313: run_tests.sh displays the bash command to test against., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 3eba6922e6 190/313: Use executable-find instead of hardcoding /bin/bash., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 1d41c58bd5 192/313: Send initialization command as one string, as long as possible., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion c5d4f92e6d 195/313: Still EMACS_BASH_COMPLETE using setenv for local processes., ELPA Syncer, 2022/12/03