emacs-diffs
[Top][All Lists]
Advanced

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

master efea3a0: Add :company-kind support to sh-mode completion


From: Dmitry Gutov
Subject: master efea3a0: Add :company-kind support to sh-mode completion
Date: Fri, 14 May 2021 20:44:26 -0400 (EDT)

branch: master
commit efea3a02f5f90566ba6e0c61371a68e21e2d1d77
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    Add :company-kind support to sh-mode completion
    
    * lisp/progmodes/sh-script.el (sh--completion-keywords):
    New variable.
    (sh--cmd-completion-table): Extracted from here.
    (sh-completion-at-point-function): Add :company-kind.
---
 lisp/progmodes/sh-script.el | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index c6bd32a..c3a12c5 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1596,6 +1596,8 @@ This adds rules for comments and assignments."
 
 ;;; Completion
 
+(defvar sh--completion-keywords '("if" "while" "until" "for"))
+
 (defun sh--vars-before-point ()
   (save-excursion
     (let ((vars ()))
@@ -1617,7 +1619,7 @@ This adds rules for comments and assignments."
                          (sh--vars-before-point))
                  (locate-file-completion-table
                   exec-path exec-suffixes string pred t)
-                 '("if" "while" "until" "for"))))
+                 sh--completion-keywords)))
     (complete-with-action action cmds string pred)))
 
 (defun sh-completion-at-point-function ()
@@ -1628,9 +1630,17 @@ This adds rules for comments and assignments."
           (start (point)))
       (cond
        ((eq (char-before) ?$)
-        (list start end (sh--vars-before-point)))
+        (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 #'sh--cmd-completion-table
+              :company-kind
+              (lambda (s)
+                (cond
+                 ((member s sh--completion-keywords) 'keyword)
+                 ((string-suffix-p "=" s) 'variable)
+                 (t 'function)))
+              ))))))
 
 ;;; Indentation and navigation with SMIE.
 



reply via email to

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