Skip to content

Commit 59f53df

Browse files
committed
contrib: Add basic Emacs mode for LiveCode builder.
Currently support some basic syntax highlighting.
1 parent 180490a commit 59f53df

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

contrib/emacs/livecode-mode.el

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
;; Copyright (C) 2015 Runtime Revolution Ltd.
2+
3+
;; This file is part of LiveCode.
4+
5+
;; LiveCode is free software; you can redistribute it and/or modify it
6+
;; under the terms of the GNU General Public License v3 as published
7+
;; by the Free Software Foundation.
8+
9+
;; LiveCode is distributed in the hope that it will be useful, but
10+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
11+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
;; General Public License for more details.
13+
14+
;; You should have received a copy of the GNU General Public License
15+
;; along with LiveCode. If not see <http://www.gnu.org/licenses/>.
16+
17+
;;;###autoload
18+
(add-to-list 'auto-mode-alist '("\\.mlc\\'" . livecode-mode))
19+
20+
(defvar livecode-mode-syntax-table
21+
(let ((st (make-syntax-table)))
22+
;; Comments
23+
(modify-syntax-entry ?/ ". 14b" st)
24+
(modify-syntax-entry ?* ". 23b" st)
25+
(modify-syntax-entry ?\- "<" st)
26+
(modify-syntax-entry ?\n ">" st)
27+
;; Angle brackets
28+
(modify-syntax-entry ?< "(" st)
29+
(modify-syntax-entry ?> ")" st)
30+
st)
31+
"Syntax table for LiveCode mode")
32+
33+
(defvar livecode-keywords
34+
'("variable" "syntax" "begin" "end" "phrase" "operator"
35+
"foreign" "handler" "prefix" "postfix" "precedence" "statement"
36+
"undefined" "public" "neutral" "binds to" "optional"
37+
"any" "private" "if" "else" "then" "repeat" "metadata" "widget" "module"
38+
"version" "author" "title" "true" "false" "return" "as" "use" "type"))
39+
40+
(defvar livecode-builtins
41+
'("output" "input"
42+
"bool" "boolean"
43+
"int" "number" "real" "double" "float"
44+
"string" "data" "list" "map" "pointer" "is" "empty"))
45+
46+
(defvar livecode-font-lock-defaults
47+
(let ((symbol-regexp "\\_<\\(\\(?:\\s_\\|\\w\\)*\\)\\_>"))
48+
`((
49+
;; stuff between "
50+
("\"\\.\\*\\?" . font-lock-string-face)
51+
52+
;; Keywords and builtins
53+
( ,(regexp-opt livecode-keywords 'symbols) . font-lock-keyword-face)
54+
( ,(regexp-opt livecode-builtins 'symbols) . font-lock-builtin-face)
55+
56+
;; "as" expressions
57+
("\\_<as\\s-+\\(\\(?:\\s_\\|\\w\\)*\\)\\_>" 1 font-lock-type-face)
58+
59+
;; handler definitions including parameter names
60+
( ,(concat "^\\s-*\\(\\_<\\(public\\|foreign\\)\\_>\\s-+\\)?\\_<handler\\_>\\s-+" symbol-regexp)
61+
(3 font-lock-function-name-face nil)
62+
( ,(concat "\\(" (regexp-opt '("in" "out" "inout") 'symbols) "\\)"
63+
"\\s-+" symbol-regexp)
64+
nil nil
65+
(3 font-lock-variable-name-face)
66+
(2 font-lock-keyword-face)))
67+
68+
;; variable names
69+
( ,(concat "^\\s-*\\_<variable\\_>\\s-*" symbol-regexp)
70+
(1 font-lock-variable-name-face))
71+
72+
;; syntax definitions
73+
( ,(concat "^\\s-*\\_<syntax\\_>\\s-+" symbol-regexp)
74+
(1 font-lock-function-name-face)
75+
("\\_<is\\_>" nil nil (0 font-lock-keyword-face t)))
76+
))))
77+
78+
(define-derived-mode livecode-mode prog-mode "LiveCode builder source"
79+
"Major mode for editing LiveCode builder source files"
80+
:syntax-table livecode-mode-syntax-table
81+
82+
(setq font-lock-defaults livecode-font-lock-defaults)
83+
84+
(set (make-local-variable 'comment-start) "--")
85+
(set (make-local-variable 'comment-end) "")
86+
)
87+
88+
(provide 'livecode-mode)

0 commit comments

Comments
 (0)