-
Notifications
You must be signed in to change notification settings - Fork 0
/
kami.el
93 lines (85 loc) · 1.82 KB
/
kami.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
;; Syntax hightlighting and indentation for Kami code.
;; Author : Murali Vijayaraghavan
;; Organization : SiFive
(setq kami-keywords
'(
"MODULE"
"MOD"
"Register"
"Rule"
"Method"
"Call"
"LET"
"LETA"
"LETE"
"LETC"
"RetE"
"Read"
"Write"
"Assert"
"NonDet"
"IF"
"If"
"then"
"else"
"Retv"
"Ret"
"with"
"MODULE_WF"
"MOD_WF"
)
)
(setq kami-types-and-vals
'(
"Bool"
"Bit"
"STRUCT"
"STRUCT_TYPE"
"STRUCT_CONST"
"Array"
"ARRAY"
"ARRAY_CONST"
"Default"
"WO"
)
)
(setq kami-keywords-regex (regexp-opt kami-keywords 'words))
(setq kami-types-and-vals-regex (regexp-opt kami-types-and-vals 'words))
(defun diff-parens-times-space (space)
"Calculates the number of open parentheses minus closed parentheses in previous line,
multiplies by space"
(save-excursion
(beginning-of-line)
(let ((end (point)))
(previous-line)
(beginning-of-line)
(let ((start (point))
(currind (current-indentation)))
(+ (* space (- (how-many "[[({]" start end)
(how-many "[])}]" start end)
))
currind)
)
)
)
)
(defun indent-region-parens-times-space (space start end)
(save-excursion
(goto-char start)
(while (< (point) end)
(indent-line-to (diff-parens-times-space space))
(forward-line 1))))
(defun indent-region-parens-times-2 (start end)
(interactive "r")
(let ((space 2))
(if (use-region-p)
(indent-region-parens-times-space space start end)
(indent-line-to (diff-parens-times-space space))
)))
(global-set-key (kbd "<C-tab>") 'indent-region-parens-times-2)
(font-lock-add-keywords nil
`(
(,kami-keywords-regex . font-lock-keyword-face)
(,kami-types-and-vals-regex . font-lock-builtin-face)
)
't)