-
Notifications
You must be signed in to change notification settings - Fork 0
/
fulcrum-mode.el
123 lines (101 loc) · 3.82 KB
/
fulcrum-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
;;; fulcrum-mode.el --- Major mode for Fulcrum code -*- lexical-binding: t; -*-
;; Copyright © 2022 Alexey Egorov
;; Copyright © 2023 Alexey Egorov, Lämppi Lütti
;; Authors: Alexey Egorov <alexey.e.egorov@gmail.com>
;; Lämppi Lütti <lamppilutti@gmail.com>
;; Maintainer: Lämppi Lütti <lamppilutti@gmail.com>
;; Version: 0.0.1
;; Package-Requires: ((emacs "26.3"))
;; Keywords: languages
;; URL: http://github.com/koto-bank/fulcrum-mode
;; This file is not part of GNU Emacs.
;;; License:
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'lisp-mode)
(defgroup fulcrum-mode nil
"Major mode for Fulcrum code."
:prefix 'fulcrum-
:group 'languages)
(define-abbrev-table 'fulcrum-mode-abbrev-table ()
"Abbrev table for Fulcrum mode.
It has `lisp-mode-abbrev-table' as its parent."
:parents (list lisp-mode-abbrev-table))
(defvar fulcrum-mode-syntax-table
(let ((table (make-syntax-table lisp-data-mode-syntax-table)))
table))
(defvar fulcrum-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map lisp-mode-shared-map)
map)
"Keymap for Fulcrum mode.
All commands in `lisp-mode-shared-map' are inherited by this map.")
(defvar fulcrum-mode-line-process "")
(defconst fulcrum-font-lock-keywords
(eval-when-compile
(list
;; Declarations
(list (concat "("
(regexp-opt '("module"
"fn"
"fn-"
"struct"
"struct-"
"var")
'word)
"\\>"
"[[:space:]]*"
"\\([[:word:]]*\\)")
'(1 font-lock-keyword-face)
'(2 font-lock-function-name-face))
;; Special forms
(list (concat "("
(regexp-opt '("if"
"do"
"while"
"unless"
"return")
'word)
"\\>")
'(1 'font-lock-builtin-face)))))
(defun fulcrum-mode-set-variables ()
(set-syntax-table fulcrum-mode-syntax-table)
(setq local-abbrev-table fulcrum-mode-abbrev-table)
(setq mode-line-process '("" fulcrum-mode-line-process))
(setq font-lock-defaults
'((fulcrum-font-lock-keywords)
nil nil
(("+-*/.<>=!?$%_&:" . "w"))
nil
(font-lock-mark-block-function . mark-defun)))
(setq-local prettify-symbols-alist lisp-prettify-symbols-alist))
(put 'fn 'lisp-indent-function 'defun)
(put 'fn- 'lisp-indent-function 'defun)
(put 'module 'lisp-indent-function 'defun)
(put 'var 'lisp-indent-function 0)
;;;###autoload
(define-derived-mode fulcrum-mode lisp-data-mode "Fulcrum"
"Major mode for editing Fulcrum code.
Editing commands are similar to those of `lisp-mode'.
Commands:
Delete converts tabs to spaces as it moves back.
Blank lines separate paragraphs. Semicolons start comments.
\\{fulcrum-mode-map}"
:group 'fulcrum-mode
(fulcrum-mode-set-variables))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.\\(fc\\|fulcrum\\)\\'" . fulcrum-mode))
(provide 'fulcrum-mode)
;;; fulcrum-mode.el ends here.