-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompany-glicol.el
53 lines (45 loc) · 1.92 KB
/
company-glicol.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;; glicol-company.el --- Company completion for Glicol mode -*- lexical-binding: t; -*-
;;; Commentary:
;; Provides company-mode completion support for glicol-mode
;;; Code:
(require 'company)
(require 'glicol-docs)
(defun company-glicol--candidates (prefix)
"Generate completion candidates for PREFIX."
(let ((nodes (mapcar #'symbol-name (mapcar #'car glicol-node-docs))))
(all-completions prefix nodes)))
(defun company-glicol--annotation (candidate)
"Return annotation for CANDIDATE."
(when-let* ((node-sym (intern candidate))
(doc (alist-get node-sym glicol-node-docs))
(desc (alist-get 'description doc)))
(concat " - " (car (split-string desc "\n")))))
(defun company-glicol--doc-buffer (candidate)
"Display documentation buffer for CANDIDATE."
(when-let* ((node-sym (intern candidate))
(doc (alist-get node-sym glicol-node-docs)))
(company-doc-buffer
(format "%s\n\n=Parameters:=\n%s\n\n=Input:= %s\n=Output:= %s\n\n=Example:=\n%s"
(alist-get 'description doc)
(mapconcat (lambda (param)
(format " %s: %s" (car param) (cdr param)))
(alist-get 'parameters doc) "\n")
(alist-get 'input doc)
(alist-get 'output doc)
(alist-get 'example doc)))))
;;;###autoload
(defun company-glicol (command &optional arg &rest _ignored)
"Company backend for Glicol completion.
COMMAND is the command to execute.
ARG is the optional command argument."
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-glicol))
(prefix (and (eq major-mode 'glicol-mode)
(company-grab-symbol)))
(candidates (company-glicol--candidates arg))
(annotation (company-glicol--annotation arg))
(doc-buffer (company-glicol--doc-buffer arg))
(sorted t)))
(provide 'company-glicol)
;;; company-glicol.el ends here