-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathable-script-mode.el
More file actions
92 lines (84 loc) · 2.44 KB
/
able-script-mode.el
File metadata and controls
92 lines (84 loc) · 2.44 KB
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
;;; able-script-mode -- Able script mode
;;; Commentary:
;; Major mode for able-script code, by Alex Bethel. See
;; https://github.com/AbleCorp/able-script.
;;; Code:
(defgroup able-script-mode nil
"Support for AbleScript code."
:link '(url-link "https://github.com/AbleCorp/able-script")
:group 'languages)
(defcustom able-script-indent-offset 6
"Indent AbleScript code by this number of spaces per level."
:type 'integer
:group 'able-script-mode)
;; Adapted from
;; gemini://gemini.omarpolo.com/post/writing-a-major-mode.gmi
;;
;; TODO: this behaves strangely sometimes when point is at the
;; beginning of the line; re-write this to work like other major
;; modes.
(defun able-script-indent-line ()
"Indent current line."
(let (indent
boi-p ;begin of indent
move-eol-p
(point (point)))
(save-excursion
(back-to-indentation)
(setq indent (car (syntax-ppss))
boi-p (= point (point)))
;; don't indent empty lines
(when (and (eq (char-after) ?\n)
(not boi-p))
(setq indent 0))
;; check whether we want to move
(when boi-p
(setq move-eol-p t))
;; decrement the indent if the first character on the line is a
;; closer.
(when (or (eq (char-after) ?\))
(eq (char-after) ?\})
(eq (char-after) ?\]))
(setq indent (1- indent)))
;; indent the line.
(delete-region (line-beginning-position)
(point))
(indent-to (* able-script-indent-offset indent)))
(when move-eol-p
(back-to-indentation))))
;; Using generic-mode for now because I'm lazy.
(define-generic-mode
able-script-mode
'("owo")
'("aint"
"functio"
"bff"
"var"
"print"
"read"
"melo"
"T-Dark"
"if"
"loop"
"break"
"rlyeh"
"rickroll"
"true"
"false"
"always"
"sometimes"
"never")
'(
;; Draw base-52 numbers in the `warning' face, because if you're
;; anything like me you usually don't mean to use them.
("\\b[[:alpha:]]\\b" 0 font-lock-warning-face)
("\\bvar \\([[:alnum:]_]*\\)" 1 font-lock-variable-name-face)
("\\bfunctio \\([[:alnum:]_]*\\)" 1 font-lock-function-name-face))
'(".*\\.able")
(list
(function
(lambda ()
(setq-local indent-line-function #'able-script-indent-line))))
"Able-script mode")
(provide 'able-script-mode)
;;; able-script-mode.el ends here