]> git.eshelyaron.com Git - emacs.git/commitdiff
Provide information to show icons with Elisp completions
authorDmitry Gutov <dgutov@yandex.ru>
Tue, 30 Mar 2021 00:42:11 +0000 (03:42 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Tue, 30 Mar 2021 00:42:11 +0000 (03:42 +0300)
* lisp/progmodes/elisp-mode.el (elisp--company-kind): New function.
(elisp-completion-at-point): Use it.  And a couple of anonymous
:company-kind functions too.

lisp/progmodes/elisp-mode.el

index cdf60859d06ceaf9b35e9bd822bbdd60eebbfee4..8ade718640c3a285592ec3fed3da1537a7db29b1 100644 (file)
@@ -530,6 +530,7 @@ functions are annotated with \"<f>\" via the
                     ((elisp--expect-function-p beg)
                      (list nil obarray
                            :predicate #'fboundp
+                           :company-kind #'elisp--company-kind
                            :company-doc-buffer #'elisp--company-doc-buffer
                            :company-docsig #'elisp--company-doc-string
                            :company-location #'elisp--company-location))
@@ -543,6 +544,7 @@ functions are annotated with \"<f>\" via the
                                             (symbol-plist sym)))
                            :annotation-function
                            (lambda (str) (if (fboundp (intern-soft str)) " <f>"))
+                           :company-kind #'elisp--company-kind
                            :company-doc-buffer #'elisp--company-doc-buffer
                            :company-docsig #'elisp--company-doc-string
                            :company-location #'elisp--company-location))
@@ -553,6 +555,11 @@ functions are annotated with \"<f>\" via the
                                                  obarray
                                                  #'boundp
                                                  'strict))
+                           :company-kind
+                           (lambda (s)
+                             (if (test-completion s elisp--local-variables-completion-table)
+                                 'value
+                               'variable))
                            :company-doc-buffer #'elisp--company-doc-buffer
                            :company-docsig #'elisp--company-doc-string
                            :company-location #'elisp--company-location)))
@@ -599,11 +606,13 @@ functions are annotated with \"<f>\" via the
                                       (looking-at "\\_<let\\*?\\_>"))))
                         (list t obarray
                               :predicate #'boundp
+                              :company-kind (lambda (_) 'variable)
                               :company-doc-buffer #'elisp--company-doc-buffer
                               :company-docsig #'elisp--company-doc-string
                               :company-location #'elisp--company-location))
                        (_ (list nil obarray
                                 :predicate #'fboundp
+                                :company-kind #'elisp--company-kind
                                 :company-doc-buffer #'elisp--company-doc-buffer
                                 :company-docsig #'elisp--company-doc-string
                                 :company-location #'elisp--company-location
@@ -619,6 +628,16 @@ functions are annotated with \"<f>\" via the
                                        " " (cadr table-etc)))
                     (cddr table-etc)))))))))
 
+(defun elisp--company-kind (str)
+  (let ((sym (intern-soft str)))
+    (cond
+     ((or (macrop sym) (special-form-p sym)) 'keyword)
+     ((fboundp sym) 'function)
+     ((boundp sym) 'variable)
+     ((featurep sym) 'module)
+     ((facep sym) 'color)
+     (t 'text))))
+
 (defun lisp-completion-at-point (&optional _predicate)
   (declare (obsolete elisp-completion-at-point "25.1"))
   (elisp-completion-at-point))