-
Notifications
You must be signed in to change notification settings - Fork 1
/
rill-mode.el
149 lines (115 loc) · 4.02 KB
/
rill-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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
;;; rill-mode.el --- Rill major mode
;; Copyright (C) 2014 by
;; Author: ___Johniel
;; Keywords: rill
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(defconst rill-mode-version "0.0.1"
"The version of `rill-mode'.")
(defgroup rill nil
"A Rill major mode."
:group 'languages)
(defvar rill-mode-hook nil)
(defcustom rill-tab-width tab-width
"The tab width to use when indenting."
:type 'integer
:group 'rill
:safe 'integerp)
(add-to-list 'auto-mode-alist '("\\.rill\\'" . rill-mode))
;; Commands
(defun rill-compile-file ()
(interactive)
(message "ブーンwブーンw"))
(defvar rill-mode-map
(let ((map (make-sparse-keymap)))
;; key bindings
(define-key map (kbd "C-S-b") '(lambda () (interactvice) (message "文鳥美味しいです(^q^)")))
map)
"Keymap for `rill-mode'.")
;;
;; Define Language Syntax
;;
(defconst rill-def-regexp
"\\<\\(def\\|class\\|\\)\\s-+\\(\\(?:\\sw\\|\\\\\\|_\\)+\\)?")
(defconst rill-boolean-keywords-regexp
"\\<\\(true\\|\\<false\\)\\>")
(defconst rill-comment-regexp
"\\(//.*$\\|/\\*.*\\*/\\)")
(defconst rill-def-var-regexp
"\\(val\\|ref\\)\\s-*\\(\\sw+\\).*?:\\s-*\\(\\sw+\\)\\(,\\|;\\)?")
(defconst rill-keywords-regexp
"\\<\\(return\\|val\\|extern\\|for\\|while\\|if\\|else\\)\\>[^_]")
(defconst rill-mutable-type-regexp
"mutable(\\(\\sw+\\))")
(defconst rill-font-lock-keywords
`((,rill-def-regexp (1 font-lock-keyword-face)
(2 font-lock-type-face))
(,rill-boolean-keywords-regexp . font-lock-keyword-face)
(,rill-def-var-regexp (1 font-lock-keyword-face)
(2 font-lock-variable-name-face)
(3 font-lock-type-face))
(,rill-comment-regexp . font-lock-comment-face)
(,rill-keywords-regexp . font-lock-keyword-face)
(,rill-mutable-type-regexp (1 font-lock-type-face))))
;;
;; Define Major Mode
;;
(defvar rill-mode-syntax-table
(let ((st (make-syntax-table)))
st)
"Syntax table for `rill-mode'.")
(defvar rill-tab-width 4)
(defun rill-previous-indent ()
(save-excursion
(forward-line -1)
(if (bobp)
0
(while (and (looking-at "^[ \t]*$") (not (bobp)))
(forward-line -1))
(current-indentation))))
(defsubst rill-insert-spaces (count)
(insert-char (string-to-char " ") count))
(defun rill-indent-addtional-depth ()
"1行に if () {} とか {{ みたいなのは知らない"
(save-excursion
(* rill-tab-width
(if (looking-at ".*}.*$")
-1
(progn (beginning-of-line)
(forward-line -1)
(if (looking-at ".*{.*$") +1 0))))))
(defun rill-indent-line ()
"Indent current line."
(interactive)
(beginning-of-line)
(when (not (looking-at "[ \t]*$"))
(while (looking-at "[ \t]")
(delete-char 1))
(rill-insert-spaces (+ (rill-indent-addtional-depth)
(rill-previous-indent)))))
(define-derived-mode rill-mode prog-mode "Rill"
"Major mode for editing Rill."
(setq rill-tab-width 4))
(defun rill-mode ()
"Major mode for editing Rill"
(interactive)
(kill-all-local-variables)
(set (make-local-variable 'font-lock-defaults) '(rill-font-lock-keywords))
(set (make-local-variable 'indent-line-function) 'rill-indent-line)
(set-syntax-table rill-mode-syntax-table)
(use-local-map rill-mode-map)
(setq major-mode 'rill-mode)
(setq mode-name "Rill")
(run-hooks 'rill-mode-hook))
(provide 'rill-mode)
;;; rill-mode.el ends here