-
Notifications
You must be signed in to change notification settings - Fork 0
/
company-ractionary.el
98 lines (89 loc) · 3.51 KB
/
company-ractionary.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
;;; company-ractionary.el --- Company Ractionary backend
;; -*- lexical-binding: t; -*-
;;; Commentary:
;;
;; This file contains a Company backend that completes words from a
;; static, Ractionary generated dictionary. In addition, it includes a
;; backend that completes words from a local Racket namespace, but
;; only if `racket-run' (of `racket-mode') has been executed. The two
;; backends can be used together.
;;
;; To use this feature, add it to `load-path':
;;
;; (add-to-list 'load-path "/path/to/this/files/directory")
;;
;; and generate the `ractionary-words-help' dictionary, and add it to
;; `load-path' also.
;;
;; Also add `autoload' calls for the backend functions defined in this
;; file, if necessary:
;;
;; (autoload 'company-ractionary "company-ractionary" nil t)
;; (autoload 'company-maybe-racket-mode "company-ractionary" nil t)
;;
;; Those autoloads may or may not be necessary, as Company should load
;; this feature automatically when the `company-ractionary' function
;; is first used.
;;
;; In your `racket-mode-hook', pick the `company-backends' you wish to
;; use. For example:
;;
;; (setq-local company-backends
;; '((company-ractionary
;; :with
;; company-maybe-racket-mode
;; company-dabbrev-code)))
;;
;; As the `company-ractionary' backend does not check for
;; `racket-mode' specifically, you should not add it to
;; `company-backends' globally, unless you first add the appropriate
;; check to the `prefix' operations. The `company-maybe-racket-mode'
;; backend does check for `racket-mode', which it requires to
;; function.
;;; Code:
(require 'ractionary-words-help)
;;;###autoload
(defun company-ractionary (command &optional arg &rest ignored)
"Ractionary backend for Company.
COMMAND, ARG, and IGNORED are as for other Company backends.
Provides hover help via the mode started by the function
`company-quickhelp-local-mode', when that minor mode is enabled."
(interactive (list 'interactive))
(case command
(interactive (company-begin-backend 'company-ractionary))
(prefix (company-grab-symbol))
(candidates
(mapcar
(lambda (w-h)
(propertize (car w-h) 'help (cadr w-h)))
(remove-if-not
(lambda (c) (string-prefix-p arg (car c)))
ractionary-dictionary-with-help)))
(sorted t)
(quickhelp-string (get-text-property 0 'help arg))))
;; This is essential when Company does not do the loading for us, but
;; rather our `company-maybe-racket-mode' uses `company-capf'
;; directly.
(autoload 'company-capf "company-capf" nil t)
;; Defined by racket-mode, but possibly meant to be internal. Used to
;; check whether `racket-complete-at-point' is available for use.
;; (Could really use a status bar indicator for that in
;; `racket-mode'.)
(autoload 'racket--in-repl-or-its-file-p "racket-repl")
;;;###autoload
(defun company-maybe-racket-mode (command &optional arg &rest ignored)
"Defines a Company backend for `racket-mode'.
COMMAND, ARG, and IGNORED are as for other Company backends.
Return candidates based on `racket-complete-at-point', but only
when `racket--in-repl-or-its-file-p' holds, in which case return
an empty candidate list. Offer only candidate words, and not any
meta information."
(interactive (list 'interactive))
(case command
(interactive (company-begin-backend 'company-maybe-racket-mode))
(prefix (and (eq major-mode 'racket-mode)
(racket--in-repl-or-its-file-p)
(company-grab-symbol)))
(candidates (apply 'company-capf command arg ignored))))
(provide 'company-ractionary)
;;; company-ractionary.el ends here