Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/sml-mode/sml-defs.el
ViewVC logotype

Annotation of /sml/trunk/sml-mode/sml-defs.el

Parent Directory Parent Directory | Revision Log Revision Log


Revision 542 - (view) (download)

1 : monnier 541 ;;; sml-defs.el --- Various definitions for sml-mode
2 : monnier 319
3 : monnier 541 ;; Copyright (C) 1999-2000 Stefan Monnier <monnier@cs.yale.edu>
4 : monnier 319 ;;
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 : monnier 541 ;;; Commentary:
20 :    
21 :    
22 :     ;;; Code:
23 :    
24 :     (eval-when-compile (require 'cl))
25 : monnier 319 (require 'sml-util)
26 :    
27 :    
28 : monnier 394 (defgroup sml ()
29 :     "Editing SML code."
30 :     :group 'languages)
31 :    
32 : monnier 319 (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 : monnier 341 ("\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 : monnier 347 ;;("\C-\M-\\" . sml-indent-region)
51 :     ;;("\t" . sml-indent-line) ; ...except this one
52 : monnier 319 ;; Process commands added to sml-mode-map -- these should autoload
53 : monnier 341 ("\C-c\C-l" . sml-load-file)
54 : monnier 535 ;;("\C-c`" . sml-next-error)
55 :     )
56 :     "Generic bindings used in `sml-mode' and `inferior-sml-mode'."
57 : monnier 394 :group 'sml)
58 : monnier 319
59 :     (defmap sml-mode-map
60 : monnier 333 '(("\C-c\C-c" . sml-compile)
61 : monnier 319 ("\C-c\C-s" . switch-to-sml)
62 :     ("\C-c\C-r" . sml-send-region)
63 : monnier 535 ("\C-c\C-b" . sml-send-buffer)
64 :     ([(meta shift down-mouse-1)] . sml-drag-region))
65 :     "The keymap used in `sml-mode'."
66 : monnier 394 :inherit sml-bindings
67 :     :group 'sml)
68 : monnier 319
69 : monnier 541 (defsyntax sml-mode-syntax-table
70 : monnier 535 `((?\* . ,(if sml-builtin-nested-comments-flag ". 23n" ". 23"))
71 : monnier 319 (?\( . "()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 : monnier 334
81 :    
82 :     (easy-menu-define sml-mode-menu sml-mode-map "Menu used in sml-mode."
83 : monnier 332 '("SML"
84 :     ("Process"
85 : monnier 334 ["Start default ML compiler" sml (fboundp 'sml)]
86 : monnier 541 ["-" nil nil]
87 : monnier 334 ["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 : monnier 541 ["--" nil nil]
91 : monnier 334 ["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 : monnier 535 ;;["goto next error" sml-next-error (featurep 'sml-proc)]
95 :     ["goto next error" next-error (featurep 'sml-proc)]
96 : monnier 541 ["---" nil nil]
97 : monnier 334 ["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 : monnier 332 ["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 : monnier 334 ("Forms" :filter sml-forms-menu)
104 : monnier 332 ("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 : monnier 394 ["Remove overlay" (sml-error-overlay 'undo) ;:active (sml-overlay-active-p)
121 :     ]))
122 : monnier 332
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 : monnier 319 ;;
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 : monnier 334
144 :     (defconst sml-begin-syms
145 :     '("let" "abstype" "local" "struct" "sig")
146 :     "Symbols matching the `end' symbol.")
147 :    
148 : monnier 342 (defconst sml-begin-syms-re
149 : monnier 319 (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 : monnier 334 "datatype" "type" "exception" "open" "infix" "infixr" "nonfix"
160 : monnier 319 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 : monnier 334 (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 : monnier 339 (,sml-module-head-syms "d=" 0)
184 :     ("local" "in" 0)
185 : monnier 334 ;;("of" . (3 nil))
186 :     ;;("else" . (sml-indent-level 0))
187 :     ;;(("in" "fun" "and" "of") . (sml-indent-level nil))
188 : monnier 339 ("if" "else" 0)
189 :     (,sml-=-starter-syms nil)
190 : monnier 334 (("abstype" "case" "datatype" "if" "then" "else" "sharing" "infix" "infixr"
191 :     "let" "local" "nonfix" "open" "raise" "sig" "struct" "type" "val" "while"
192 : monnier 541 "do" "with" "withtype")))))
193 : monnier 319
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 : monnier 334 (sml-preproc-alist
200 :     `((("of" "else" "then" "d=") . (not (sml-bolp)))
201 :     ("in" . t)))
202 : monnier 319 "Words which might delegate indentation to their parent.")
203 :    
204 : monnier 334 (defconst sml-symbol-indent
205 :     '(("fn" . -3)
206 :     ("of" . 1)
207 : monnier 341 ("|" . -2)
208 : monnier 334 ;;("in" . 1)
209 :     ("d=" . 2))
210 :     "Special indentation alist for some symbols.")
211 :    
212 :     (defconst sml-open-paren
213 :     (sml-preproc-alist
214 : monnier 342 `((,(list* "with" "in" sml-begin-syms) ,sml-begin-syms-re "\\<end\\>")))
215 : monnier 334 "Symbols that should behave somewhat like opening parens.")
216 :    
217 :     (defconst sml-close-paren
218 : monnier 339 `(("in" "\\<l\\(ocal\\|et\\)\\>")
219 :     ("with" "\\<abstype\\>")
220 :     ("withtype" "\\<\\(abs\\|data\\)type\\>")
221 : monnier 342 ("end" ,sml-begin-syms-re)
222 : monnier 339 ("then" "\\<if\\>")
223 :     ("else" "\\<if\\>" (sml-bolp))
224 :     ("of" "\\<case\\>")
225 :     ("d=" nil))
226 : monnier 334 "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 : monnier 319 (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 :     (defconst sml-starters-re (sml-syms-re sml-starters-syms))
243 :    
244 :     (defconst sml-exptrail-syms
245 : monnier 334 '("if" "then" "else" "while" "withtype" "do" "case" "of" "raise" "fn"))
246 : monnier 319
247 :     (defconst sml-pipehead-re
248 : monnier 334 (concat
249 :     "|\\S.\\|"
250 : monnier 542 (sml-syms-re "of" "fun" "fn" "and" "handle" "datatype" "abstype"))
251 : monnier 319 "A `|' corresponds to one of these.")
252 :    
253 :     (provide 'sml-defs)
254 : monnier 541
255 :     ;;; sml-defs.el ends here

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0