-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcompany-wsdmode.el
82 lines (70 loc) · 2.58 KB
/
company-wsdmode.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
;;; Package --- Summary
;;
;; This package provides company completion for wsd-mode buffers.
;;
;;
;;; Commentary:
;;
;; Activated automatically by wsd-mode itself.
;;
;;; Code:
(require 'cl-lib)
(ignore-errors
;; required to allow byte-compilation
(require 'company))
(defconst wsd-keyword-completions
'("title" "participant" "as" "over" "right" "left" "of"
"autonumber" "parallel" "activate" "deactivate"
"alt" "opt" "end" "loop" "else" "destroy"
"note" "state" "ref"))
(defun wsd-get-participants ()
"Returns a list of participants found in the document."
(save-excursion
(goto-char (point-min))
(let (res)
(while (re-search-forward "^[[:blank:]]*participant[[:blank:]]+\\(.+\\)[[:blank:]]+as[[:blank:]]+\\(.+\\)$" nil t nil)
(add-to-list 'res (match-string-no-properties 1))
(add-to-list 'res (match-string-no-properties 2)))
res)))
(defun wsd-get-actors ()
"Returns a list of actors found in the document."
(save-excursion
(goto-char (point-min))
(let* ((operators '("-->-" "-->" "->+" "->*" "->-" "->"))
(rx-operators (regexp-opt operators t))
(rx-actors (wsd-rx-lstart (concat "\\([^\n-]+\\)"
rx-operators
"\\(.+\\)"
":.*$")))
res)
(while (re-search-forward rx-actors nil t nil)
(add-to-list 'res (match-string-no-properties 1))
(add-to-list 'res (match-string-no-properties 3)))
res)))
(defun wsd-get-completion-keywords ()
"Return things which are valid completions for the current buffer."
;; TODO: determine if looking at statement where participant is expected
;; in those cases, do NOT return keyword matches!
(append
wsd-keyword-completions
(wsd-get-participants)
(wsd-get-actors))
;; TODO: enumerate active/deactivate statements? or redundant?
)
(defun company-wsd-mode (command &optional arg &rest ignored)
"Company back-end function for `wsd-mode'.
See https://github.com/company-mode/company-mode/wiki/Writing-backends for
documentation on parameters."
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-wsd-mode))
(prefix (and (eq major-mode 'wsd-mode)
(company-grab-symbol)))
(candidates
(cl-remove-if-not
(lambda (c) (string-prefix-p arg c))
(wsd-get-completion-keywords)))))
(when (boundp 'company-backends)
(add-to-list 'company-backends 'company-wsd-mode))
(provide 'company-wsdmode)
;;; company-wsdmode.el ends here