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

[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



reply via email to

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