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

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

[nongnu] elpa/bash-completion c3797e0d09 277/313: Avoid running the same


From: ELPA Syncer
Subject: [nongnu] elpa/bash-completion c3797e0d09 277/313: Avoid running the same completion multiple times.
Date: Sat, 3 Dec 2022 10:59:37 -0500 (EST)

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

    Avoid running the same completion multiple times.
    
    Before this change bash-completion--completion-table-with-cache was
    not caching aggressively enough. It used to check the string argument,
    which was useless since the COMP argument cannot change anyways. The
    completions returned by bash are just meant to be used as they are.
---
 bash-completion.el                       | 25 +++++++++++--------------
 test/bash-completion-integration-test.el | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/bash-completion.el b/bash-completion.el
index 4b48c8f7ab..874dacaee0 100644
--- a/bash-completion.el
+++ b/bash-completion.el
@@ -1578,28 +1578,25 @@ Return the parsed value, as a string or nil."
 
 The result is a function that works like one built by
 `completion-table-with-cache' with the difference that the
-completions, built by `bash-completion-comm' are complete
-and that completion style doesn't necessarily use substring
-completion."
-  (let ((last-str) (last-result)
+completions, built by `bash-completion-comm' are not filtered
+using the current Emacs completion style."
+  (let ((last-result)
         (calling-buffer (current-buffer))
         (dir default-directory)
         (use-separate-process bash-completion-use-separate-processes)
         (nospace bash-completion-nospace))
-    (lambda (str predicate action)
+    (lambda (_str predicate action)
       (if (or (eq (car-safe action) 'boundaries)
               (eq action 'metadata))
           nil
         (let ((result
-               (if (equal str last-str)
-                   last-result
-                 (let ((bash-completion-use-separate-processes 
use-separate-process)
-                       (bash-completion-nospace nospace)
-                       (default-directory dir))
-                   (with-current-buffer calling-buffer
-                     (bash-completion-comm comp process))))))
-          (setq last-str str
-                last-result result)
+               (or last-result
+                   (let ((bash-completion-use-separate-processes 
use-separate-process)
+                         (bash-completion-nospace nospace)
+                         (default-directory dir))
+                     (with-current-buffer calling-buffer
+                       (bash-completion-comm comp process))))))
+          (setq last-result result)
           (let ((filtered-result (if predicate (mapcar predicate result) 
result))
                 (completion-ignore-case (process-get process 
'completion-ignore-case)))
             (cond
diff --git a/test/bash-completion-integration-test.el 
b/test/bash-completion-integration-test.el
index be9765f5aa..827cfbad87 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -538,4 +538,22 @@ $ ")))))
    (let ((default-directory "/does-not-exist/"))
      (should (equal "ls some/" (bash-completion_test-complete "ls so"))))))
 
+(ert-deftest bash-completion-integration-caching ()
+  "Make sure caching works and that completion is only executed once."
+  (bash-completion_test-with-shell-harness
+   (concat ; .bashrc
+    "PS1='$ '\n"
+    "dummycount=0;\n"
+    "function _dummy {\n"
+    "  dummycount=$(( $dummycount + 1 ))\n"
+    "  COMPREPLY=(libra library librarian)\n"
+    "}\n"
+    "function dummy { echo count: ${dummycount}.; }\n"
+    "complete -F _dummy dummy\n")
+   nil ; use-separate-process
+   (bash-completion_test-send "dummy libr" 'complete)
+   (should (string-match
+            (regexp-quote "$ dummy libra\ncount: 1.")
+            (bash-completion_test-buffer-string)))))
+
 ;;; bash-completion-integration-test.el ends here



reply via email to

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