all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: yikai@z1k.dev
To: 59678@debbugs.gnu.org
Cc: Yikai Zhao <yikai@z1k.dev>
Subject: bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance
Date: Tue, 29 Nov 2022 22:30:14 +0800	[thread overview]
Message-ID: <20221129143013.191469-1-yikai@z1k.dev> (raw)

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






             reply	other threads:[~2022-11-29 14:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29 14:30 yikai [this message]
2022-12-01 15:46 ` bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance Eli Zaretskii
2022-12-01 20:30   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 13:45     ` Eli Zaretskii
2022-12-02 17:01     ` Yikai Zhao
2022-12-02 13:44 ` Eli Zaretskii
2022-12-02 17:00   ` Yikai Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221129143013.191469-1-yikai@z1k.dev \
    --to=yikai@z1k.dev \
    --cc=59678@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.