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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/bash-completion 34221c1fdd 185/313: Make bash-completion-e


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion 34221c1fdd 185/313: Make bash-completion-enable-caching the default, remove the
Date: Sat, 3 Dec 2022 10:59:29 -0500 (EST)

branch: elpa/bash-completion
commit 34221c1fdd02230218c2964998eb6115150f51df
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>

    Make bash-completion-enable-caching the default, remove the
    customization.
    
    With this commit, always return a dynamic table completion when doing
    completion from comint.
    
    To preserve backward compatibility,
    `bash-completion-dynamic-complete-nocomint' still returns a list of
    candidates instead of a lambda, unless passed an optional argument.
    
    Issue #30
---
 bash-completion.el                       | 37 +++++++++++---------------------
 test/bash-completion-integration-test.el |  6 ------
 test/bash-completion-test.el             | 13 ++++++++++-
 3 files changed, 24 insertions(+), 32 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index c73586775e..bce01221f7 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -197,26 +197,6 @@ to remove the extra space bash adds after a completion."
   :type '(boolean)
   :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'.
-
-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.
-
-Wordbreak completions behaves slightly differently when this operation is
-enabled."
-        :type 'boolean
-        :group 'bash-completion)
-  (defconst bash-completion-enable-caching nil))
-
-(defalias 'bash-completion--completion-table-with-cache
-  (if (fboundp 'completion-table-with-cache)
-      'completion-table-with-cache 'completion-table-dynamic))
-
 (defvar bash-completion-start-files
   '("~/.emacs_bash.sh" "~/.emacs.d/init_bash.sh")
   "Shell files that, if they exist, will be sourced at the
@@ -366,13 +346,19 @@ When doing completion outside of a comint buffer, call
       (unwind-protect
           (bash-completion-dynamic-complete-nocomint
            (comint-line-beginning-position)
-           (point))
+           (point)
+           'dynamic-table)
         ;; cleanup
         (if message-timer
             (cancel-timer message-timer)))))
 
+(defalias 'bash-completion--completion-table-with-cache
+  (if (fboundp 'completion-table-with-cache)
+      'completion-table-with-cache 'completion-table-dynamic))
+
 ;;;###autoload
-(defun bash-completion-dynamic-complete-nocomint (comp-start comp-pos)
+(defun bash-completion-dynamic-complete-nocomint
+    (comp-start comp-pos &optional dynamic-table)
   "Return completion information for bash command at an arbitrary position.
 
 The bash command to be completed begins at COMP-START in the
@@ -385,8 +371,9 @@ It is meant to be called directly from any completion 
engine.
 Returns (list stub-start stub-end completions) with
  - stub-start, the position at which the completed region starts
  - stub-end, the position at which the completed region ends
- - completions, a possibly empty list of completion candidates or a function if
-   `bash-completion-enable-caching' is non-nil"
+ - completions, a possibly empty list of completion candidates
+   or a function, if DYNAMIC-TABLE is non-nil, a lambda such as the one
+   returned by `completion-table-dynamic'"
   (when bash-completion-enabled
     (let* ((process (bash-completion-require-process))
            (comp (bash-completion--parse
@@ -397,7 +384,7 @@ Returns (list stub-start stub-end completions) with
       (list
        stub-start
        comp-pos
-       (if bash-completion-enable-caching
+       (if dynamic-table
            (bash-completion--completion-table-with-cache
             (lambda (_)
               (bash-completion-comm comp process)))
diff --git a/test/bash-completion-integration-test.el 
b/test/bash-completion-integration-test.el
index 5a29b1a086..452eb387cc 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -38,7 +38,6 @@
      (let ((test-env-dir (bash-completion_test-setup-env)))
        (let ((bash-completion-processes nil)
              (bash-completion-nospace nil)
-             (bash-completion-enable-caching nil)
              (bash-completion-start-files nil)
              (bash-completion-args
               (list "--noediting"
@@ -142,11 +141,6 @@ for testing completion."
   (bash-completion_test-with-shell-harness
    (bash-completion-integration-test-complete)))
 
-(ert-deftest bash-completion-integration-completion-test-with-caching ()
-  (bash-completion_test-with-shell-harness
-   (setq bash-completion-enable-caching t)
-   (bash-completion-integration-test-complete)))
-
 (defun bash-completion-integration-test-complete ()
    ;; complete command
    (should (equal "somefunction "
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index afb202f193..7472d75edc 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -863,7 +863,6 @@ before calling `bash-completion-dynamic-complete-nocomint'.
   `(let ((default-directory "/tmp/test")
          (bash-completion-alist '())
          (wordbreaks "@><=;|&(:")
-         (bash-completion-enable-caching nil)
          (bash-completion-nospace nil))
      (lexical-let ((--process-buffer)
                    (--test-buffer)
@@ -911,6 +910,18 @@ before calling `bash-completion-dynamic-complete-nocomint'.
    (should (equal "cd >/dev/null 2>&1 /tmp/test ; compgen -o default -- he 
2>/dev/null"
                   (pop --captured-commands)))))
 
+(ert-deftest bash-completion-simple-dynamic-table-test ()
+  (--with-fake-bash-completion-send
+   (push "hell\nhello1\nhello2\n" --send-results)
+   (insert "$ cat he")
+   (pcase-let ((`(,stub-start ,stub-end ,completions)
+                (bash-completion-dynamic-complete-nocomint
+                 3 (point) 'dynamic-table)))
+     (should (equal 7 stub-start))
+     (should (equal 9 stub-end))
+     (should (equal '("hell" "hello1" "hello2")
+                    (funcall completions "he" nil t))))))
+
 (ert-deftest bash-completion-single-completion-test ()
   (--with-fake-bash-completion-send
    (push "hello\n" --send-results)



reply via email to

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