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 767 - (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 706 (defvar sml-outline-regexp
33 :     ;; `st' and `si' are to match structure and signature.
34 :     " \\|s[ti]\\|[ \t]*\\(let[ \t]+\\)?\\(fun\\|and\\)\\>"
35 :     "Regexp matching a major heading.
36 :     This actually can't work without extending `outline-minor-mode' with the
37 :     notion of \"the end of an outline\".")
38 : monnier 319
39 :     ;;;
40 :     ;;; Internal defines
41 :     ;;;
42 :    
43 : monnier 700 (defmap sml-mode-map
44 : monnier 319 ;; smarter cursor movement
45 :     '((forward-sexp . sml-user-forward-sexp)
46 :     (backward-sexp . sml-user-backward-sexp)
47 :     ;; Text-formatting commands:
48 : monnier 341 ("\C-c\C-m" . sml-insert-form)
49 :     ("\C-c\C-i" . sml-mode-info)
50 :     ("\M-|" . sml-electric-pipe)
51 : monnier 700 ("\M-\ " . sml-electric-space)
52 : monnier 341 ("\;" . sml-electric-semi)
53 :     ("\M-\t" . sml-back-to-outer-indent)
54 : monnier 319 ;; Process commands added to sml-mode-map -- these should autoload
55 : monnier 341 ("\C-c\C-l" . sml-load-file)
56 : monnier 700 ("\C-c\C-c" . sml-compile)
57 : monnier 319 ("\C-c\C-s" . switch-to-sml)
58 :     ("\C-c\C-r" . sml-send-region)
59 : monnier 535 ("\C-c\C-b" . sml-send-buffer)
60 :     ([(meta shift down-mouse-1)] . sml-drag-region))
61 :     "The keymap used in `sml-mode'."
62 : monnier 700 ;; :inherit sml-bindings
63 : monnier 394 :group 'sml)
64 : monnier 319
65 : monnier 541 (defsyntax sml-mode-syntax-table
66 : monnier 535 `((?\* . ,(if sml-builtin-nested-comments-flag ". 23n" ". 23"))
67 : monnier 319 (?\( . "()1")
68 :     (?\) . ")(4")
69 :     ("._'" . "_")
70 :     (",;" . ".")
71 :     ;; `!' is not really a prefix-char, oh well!
72 :     ("~#!" . "'")
73 :     ("%&$+-/:<=>?@`^|" . "."))
74 : monnier 700 "The syntax table used in `sml-mode'.")
75 : monnier 319
76 : monnier 334
77 :     (easy-menu-define sml-mode-menu sml-mode-map "Menu used in sml-mode."
78 : monnier 332 '("SML"
79 :     ("Process"
80 : monnier 334 ["Start default ML compiler" sml (fboundp 'sml)]
81 : monnier 541 ["-" nil nil]
82 : monnier 334 ["run CM.make" sml-make (featurep 'sml-proc)]
83 :     ["load ML source file" sml-load-file (featurep 'sml-proc)]
84 :     ["switch to ML buffer" switch-to-sml (featurep 'sml-proc)]
85 : monnier 541 ["--" nil nil]
86 : monnier 334 ["send buffer contents" sml-send-buffer (featurep 'sml-proc)]
87 :     ["send region" sml-send-region (featurep 'sml-proc)]
88 :     ["send paragraph" sml-send-function (featurep 'sml-proc)]
89 : monnier 535 ;;["goto next error" sml-next-error (featurep 'sml-proc)]
90 :     ["goto next error" next-error (featurep 'sml-proc)]
91 : monnier 541 ["---" nil nil]
92 : monnier 700 ;; ["Standard ML of New Jersey" sml-smlnj (fboundp 'sml-smlnj)]
93 :     ;; ["Poly/ML" sml-poly-ml (fboundp 'sml-poly-ml)]
94 :     ;; ["Moscow ML" sml-mosml (fboundp 'sml-mosml)]
95 : monnier 332 ["Help for Inferior ML" (describe-function 'inferior-sml-mode) :active (featurep 'sml-proc)])
96 :     ["electric pipe" sml-electric-pipe t]
97 :     ["insert SML form" sml-insert-form t]
98 : monnier 334 ("Forms" :filter sml-forms-menu)
99 : monnier 332 ("Format/Mode Variables"
100 :     ["indent region" sml-indent-region t]
101 :     ["outdent" sml-back-to-outer-indent t]
102 :     ["-" nil nil]
103 :     ["set indent-level" sml-indent-level t]
104 :     ["set pipe-indent" sml-pipe-indent t]
105 :     ["--" nil nil]
106 :     ["toggle type-of-indent" (sml-type-of-indent) t]
107 :     ["toggle nested-if-indent" (sml-nested-if-indent) t]
108 :     ["toggle case-indent" (sml-case-indent) t]
109 :     ["toggle electric-semi-mode" (sml-electric-semi-mode) t])
110 :     ["-----" nil nil]
111 :     ["SML mode help (brief)" describe-mode t]
112 :     ["SML mode *info*" sml-mode-info t]
113 :     ["-----" nil nil]
114 : monnier 394 ["Remove overlay" (sml-error-overlay 'undo) ;:active (sml-overlay-active-p)
115 :     ]))
116 : monnier 332
117 :     ;;; Make's sure they appear in the menu bar when sml-mode-map is active.
118 :     ;; On the hook for XEmacs only -- see easy-menu-add in auc-menu.el.
119 :     ;; (defun sml-mode-menu-bar ()
120 :     ;; "Make sure menus appear in the menu bar as well as under mouse 3."
121 :     ;; (and (eq major-mode 'sml-mode)
122 :     ;; (easy-menu-add sml-mode-menu sml-mode-map)))
123 :     ;; (add-hook 'sml-mode-hook 'sml-mode-menu-bar)
124 :    
125 : monnier 319 ;;
126 :     ;; regexps
127 :     ;;
128 :    
129 :     (defun sml-syms-re (&rest syms)
130 :     (concat "\\<" (regexp-opt (flatten syms) t) "\\>"))
131 :    
132 :     ;;
133 :    
134 :     (defconst sml-module-head-syms
135 :     '("signature" "structure" "functor" "abstraction"))
136 :    
137 : monnier 334
138 :     (defconst sml-begin-syms
139 :     '("let" "abstype" "local" "struct" "sig")
140 :     "Symbols matching the `end' symbol.")
141 :    
142 : monnier 342 (defconst sml-begin-syms-re
143 : monnier 319 (sml-syms-re "let" "abstype" "local" "struct" "sig")
144 :     "Symbols matching the `end' symbol.")
145 :    
146 :     ;; (defconst sml-user-begin-symbols-re
147 :     ;; (sml-syms-re "let" "abstype" "local" "struct" "sig" "in" "with")
148 :     ;; "Symbols matching (loosely) the `end' symbol.")
149 :    
150 :     (defconst sml-sexp-head-symbols-re
151 :     (sml-syms-re "let" "abstype" "local" "struct" "sig" "in" "with"
152 :     "if" "then" "else" "case" "of" "fn" "fun" "val" "and"
153 : monnier 334 "datatype" "type" "exception" "open" "infix" "infixr" "nonfix"
154 : monnier 319 sml-module-head-syms
155 :     "handle" "raise")
156 :     "Symbols starting an sexp.")
157 :    
158 :     ;; (defconst sml-not-arg-start-re
159 :     ;; (sml-syms-re "in" "of" "end" "andalso")
160 :     ;; "Symbols that can't be found at the head of an arg.")
161 :    
162 :     ;; (defconst sml-not-arg-re
163 :     ;; (sml-syms-re "in" "of" "end" "andalso")
164 :     ;; "Symbols that should not be confused with an arg.")
165 :    
166 : monnier 334 (defconst sml-=-starter-syms
167 :     (list* "|" "val" "fun" "and" "datatype" "type" "abstype" "eqtype"
168 :     sml-module-head-syms)
169 :     "Symbols that can be followed by a `='.")
170 :     (defconst sml-=-starter-re
171 :     (concat "\\S.|\\S.\\|" (sml-syms-re (cdr sml-=-starter-syms)))
172 :     "Symbols that can be followed by a `='.")
173 :    
174 :     (defconst sml-indent-rule
175 :     (sml-preproc-alist
176 :     `(("struct" . 0)
177 : monnier 339 (,sml-module-head-syms "d=" 0)
178 :     ("local" "in" 0)
179 : monnier 334 ;;("of" . (3 nil))
180 :     ;;("else" . (sml-indent-level 0))
181 :     ;;(("in" "fun" "and" "of") . (sml-indent-level nil))
182 : monnier 339 ("if" "else" 0)
183 :     (,sml-=-starter-syms nil)
184 : monnier 334 (("abstype" "case" "datatype" "if" "then" "else" "sharing" "infix" "infixr"
185 :     "let" "local" "nonfix" "open" "raise" "sig" "struct" "type" "val" "while"
186 : monnier 541 "do" "with" "withtype")))))
187 : monnier 319
188 :     (defconst sml-starters-indent-after
189 :     (sml-syms-re "let" "local" "struct" "in" "sig" "with")
190 :     "Indent after these.")
191 :    
192 :     (defconst sml-delegate
193 : monnier 334 (sml-preproc-alist
194 :     `((("of" "else" "then" "d=") . (not (sml-bolp)))
195 :     ("in" . t)))
196 : monnier 319 "Words which might delegate indentation to their parent.")
197 :    
198 : monnier 334 (defconst sml-symbol-indent
199 :     '(("fn" . -3)
200 :     ("of" . 1)
201 : monnier 341 ("|" . -2)
202 : monnier 334 ;;("in" . 1)
203 :     ("d=" . 2))
204 :     "Special indentation alist for some symbols.")
205 :    
206 :     (defconst sml-open-paren
207 :     (sml-preproc-alist
208 : monnier 342 `((,(list* "with" "in" sml-begin-syms) ,sml-begin-syms-re "\\<end\\>")))
209 : monnier 334 "Symbols that should behave somewhat like opening parens.")
210 :    
211 :     (defconst sml-close-paren
212 : monnier 339 `(("in" "\\<l\\(ocal\\|et\\)\\>")
213 :     ("with" "\\<abstype\\>")
214 :     ("withtype" "\\<\\(abs\\|data\\)type\\>")
215 : monnier 342 ("end" ,sml-begin-syms-re)
216 : monnier 339 ("then" "\\<if\\>")
217 :     ("else" "\\<if\\>" (sml-bolp))
218 :     ("of" "\\<case\\>")
219 :     ("d=" nil))
220 : monnier 334 "Symbols that should behave somewhat like close parens.")
221 :    
222 :     (defconst sml-agglomerate-re "\\<else[ \t]+if\\>"
223 :     "Regexp of compound symbols (pairs of symbols to be considered as one).")
224 :    
225 :     (defconst sml-non-nested-of-starter-re
226 :     (sml-syms-re "datatype" "abstype" "exception")
227 :     "Symbols that can introduce an `of' that shouldn't behave like a paren.")
228 :    
229 : monnier 319 (defconst sml-starters-syms
230 :     (append sml-module-head-syms
231 :     '("abstype" "datatype" "exception" "fun"
232 :     "local" "infix" "infixr" "sharing" "nonfix"
233 :     "open" "type" "val" "and"
234 :     "withtype" "with"))
235 :     "The starters of new expressions.")
236 :    
237 :     (defconst sml-exptrail-syms
238 : monnier 334 '("if" "then" "else" "while" "withtype" "do" "case" "of" "raise" "fn"))
239 : monnier 319
240 : monnier 544 (defconst sml-pipeheads
241 :     '("|" "of" "fun" "fn" "and" "handle" "datatype" "abstype")
242 :     "A `|' corresponds to one of these.")
243 : monnier 319
244 : monnier 544
245 : monnier 319 (provide 'sml-defs)
246 : monnier 541
247 :     ;;; sml-defs.el ends here

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