1 ;;; sml-defs.el --- Various definitions for sml-mode
3 ;; Copyright (C) 1999-2000 Stefan Monnier <monnier@cs.yale.edu>
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.
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.
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.
24 (eval-when-compile (require 'cl))
32 (defvar sml-outline-regexp "[ \t]*\\((\\*+\\|\\(let[ \t]+\\)?fun.\\)"
33 "Regexp matching a major heading.")
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)
56 "Generic bindings used in `sml-mode' and `inferior-sml-mode'."
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'."
69 (defsyntax sml-mode-syntax-table
70 `((?\* . ,(if sml-builtin-nested-comments-flag ". 23n" ". 23"))
75 ;; `!' is not really a prefix-char, oh well!
77 ("%&$+-/:<=>?@`^|" . "."))
78 "The syntax table used in sml-mode.")
82 (easy-menu-define sml-mode-menu sml-mode-map "Menu used in sml-mode."
85 ["Start default ML compiler" sml (fboundp 'sml)]
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)]
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)]
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]
108 ["set indent-level" sml-indent-level t]
109 ["set pipe-indent" sml-pipe-indent t]
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])
116 ["SML mode help (brief)" describe-mode t]
117 ["SML mode *info*" sml-mode-info t]
118 ["SML mode version" sml-mode-version t]
120 ["Remove overlay" (sml-error-overlay 'undo) ;:active (sml-overlay-active-p)
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)
135 (defun sml-syms-re (&rest syms)
136 (concat "\\<" (regexp-opt (flatten syms) t) "\\>"))
140 (defconst sml-module-head-syms
141 '("signature" "structure" "functor" "abstraction"))
144 (defconst sml-begin-syms
145 '("let" "abstype" "local" "struct" "sig")
146 "Symbols matching the `end' symbol.")
148 (defconst sml-begin-syms-re
149 (sml-syms-re "let" "abstype" "local" "struct" "sig")
150 "Symbols matching the `end' symbol.")
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.")
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"
162 "Symbols starting an sexp.")
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.")
168 ;; (defconst sml-not-arg-re
169 ;; (sml-syms-re "in" "of" "end" "andalso")
170 ;; "Symbols that should not be confused with an arg.")
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 `='.")
180 (defconst sml-indent-rule
183 (,sml-module-head-syms "d=" 0)
186 ;;("else" . (sml-indent-level 0))
187 ;;(("in" "fun" "and" "of") . (sml-indent-level nil))
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")))))
194 (defconst sml-starters-indent-after
195 (sml-syms-re "let" "local" "struct" "in" "sig" "with")
196 "Indent after these.")
198 (defconst sml-delegate
200 `((("of" "else" "then" "d=") . (not (sml-bolp)))
202 "Words which might delegate indentation to their parent.")
204 (defconst sml-symbol-indent
210 "Special indentation alist for some symbols.")
212 (defconst sml-open-paren
214 `((,(list* "with" "in" sml-begin-syms) ,sml-begin-syms-re "\\<end\\>")))
215 "Symbols that should behave somewhat like opening parens.")
217 (defconst sml-close-paren
218 `(("in" "\\<l\\(ocal\\|et\\)\\>")
219 ("with" "\\<abstype\\>")
220 ("withtype" "\\<\\(abs\\|data\\)type\\>")
221 ("end" ,sml-begin-syms-re)
223 ("else" "\\<if\\>" (sml-bolp))
226 "Symbols that should behave somewhat like close parens.")
228 (defconst sml-agglomerate-re "\\<else[ \t]+if\\>"
229 "Regexp of compound symbols (pairs of symbols to be considered as one).")
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.")
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"
241 "The starters of new expressions.")
243 (defconst sml-exptrail-syms
244 '("if" "then" "else" "while" "withtype" "do" "case" "of" "raise" "fn"))
246 (defconst sml-pipeheads
247 '("|" "of" "fun" "fn" "and" "handle" "datatype" "abstype")
248 "A `|' corresponds to one of these.")
253 ;;; sml-defs.el ends here