]> code.delx.au - gnu-emacs-elpa/blob - sml-defs.el
4b060dfacbd2c700ddf16e33a0865c6cb904d0b3
[gnu-emacs-elpa] / sml-defs.el
1 ;;; sml-defs.el --- Various definitions for sml-mode
2
3 ;; Copyright (C) 1999-2000 Stefan Monnier <monnier@cs.yale.edu>
4 ;;
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation; either version 2 of the License, or
8 ;; (at your option) any later version.
9 ;;
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
14 ;;
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program; if not, write to the Free Software
17 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 ;;; Commentary:
20
21
22 ;;; Code:
23
24 (eval-when-compile (require 'cl))
25 (require 'sml-util)
26
27
28 (defgroup sml ()
29 "Editing SML code."
30 :group 'languages)
31
32 (defvar sml-outline-regexp "[ \t]*\\((\\*+\\|\\(let[ \t]+\\)?fun.\\)"
33 "Regexp matching a major heading.")
34
35 ;;;
36 ;;; Internal defines
37 ;;;
38
39 (defmap sml-bindings
40 ;; smarter cursor movement
41 '((forward-sexp . sml-user-forward-sexp)
42 (backward-sexp . sml-user-backward-sexp)
43 ;; Text-formatting commands:
44 ("\C-c\C-m" . sml-insert-form)
45 ("\C-c\C-i" . sml-mode-info)
46 ("\M-|" . sml-electric-pipe)
47 ("\M-\ " . sml-electric-pipe)
48 ("\;" . sml-electric-semi)
49 ("\M-\t" . sml-back-to-outer-indent)
50 ;;("\C-\M-\\" . sml-indent-region)
51 ;;("\t" . sml-indent-line) ; ...except this one
52 ;; Process commands added to sml-mode-map -- these should autoload
53 ("\C-c\C-l" . sml-load-file)
54 ;;("\C-c`" . sml-next-error)
55 )
56 "Generic bindings used in `sml-mode' and `inferior-sml-mode'."
57 :group 'sml)
58
59 (defmap sml-mode-map
60 '(("\C-c\C-c" . sml-compile)
61 ("\C-c\C-s" . switch-to-sml)
62 ("\C-c\C-r" . sml-send-region)
63 ("\C-c\C-b" . sml-send-buffer)
64 ([(meta shift down-mouse-1)] . sml-drag-region))
65 "The keymap used in `sml-mode'."
66 :inherit sml-bindings
67 :group 'sml)
68
69 (defsyntax sml-mode-syntax-table
70 `((?\* . ,(if sml-builtin-nested-comments-flag ". 23n" ". 23"))
71 (?\( . "()1")
72 (?\) . ")(4")
73 ("._'" . "_")
74 (",;" . ".")
75 ;; `!' is not really a prefix-char, oh well!
76 ("~#!" . "'")
77 ("%&$+-/:<=>?@`^|" . "."))
78 "The syntax table used in sml-mode.")
79
80
81
82 (easy-menu-define sml-mode-menu sml-mode-map "Menu used in sml-mode."
83 '("SML"
84 ("Process"
85 ["Start default ML compiler" sml (fboundp 'sml)]
86 ["-" nil nil]
87 ["run CM.make" sml-make (featurep 'sml-proc)]
88 ["load ML source file" sml-load-file (featurep 'sml-proc)]
89 ["switch to ML buffer" switch-to-sml (featurep 'sml-proc)]
90 ["--" nil nil]
91 ["send buffer contents" sml-send-buffer (featurep 'sml-proc)]
92 ["send region" sml-send-region (featurep 'sml-proc)]
93 ["send paragraph" sml-send-function (featurep 'sml-proc)]
94 ;;["goto next error" sml-next-error (featurep 'sml-proc)]
95 ["goto next error" next-error (featurep 'sml-proc)]
96 ["---" nil nil]
97 ["Standard ML of New Jersey" sml-smlnj (fboundp 'sml-smlnj)]
98 ["Poly/ML" sml-poly-ml (fboundp 'sml-poly-ml)]
99 ["Moscow ML" sml-mosml (fboundp 'sml-mosml)]
100 ["Help for Inferior ML" (describe-function 'inferior-sml-mode) :active (featurep 'sml-proc)])
101 ["electric pipe" sml-electric-pipe t]
102 ["insert SML form" sml-insert-form t]
103 ("Forms" :filter sml-forms-menu)
104 ("Format/Mode Variables"
105 ["indent region" sml-indent-region t]
106 ["outdent" sml-back-to-outer-indent t]
107 ["-" nil nil]
108 ["set indent-level" sml-indent-level t]
109 ["set pipe-indent" sml-pipe-indent t]
110 ["--" nil nil]
111 ["toggle type-of-indent" (sml-type-of-indent) t]
112 ["toggle nested-if-indent" (sml-nested-if-indent) t]
113 ["toggle case-indent" (sml-case-indent) t]
114 ["toggle electric-semi-mode" (sml-electric-semi-mode) t])
115 ["-----" nil nil]
116 ["SML mode help (brief)" describe-mode t]
117 ["SML mode *info*" sml-mode-info t]
118 ["SML mode version" sml-mode-version t]
119 ["-----" nil nil]
120 ["Remove overlay" (sml-error-overlay 'undo) ;:active (sml-overlay-active-p)
121 ]))
122
123 ;;; Make's sure they appear in the menu bar when sml-mode-map is active.
124 ;; On the hook for XEmacs only -- see easy-menu-add in auc-menu.el.
125 ;; (defun sml-mode-menu-bar ()
126 ;; "Make sure menus appear in the menu bar as well as under mouse 3."
127 ;; (and (eq major-mode 'sml-mode)
128 ;; (easy-menu-add sml-mode-menu sml-mode-map)))
129 ;; (add-hook 'sml-mode-hook 'sml-mode-menu-bar)
130
131 ;;
132 ;; regexps
133 ;;
134
135 (defun sml-syms-re (&rest syms)
136 (concat "\\<" (regexp-opt (flatten syms) t) "\\>"))
137
138 ;;
139
140 (defconst sml-module-head-syms
141 '("signature" "structure" "functor" "abstraction"))
142
143
144 (defconst sml-begin-syms
145 '("let" "abstype" "local" "struct" "sig")
146 "Symbols matching the `end' symbol.")
147
148 (defconst sml-begin-syms-re
149 (sml-syms-re "let" "abstype" "local" "struct" "sig")
150 "Symbols matching the `end' symbol.")
151
152 ;; (defconst sml-user-begin-symbols-re
153 ;; (sml-syms-re "let" "abstype" "local" "struct" "sig" "in" "with")
154 ;; "Symbols matching (loosely) the `end' symbol.")
155
156 (defconst sml-sexp-head-symbols-re
157 (sml-syms-re "let" "abstype" "local" "struct" "sig" "in" "with"
158 "if" "then" "else" "case" "of" "fn" "fun" "val" "and"
159 "datatype" "type" "exception" "open" "infix" "infixr" "nonfix"
160 sml-module-head-syms
161 "handle" "raise")
162 "Symbols starting an sexp.")
163
164 ;; (defconst sml-not-arg-start-re
165 ;; (sml-syms-re "in" "of" "end" "andalso")
166 ;; "Symbols that can't be found at the head of an arg.")
167
168 ;; (defconst sml-not-arg-re
169 ;; (sml-syms-re "in" "of" "end" "andalso")
170 ;; "Symbols that should not be confused with an arg.")
171
172 (defconst sml-=-starter-syms
173 (list* "|" "val" "fun" "and" "datatype" "type" "abstype" "eqtype"
174 sml-module-head-syms)
175 "Symbols that can be followed by a `='.")
176 (defconst sml-=-starter-re
177 (concat "\\S.|\\S.\\|" (sml-syms-re (cdr sml-=-starter-syms)))
178 "Symbols that can be followed by a `='.")
179
180 (defconst sml-indent-rule
181 (sml-preproc-alist
182 `(("struct" . 0)
183 (,sml-module-head-syms "d=" 0)
184 ("local" "in" 0)
185 ;;("of" . (3 nil))
186 ;;("else" . (sml-indent-level 0))
187 ;;(("in" "fun" "and" "of") . (sml-indent-level nil))
188 ("if" "else" 0)
189 (,sml-=-starter-syms nil)
190 (("abstype" "case" "datatype" "if" "then" "else" "sharing" "infix" "infixr"
191 "let" "local" "nonfix" "open" "raise" "sig" "struct" "type" "val" "while"
192 "do" "with" "withtype")))))
193
194 (defconst sml-starters-indent-after
195 (sml-syms-re "let" "local" "struct" "in" "sig" "with")
196 "Indent after these.")
197
198 (defconst sml-delegate
199 (sml-preproc-alist
200 `((("of" "else" "then" "d=") . (not (sml-bolp)))
201 ("in" . t)))
202 "Words which might delegate indentation to their parent.")
203
204 (defconst sml-symbol-indent
205 '(("fn" . -3)
206 ("of" . 1)
207 ("|" . -2)
208 ;;("in" . 1)
209 ("d=" . 2))
210 "Special indentation alist for some symbols.")
211
212 (defconst sml-open-paren
213 (sml-preproc-alist
214 `((,(list* "with" "in" sml-begin-syms) ,sml-begin-syms-re "\\<end\\>")))
215 "Symbols that should behave somewhat like opening parens.")
216
217 (defconst sml-close-paren
218 `(("in" "\\<l\\(ocal\\|et\\)\\>")
219 ("with" "\\<abstype\\>")
220 ("withtype" "\\<\\(abs\\|data\\)type\\>")
221 ("end" ,sml-begin-syms-re)
222 ("then" "\\<if\\>")
223 ("else" "\\<if\\>" (sml-bolp))
224 ("of" "\\<case\\>")
225 ("d=" nil))
226 "Symbols that should behave somewhat like close parens.")
227
228 (defconst sml-agglomerate-re "\\<else[ \t]+if\\>"
229 "Regexp of compound symbols (pairs of symbols to be considered as one).")
230
231 (defconst sml-non-nested-of-starter-re
232 (sml-syms-re "datatype" "abstype" "exception")
233 "Symbols that can introduce an `of' that shouldn't behave like a paren.")
234
235 (defconst sml-starters-syms
236 (append sml-module-head-syms
237 '("abstype" "datatype" "exception" "fun"
238 "local" "infix" "infixr" "sharing" "nonfix"
239 "open" "type" "val" "and"
240 "withtype" "with"))
241 "The starters of new expressions.")
242
243 (defconst sml-exptrail-syms
244 '("if" "then" "else" "while" "withtype" "do" "case" "of" "raise" "fn"))
245
246 (defconst sml-pipeheads
247 '("|" "of" "fun" "fn" "and" "handle" "datatype" "abstype")
248 "A `|' corresponds to one of these.")
249
250
251 (provide 'sml-defs)
252
253 ;;; sml-defs.el ends here