emacs-bug-tracker
[Top][All Lists]
Advanced

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

bug#59678: closed ([PATCH] sh-script: use completion-table-with-cache to


From: GNU bug Tracking System
Subject: bug#59678: closed ([PATCH] sh-script: use completion-table-with-cache to improve performance)
Date: Fri, 02 Dec 2022 13:45:01 +0000

Your message dated Fri, 02 Dec 2022 15:44:11 +0200
with message-id <83k039gbtg.fsf@gnu.org>
and subject line Re: bug#59678: [PATCH] sh-script: use 
completion-table-with-cache to improve performance
has caused the debbugs.gnu.org bug report #59678,
regarding [PATCH] sh-script: use completion-table-with-cache to improve 
performance
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
59678: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59678
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: [PATCH] sh-script: use completion-table-with-cache to improve performance Date: Tue, 29 Nov 2022 22:30:14 +0800
Hi,

I found that the auto-completion on .sh files (with company-mode) was pretty 
slow (takes several seconds).
It turns out that company-mode would call the capf function with 'metadata 
action for each candidate,
where each function call would need to list all the cmds. In this patch, I 
modified the code to use
completion-table-with-cache which fixes the problem for me.



---
 lisp/progmodes/sh-script.el | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 408ebfc0451..188b3b73125 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1688,19 +1688,17 @@ sh--vars-before-point
 ;; (defun sh--var-completion-table (string pred action)
 ;;   (complete-with-action action (sh--vars-before-point) string pred))
 
-(defun sh--cmd-completion-table (string pred action)
-  (let ((cmds
-         (append (when (fboundp 'imenu--make-index-alist)
-                   (mapcar #'car
-                           (condition-case nil
-                               (imenu--make-index-alist)
-                             (imenu-unavailable nil))))
-                 (mapcar (lambda (v) (concat v "="))
-                         (sh--vars-before-point))
-                 (locate-file-completion-table
-                  exec-path exec-suffixes string pred t)
-                 sh--completion-keywords)))
-    (complete-with-action action cmds string pred)))
+(defun sh--cmd-completion-table-gen (string)
+  (append (when (fboundp 'imenu--make-index-alist)
+            (mapcar #'car
+                    (condition-case nil
+                        (imenu--make-index-alist)
+                      (imenu-unavailable nil))))
+          (mapcar (lambda (v) (concat v "="))
+                  (sh--vars-before-point))
+          (locate-file-completion-table
+           exec-path exec-suffixes string nil t)
+          sh--completion-keywords))
 
 (defun sh-completion-at-point-function ()
   (save-excursion
@@ -1713,7 +1711,7 @@ sh-completion-at-point-function
         (list start end (sh--vars-before-point)
               :company-kind (lambda (_) 'variable)))
        ((sh-smie--keyword-p)
-        (list start end #'sh--cmd-completion-table
+        (list start end (completion-table-with-cache 
#'sh--cmd-completion-table-gen)
               :company-kind
               (lambda (s)
                 (cond
-- 
2.38.1




--- End Message ---
--- Begin Message --- Subject: Re: bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance Date: Fri, 02 Dec 2022 15:44:11 +0200
> Cc: Yikai Zhao <yikai@z1k.dev>
> From: yikai@z1k.dev
> Date: Tue, 29 Nov 2022 22:30:14 +0800
> 
> Hi,
> 
> I found that the auto-completion on .sh files (with company-mode) was pretty 
> slow (takes several seconds).
> It turns out that company-mode would call the capf function with 'metadata 
> action for each candidate,
> where each function call would need to list all the cmds. In this patch, I 
> modified the code to use
> completion-table-with-cache which fixes the problem for me.

Thanks, installed on the emacs-29 branch.

In the future, please accompany your changes with ChangeLog-style commit of
messages (see CONTRIBUTE for the details).


--- End Message ---

reply via email to

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