-
Notifications
You must be signed in to change notification settings - Fork 0
/
company-fontawesome.el
104 lines (77 loc) · 3.32 KB
/
company-fontawesome.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
;;; company-fontawesome.el --- company-mode backend for fontawesome
;; Copyright (C) 2017 Arnaud Meuret
;; Author: Arnaud Meuret <[email protected]>
;; Homepage: https://github.com/ameuret/company-fontawesome.git
;; Created: 12 Jul 2017
;; Version: 0.1.0
;; Package-Requires: ((cl-lib "0.5") (company "0.8.0") all-the-icons)
;; Keywords: fontawesome company convenience tools
;; Prefix: company-fontawesome
;;; Commentary:
;; Please sea https://github.com/ameuret/company-fontawesome.git
;;; Code:
(require 'cl-lib)
(require 'all-the-icons)
(defconst company-fontawesome-version "0.1.0")
(defun company-fontawesome--make-candidate (candidate)
"Build a propertized string from the CANDIDATE list.
CANDIDATE must be formed as: (name . glyph).
The icon name is prefixed with fa- and the glyph is stored under the meta prop."
(let (
(text (concat "fa-" (car candidate)))
(meta (cdr candidate)))
(setq text (propertize text 'meta meta))))
(defun company-fontawesome--candidates (prefix)
"Build the list of candidates that start with PREFIX."
(let (res)
(dolist (item (all-the-icons-faicon-data))
(when (string-prefix-p prefix (concat "fa-" (car item)))
(push (company-fontawesome--make-candidate item) res))
;;(message "Done: %S" item)
;;(message (get-text-property 0 'face (car item)))
)
res))
(defun company-fontawesome--meta (candidate)
"Build the string to be displayed when the CANDIDATE is highlighted.
Displayed in the echo area when the default frontend is used."
(format "%s -> %s"
(substring-no-properties candidate)
(get-text-property 0 'meta candidate)
))
(defun company-fontawesome--annotation (candidate)
"Build the string showing the CANDIDATE glyph alongside the icon id."
(setq res (format "%s" (get-text-property 0 'meta candidate)))
;; This attempt to control the display (hoping to solve font
;; conflicts) has proved insufficient. The face properties are reset
;; later by company.el
(put-text-property 0 1 'font-lock-face 'font-lock-warning-face res)
res)
(defun company-fontawesome (command &optional arg &rest ignored)
"Start the backend and act according to COMMAND.
ARG can have various meanings depending on COMMAND but is often the
candidate."
(interactive (list 'interactive))
;; (message "Company cmd:%s" command)
(cl-case command
(interactive (company-begin-backend 'company-fontawesome))
(prefix (company-grab-symbol-cons "\\.\\|->" 2))
(candidates (company-fontawesome--candidates arg))
(annotation (company-fontawesome--annotation arg))
(meta (company-fontawesome--meta arg))
;; (post-completion
;; (progn
;; (kill-region (- (point) (length arg)) (point))
;; (insert (get-text-property 0 'meta arg))))
))
(defun company-fontawesome-init ()
"Add fontawesome to the company backends."
(interactive)
(add-to-list 'company-backends 'company-fontawesome))
(provide 'company-fontawesome)
;; (message "%s" (cdr (nth 42 (all-the-icons-faicon-data))))
;; (insert (cdr (nth 7 (all-the-icons-faicon-data))))
;; (type-of (cdr(nth 0 company-custom-keywords)))
;; (type-of (cdr(nth 42 (all-the-icons-faicon-data))))
;; (dolist (i (all-the-icons-faicon-data))
;; (message "%s: %s" (car i) (cdr i)))
;;; company-fontawesome.el ends here