-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhoon-ts-mode.el
117 lines (94 loc) · 3.4 KB
/
hoon-ts-mode.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
105
106
107
108
109
110
111
112
113
114
115
116
117
;;; hoon-ts-mode.el --- Hoon ts mode -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(require 'treesit)
(defvar hoon--treesit-font-lock-setting
(treesit-font-lock-rules
:feature 'comment
:language 'hoon
'((Gap) @font-lock-comment-face)
:feature 'string
:language 'hoon
'((string) @font-lock-string-face)
:feature 'aura
:language 'hoon
'((aura) @font-lock-type-face)
:feature 'shadow
:language 'hoon
'((wrapFace (name) @font-lock-variable-name-face));;TODO: labels
:feature 'rune
:language 'hoon
'((rune) @font-lock-builtin-face)
:feature 'typeCast
:language 'hoon
'((typeCast (_)) @font-lock-type-face)
:feature 'zapzap
:language 'hoon
:override t
'((zapzap (_)) @font-lock-warning-face)
:feature 'name
:language 'hoon
'((name) @font-lock-variable-name-face)
:feature 'lusNames
:language 'hoon
'((luslusTall (name) @font-lock-function-name-face)
(lusbucTall (name) @font-lock-function-name-face))
:feature 'gateCall
:language 'hoon
'((gateCall) @font-lock-constant-call-face)
:feature 'constants
:language 'hoon
'((mold) @font-lock-keyword-face
(lark) @font-lock-misc-punctuation-face
(date) @font-lock-keyword-face
(number) @font-lock-keyword-face
(boolean) @font-lock-keyword-face
(term) @font-lock-keyword-face))
"Tree-sitter font-lock settings.")
;;;###autoload
(define-derived-mode hoon-ts-mode hoon-mode "Hoon ts mode"
"Treesitter mode for hoon files"
(when (treesit-ready-p 'hoon)
(treesit-parser-create 'hoon)
;; set up treesit
(setq-local treesit-font-lock-feature-list
'((comment string aura)
(zapzap rune)
(constants lusNames shadow)
(gateCal typeCast)))
(setq-local treesit-font-lock-settings hoon--treesit-font-lock-setting)
;; - treesit-simple-indent-rules
;; - treesit-defun-type-regexp
(setq treesit-simple-imenu-settings
`(("Arms" "\\`luslusTall\\'" nil hoon--treesit-defun-name)
("Molds" "\\`lusbucTall\\'" nil hoon--treesit-defun-name))) ;; - treesit-simple-imenu-settings
(treesit-major-mode-setup)))
(defun hoon--treesit-defun-name (node)
(pcase (treesit-node-type node)
((or "luslusTall" "lusbucTall" "wrapFace")
(treesit-node-text (treesit-search-forward node "name")))))
(add-to-list 'auto-mode-alist '("\\.hoon$" . hoon-ts-mode))
(defvar hoon-ts-mode-default-grammar-sources
'((hoon . ("https://github.com/urbit-pilled/tree-sitter-hoon.git"))))
(defun hoon-ts-install-grammar ()
"Experimental function to install the tree-sitter-hoon grammar."
(interactive)
(if (and (treesit-available-p) (boundp 'treesit-language-source-alist))
(let ((treesit-language-source-alist
(append
treesit-language-source-alist
hoon-ts-mode-default-grammar-sources)))
(if (y-or-n-p
(format
(concat "The following language grammar repository which will be "
"downloaded and installed "
"%s, proceed?")
(cadr (assoc 'hoon treesit-language-source-alist))))
(treesit-install-language-grammar 'hoon)))
(display-warning
'treesit
(concat "Cannot install grammar because"
" "
"tree-sitter library is not compiled with Emacs"))))
(provide 'hoon-ts-mode)
;;; hoon-ts-mode.el ends here