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

[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



reply via email to

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