aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYikai Zhao2022-11-29 22:30:14 +0800
committerEli Zaretskii2022-12-02 15:42:09 +0200
commitf72cda2b822e0726f46a8caa4ec0b8e7ddae2584 (patch)
treeeff86708498ab33098d4dcc6a8786390f39c1924
parente5b0141b0d7231426971763486b9cec0aac77a88 (diff)
downloademacs-f72cda2b822e0726f46a8caa4ec0b8e7ddae2584.tar.gz
emacs-f72cda2b822e0726f46a8caa4ec0b8e7ddae2584.zip
Speed up auto-completion in 'sh-script-mode'
* lisp/progmodes/sh-script.el (sh--cmd-completion-table-gen): New function, replacement for 'sh--cmd-completion-table'. (sh--cmd-completion-table): Function removed. (sh-completion-at-point-function): Use 'sh--cmd-completion-table-gen'. (Bug#59678)
-rw-r--r--lisp/progmodes/sh-script.el30
1 files changed, 14 insertions, 16 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 408ebfc0451..e170d18afeb 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1688,19 +1688,17 @@ This adds rules for comments and assignments."
1688;; (defun sh--var-completion-table (string pred action) 1688;; (defun sh--var-completion-table (string pred action)
1689;; (complete-with-action action (sh--vars-before-point) string pred)) 1689;; (complete-with-action action (sh--vars-before-point) string pred))
1690 1690
1691(defun sh--cmd-completion-table (string pred action) 1691(defun sh--cmd-completion-table-gen (string)
1692 (let ((cmds 1692 (append (when (fboundp 'imenu--make-index-alist)
1693 (append (when (fboundp 'imenu--make-index-alist) 1693 (mapcar #'car
1694 (mapcar #'car 1694 (condition-case nil
1695 (condition-case nil 1695 (imenu--make-index-alist)
1696 (imenu--make-index-alist) 1696 (imenu-unavailable nil))))
1697 (imenu-unavailable nil)))) 1697 (mapcar (lambda (v) (concat v "="))
1698 (mapcar (lambda (v) (concat v "=")) 1698 (sh--vars-before-point))
1699 (sh--vars-before-point)) 1699 (locate-file-completion-table
1700 (locate-file-completion-table 1700 exec-path exec-suffixes string nil t)
1701 exec-path exec-suffixes string pred t) 1701 sh--completion-keywords))
1702 sh--completion-keywords)))
1703 (complete-with-action action cmds string pred)))
1704 1702
1705(defun sh-completion-at-point-function () 1703(defun sh-completion-at-point-function ()
1706 (save-excursion 1704 (save-excursion
@@ -1713,14 +1711,14 @@ This adds rules for comments and assignments."
1713 (list start end (sh--vars-before-point) 1711 (list start end (sh--vars-before-point)
1714 :company-kind (lambda (_) 'variable))) 1712 :company-kind (lambda (_) 'variable)))
1715 ((sh-smie--keyword-p) 1713 ((sh-smie--keyword-p)
1716 (list start end #'sh--cmd-completion-table 1714 (list start end
1715 (completion-table-with-cache #'sh--cmd-completion-table-gen)
1717 :company-kind 1716 :company-kind
1718 (lambda (s) 1717 (lambda (s)
1719 (cond 1718 (cond
1720 ((member s sh--completion-keywords) 'keyword) 1719 ((member s sh--completion-keywords) 'keyword)
1721 ((string-suffix-p "=" s) 'variable) 1720 ((string-suffix-p "=" s) 'variable)
1722 (t 'function))) 1721 (t 'function)))))))))
1723 ))))))
1724 1722
1725;;; Indentation and navigation with SMIE. 1723;;; Indentation and navigation with SMIE.
1726 1724