-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavrforth.el
79 lines (65 loc) · 2.96 KB
/
avrforth.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
;(defvar my-mode-map nil "keymap for `my-mode-mode'")
;(setq my-mode-map (make-sparse-keymap))
;(define-key my-mode-map (kbd "C-c C-a") 'my-mode-cmd1)
(defface avrforth-face-compiled-word
'((t :foreground "green"))
"Face for words that get compiled, not run (including ] prefix)"
:group 'avrforth)
(defvar avrforth-mode-syntax-table nil "Syntax table for `avrforth-mode'.")
(setq avrforth-mode-syntax-table
(let ( (st (make-syntax-table text-mode-syntax-table)))
;;(modify-syntax-entry ?\\ "<" st)
;;(modify-syntax-entry ?\n ">" st)
(modify-syntax-entry ?. "_" st)
(modify-syntax-entry ?, "_" st)
(modify-syntax-entry ?: "_" st)
(modify-syntax-entry ?\; "_" st)
(modify-syntax-entry ?! "_" st)
(modify-syntax-entry ?@ "_" st)
(modify-syntax-entry ?# "_" st)
(modify-syntax-entry ?? "_" st)
(modify-syntax-entry ?~ "_" st)
(modify-syntax-entry ?\( "_" st)
(modify-syntax-entry ?\) "_" st)
(modify-syntax-entry ?\[ "_" st)
(modify-syntax-entry ?\] "_" st)
(modify-syntax-entry ?' "_" st)
(modify-syntax-entry ?` "_" st)
st))
(setq avrforth-highlights
'( ;; comment
("\\_<\([[:space:]][^)]\\{1,63\\}\)" . font-lock-comment-face)
;; we have a 64 byte buffer, longer comments cause crashes:
("\\_<\([[:space:]][^)]+\)" . font-lock-warning-face)
;; string
("\\_<[^[:space:]]*\"[[:space:]]\\([^\"]*\\)\"" 1 font-lock-string-face )
;; ] prefix
("\\_<\][[:space:]]+\]\\_>" . font-lock-warning-face)
("\\_<\][[:space:]]+[^[:space:]]+\\_>" . 'avrforth-face-compiled-word)
;; colon definition
;;("\\_<[^[:space:]]*:[[:space:]]+[^[:space:]]+\\>_" . font-lock-function-name-face)
("\\_<[^[:space:]]*:[[:space:]]+[^[:space:]]+\\_>" . font-lock-function-name-face)
;; l
("\\_<l\\_>" . font-lock-keyword-face)
;; [
("\\_<\\[\\_>" . font-lock-keyword-face)
;; only 16-bit lowercase hexadecimal!
("\\_<$[[:space:]]+[0-9a-f]\\{1,4\\}\\_>" . font-lock-constant-face)
;; any other literals are no good:
("\\_<$[[:space:]]+[^[:space:]]+" . font-lock-warning-face)
t))
;;(require 'forth-mode)
;; get your forth-mode from gforth.el, distributed in the official
;; gforth releases.
(define-derived-mode avrforth-mode forth-mode "avrforth"
"major mode for editing avrforth language code.
gforth's syntax highlighting makes it really to read. this mode
will turn your ]-prefixed words into a different font, and it
will color [ and l pairs (not [ and ]) so they match."
(setq font-lock-defaults '(avrforth-highlights))
(remove-hook 'after-change-functions 'forth-change-function t)
(set-syntax-table avrforth-mode-syntax-table)
(setq font-lock-multiline t)
(setq-local comment-start "\\ ")
(setq-local comment-end ""))
;;(setq auto-mode-alist (cons '("\\.avrforth\\'" . avrforth-mode) auto-mode-alist))