[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion 2cf76221c2 178/313: Rely on compgen for de
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion 2cf76221c2 178/313: Rely on compgen for default completion, instead of doing it with |
Date: |
Sat, 3 Dec 2022 10:59:28 -0500 (EST) |
branch: elpa/bash-completion
commit 2cf76221c2218fd70b9f389650b0d963d63ada28
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
Rely on compgen for default completion, instead of doing it with
another call to compgen. "-o default" implies filenames option.
Also removes the now useless customization option
for forcing or disabling default and the unnecessary one for
filenames. Only forcing or disabling nospace remains.
This change should result in a behavior closer to bash, while making
fewer calls to compgen, so speeding up completion in general. This
should be especially visible when using tramp
Issue #19
---
bash-completion.el | 66 ++++++++------------------------
test/bash-completion-integration-test.el | 7 ++--
test/bash-completion-test.el | 32 ++++------------
3 files changed, 26 insertions(+), 79 deletions(-)
diff --git a/bash-completion.el b/bash-completion.el
index 33cccc6584..6c6135d71a 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -197,27 +197,6 @@ to remove the extra space bash adds after a completion."
:type '(boolean)
:group 'bash-completion)
-(defcustom bash-completion-default 'as-configured
- "Use default filename completion if a compspec
- generates no matches. Normally configured function by function
- using compgen."
- :type '(choice
- (:tag "As configured" 'as-configured)
- (:tag "Always" t)
- (:tag "Never"))
- :group 'bash-completion)
-
-(defcustom bash-completion-filenames 'as-configured
- "Perform filenames-specific processing on the candidates, such
- as adding a slash to directories or supressing trailing
- characters. Normally configured function by function using
- compgen."
- :type '(choice
- (:tag "As configured" 'as-configured)
- (:tag "Always" t)
- (:tag "Never"))
- :group 'bash-completion)
-
(if (fboundp 'completion-table-with-cache)
(defcustom bash-completion-enable-caching nil
"If non-nil, enable caching in
`bash-completion-dynamic-complete-nocomint'.
@@ -800,7 +779,6 @@ The result is a list of candidates, which might be empty."
(let* ((entry (bash-completion-require-process))
(process (car entry))
- (candidates)
(completion-status)
(options))
(setq completion-status (bash-completion-send
(bash-completion-generate-line comp) process))
@@ -816,20 +794,12 @@ The result is a list of candidates, which might be empty."
(bash-completion--customize comp 'nodefault)
(setq completion-status (bash-completion-send
(bash-completion-generate-line comp) process)))
(setq options (bash-completion--options comp))
- (setq candidates
- (when (eq 0 completion-status)
- (bash-completion-extract-candidates
- (bash-completion--stub comp)
- (bash-completion--unparsed-stub comp)
- (bash-completion--open-quote comp)
- options)))
- (if (and (not candidates) (memq 'default options))
- (bash-completion--default-completion
- (bash-completion--stub comp)
- (bash-completion--unparsed-stub comp)
- (bash-completion--open-quote comp)
- options)
- candidates)))
+ (when (eq 0 completion-status)
+ (bash-completion-extract-candidates
+ (bash-completion--stub comp)
+ (bash-completion--unparsed-stub comp)
+ (bash-completion--open-quote comp)
+ options))))
(defun bash-completion-extract-candidates
(parsed-stub unparsed-stub open-quote options)
@@ -1243,7 +1213,7 @@ completion candidates."
;; custom completion with a function of command
(let* ((args (copy-tree compgen-args))
(function (or (member "-F" args) (member "-C" args)))
- (function-name (car (cdr function))) )
+ (function-name (car (cdr function))))
(setcar function "-F")
(setcar (cdr function) "__bash_complete_wrapper")
(format "__BASH_COMPLETE_WRAPPER=%s compgen %s -- %s"
@@ -1379,43 +1349,37 @@ Return the status code of the command, as a number."
"Parse OPTIONS-STRINGS for compgen into a list of symbols.
Supported options and compgen option equivalent:
- 'default: -o default or -o bashdefault
+ 'default: -o default
'nospace: -o nospace
'filenames: -o filenames"
(let ((options))
- (if (bash-completion--check-option
- option-strings
- '("default" "bashdefault") bash-completion-default)
+ (if (member "default" option-strings)
(push 'default options))
(if (bash-completion--check-option
option-strings
"nospace" bash-completion-nospace)
(push 'nospace options))
- (if (bash-completion--check-option
- option-strings
- "filenames" bash-completion-filenames)
+ (if (or (member "filenames" option-strings)
+ (memq 'default options))
(push 'filenames options))
options))
(defun bash-completion--check-option
- (option-strings option-name-or-names customize-option)
+ (option-strings option-name customize-option)
"Return t if the option should be enabled.
OPTION-STRINGS is a list of compgen option strings, often
generated by `bash-completion--extract-compgen-options'
-OPTION-NAME-OR-NAMES is one or more strings that correspond
-to the option to check.
+OPTION-NAME is a string that correspond to the option to check,
+what follows -o.
CUSTOMIZE-OPTION is a customized value, which is either
'as-configured, to take the option from OPTION-STRINGS, t, to
force it to be always enabled, or nil, to force it to be always
disabled."
(if (eq 'as-configured customize-option)
- (if (listp option-name-or-names)
- (delete nil (mapcar (lambda (name) (member name option-strings))
- option-name-or-names))
- (member option-name-or-names option-strings))
+ (member option-name option-strings)
customize-option))
(provide 'bash-completion)
diff --git a/test/bash-completion-integration-test.el
b/test/bash-completion-integration-test.el
index 2f858f5b33..09d912aa4f 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -38,8 +38,7 @@
(let ((test-env-dir (bash-completion_test-setup-env)))
(let ((bash-completion-processes nil)
(bash-completion-alist nil)
- (bash-completion-nospace nil)
- (bash-completion-default 'as-configured)
+ (bash-completion-nospace 'as-configured)
(bash-completion-enable-caching nil)
(bash-completion-start-files nil)
(bash-completion-args
@@ -154,10 +153,10 @@ for testing completion."
;; custom completion
(should (equal "somefunction dummy "
(bash-completion_test-complete "somefunction du")))
- ;; failed completion, no -o default
+ ;; function returns nothing, no -o default
(should (equal "somefunction so"
(bash-completion_test-complete "somefunction so")))
- ;; failed completion, with -o default
+ ;; function returns nothing, -o default, so fallback to default
(should (equal "someotherfunction some/"
(bash-completion_test-complete "someotherfunction so")))
;; wordbreak completion
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index 4d71e2b761..72295a0192 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -733,7 +733,8 @@ The body is run with a test buffer as current buffer. Fill
it with the command-l
before calling `bash-completion-dynamic-complete-nocomint'.
"
`(let ((default-directory "/tmp/test")
- (bash-completion-alist '()))
+ (bash-completion-alist '())
+ (bash-completion-enable-caching nil))
(lexical-let ((--process-buffer)
(--test-buffer)
(--send-results (list))
@@ -990,16 +991,6 @@ 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" "-o" "default")))
- (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))))))))
-
(ert-deftest bash-completion--extract-compgen-options-test ()
(should (equal '("filenames" "default")
(bash-completion--extract-compgen-options
@@ -1012,9 +1003,7 @@ before calling
`bash-completion-dynamic-complete-nocomint'.
'("-a" "-F" "fun" "-o")))))
(ert-deftest bash-completion--parse-options ()
- (let ((bash-completion-default 'as-configured)
- (bash-completion-nospace 'as-configured)
- (bash-completion-filenames 'as-configured))
+ (let ((bash-completion-nospace 'as-configured))
(should (equal nil (bash-completion--parse-options nil)))
(should (equal '(filenames nospace default)
(bash-completion--parse-options
@@ -1022,18 +1011,13 @@ before calling
`bash-completion-dynamic-complete-nocomint'.
(should (equal '(filenames)
(bash-completion--parse-options
'("filenames"))))
- (should (equal '(default)
- (bash-completion--parse-options
- '("bashdefault"))))
- (setq bash-completion-default nil)
+ (should (equal '(filenames default)
+ (bash-completion--parse-options '("default"))))
(setq bash-completion-nospace nil)
- (setq bash-completion-filenames nil)
(should (equal '() (bash-completion--parse-options
- '("filenames" "nospace" "default"))))
- (setq bash-completion-default t)
+ '("nospace"))))
(setq bash-completion-nospace t)
- (setq bash-completion-filenames t)
- (should (equal '(filenames nospace default)
- (bash-completion--parse-options nil)))))
+ (should (equal '(nospace)
+ (bash-completion--parse-options '())))))
;;; bash-completion_test.el ends here
- [nongnu] elpa/bash-completion 6ab1fe406b 148/313: Always quote the stub before passing it to compgen., (continued)
- [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, 2022/12/03
- [nongnu] elpa/bash-completion 2cf76221c2 178/313: Rely on compgen for default completion, instead of doing it with,
ELPA Syncer <=
- [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
- [nongnu] elpa/bash-completion 24088ede85 196/313: Explicitly mention compatibility with Bash 3 and 4., ELPA Syncer, 2022/12/03