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-mode.el
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 931 - (view) (download)

1 : monnier 535 ;;; sml-mode.el --- Major mode for editing (Standard) ML
2 : monnier 32
3 : monnier 541 ;; Copyright (C) 1989 Lars Bo Nielsen
4 :     ;; Copyright (C) 1994-1997 Matthew J. Morley
5 :     ;; Copyright (C) 1999-2000 Stefan Monnier
6 : monnier 319
7 : monnier 707 ;; Author: Lars Bo Nielsen
8 :     ;; Olin Shivers
9 :     ;; Fritz Knabe (?)
10 :     ;; Steven Gilmore (?)
11 :     ;; Matthew Morley <mjm@scs.leeds.ac.uk> (aka <matthew@verisity.com>)
12 :     ;; Matthias Blume <blume@cs.princeton.edu> (aka <blume@kurims.kyoto-u.ac.jp>)
13 :     ;; (Stefan Monnier) monnier@cs.yale.edu
14 :     ;; Maintainer: (Stefan Monnier) monnier+lists/emacs/sml@flint.cs.yale.edu
15 :     ;; Keywords: SML
16 : monnier 32 ;; $Revision$
17 :     ;; $Date$
18 :    
19 :     ;; This file is not part of GNU Emacs, but it is distributed under the
20 :     ;; same conditions.
21 :    
22 :     ;; This program is free software; you can redistribute it and/or
23 :     ;; modify it under the terms of the GNU General Public License as
24 :     ;; published by the Free Software Foundation; either version 2, or (at
25 :     ;; your option) any later version.
26 :    
27 :     ;; This program is distributed in the hope that it will be useful, but
28 :     ;; WITHOUT ANY WARRANTY; without even the implied warranty of
29 :     ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 :     ;; General Public License for more details.
31 :    
32 :     ;; You should have received a copy of the GNU General Public License
33 :     ;; along with GNU Emacs; see the file COPYING. If not, write to the
34 :     ;; Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
35 :    
36 : monnier 535 ;;; Commentary:
37 :    
38 :     ;;; HISTORY
39 :    
40 : monnier 32 ;; Still under construction: History obscure, needs a biographer as
41 :     ;; well as a M-x doctor. Change Log on request.
42 :    
43 :     ;; Hacked by Olin Shivers for comint from Lars Bo Nielsen's sml.el.
44 :    
45 :     ;; Hacked by Matthew Morley to incorporate Fritz Knabe's hilite and
46 :     ;; font-lock patterns, some of Steven Gilmore's (reduced) easy-menus,
47 :     ;; and numerous bugs and bug-fixes.
48 :    
49 : monnier 535 ;;; DESCRIPTION
50 : monnier 32
51 :     ;; See accompanying info file: sml-mode.info
52 :    
53 :     ;;; FOR YOUR .EMACS FILE
54 :    
55 : monnier 535 ;; If sml-mode.el lives in some non-standard directory, you must tell
56 : monnier 32 ;; emacs where to get it. This may or may not be necessary:
57 :    
58 : monnier 707 ;; (add-to-list 'load-path "~jones/lib/emacs/")
59 : monnier 32
60 :     ;; Then to access the commands autoload sml-mode with that command:
61 :    
62 : monnier 707 ;; (load "sml-mode-startup")
63 : monnier 32
64 :     ;; sml-mode-hook is run whenever a new sml-mode buffer is created.
65 :    
66 :     ;; Finally, there are inferior-sml-{mode,load}-hooks -- see comments
67 :     ;; in sml-proc.el. For much more information consult the mode's *info*
68 :     ;; tree.
69 :    
70 : monnier 535 ;;; Code:
71 : monnier 32
72 : monnier 541 (eval-when-compile (require 'cl))
73 : monnier 319 (require 'sml-util)
74 :     (require 'sml-move)
75 :     (require 'sml-defs)
76 : monnier 768 (condition-case nil (require 'skeleton) (error nil))
77 : monnier 32
78 :     ;;; VARIABLES CONTROLLING INDENTATION
79 :    
80 : monnier 394 (defcustom sml-indent-level 4
81 :     "*Indentation of blocks in ML (see also `sml-structure-indent')."
82 :     :group 'sml
83 :     :type '(integer))
84 : monnier 32
85 : monnier 394 (defcustom sml-indent-args sml-indent-level
86 :     "*Indentation of args placed on a separate line."
87 :     :group 'sml
88 :     :type '(integer))
89 : monnier 39
90 : monnier 341 ;; (defvar sml-indent-align-args t
91 :     ;; "*Whether the arguments should be aligned.")
92 : monnier 39
93 : monnier 341 ;; (defvar sml-case-indent nil
94 :     ;; "*How to indent case-of expressions.
95 :     ;; If t: case expr If nil: case expr of
96 :     ;; of exp1 => ... exp1 => ...
97 :     ;; | exp2 => ... | exp2 => ...
98 : monnier 334
99 : monnier 341 ;; The first seems to be the standard in SML/NJ, but the second
100 :     ;; seems nicer...")
101 : monnier 32
102 : monnier 394 (defcustom sml-electric-semi-mode nil
103 :     "*If non-nil, `\;' will self insert, reindent the line, and do a newline.
104 : monnier 535 If nil, just insert a `\;'. (To insert while t, do: \\[quoted-insert] \;)."
105 : monnier 394 :group 'sml
106 : monnier 892 :type 'boolean)
107 : monnier 32
108 : monnier 892 (defcustom sml-rightalign-and t
109 :     "If non-nil, right-align `and' with its leader.
110 :     If nil: If t:
111 :     datatype a = A datatype a = A
112 :     and b = B and b = B"
113 :     :group 'sml
114 :     :type 'boolean)
115 :    
116 : monnier 32 ;;; OTHER GENERIC MODE VARIABLES
117 :    
118 :     (defvar sml-mode-info "sml-mode"
119 : monnier 535 "*Where to find Info file for `sml-mode'.
120 : monnier 32 The default assumes the info file \"sml-mode.info\" is on Emacs' info
121 : monnier 535 directory path. If it is not, either put the file on the standard path
122 :     or set the variable `sml-mode-info' to the exact location of this file
123 : monnier 32
124 : monnier 535 (setq sml-mode-info \"/usr/me/lib/info/sml-mode\")
125 : monnier 32
126 :     in your .emacs file. You can always set it interactively with the
127 :     set-variable command.")
128 :    
129 :     (defvar sml-mode-hook nil
130 : monnier 535 "*Run upon entering `sml-mode'.
131 : monnier 32 This is a good place to put your preferred key bindings.")
132 :    
133 : monnier 535 ;;; CODE FOR SML-MODE
134 : monnier 32
135 :     (defun sml-mode-info ()
136 : monnier 535 "Command to access the TeXinfo documentation for `sml-mode'.
137 :     See doc for the variable `sml-mode-info'."
138 : monnier 32 (interactive)
139 :     (require 'info)
140 :     (condition-case nil
141 : monnier 535 (info sml-mode-info)
142 : monnier 32 (error (progn
143 :     (describe-variable 'sml-mode-info)
144 :     (message "Can't find it... set this variable first!")))))
145 :    
146 :    
147 :     ;;; Autoload functions -- no-doc is another idea cribbed from AucTeX!
148 :    
149 : monnier 319 (let ((sml-no-doc
150 :     "This function is part of sml-proc, and has not yet been loaded.
151 :     Full documentation will be available after autoloading the function."))
152 : monnier 32
153 : monnier 332 (autoload 'sml-compile "sml-proc" sml-no-doc t)
154 :     (autoload 'sml-load-file "sml-proc" sml-no-doc t)
155 :     (autoload 'switch-to-sml "sml-proc" sml-no-doc t)
156 :     (autoload 'sml-send-region "sml-proc" sml-no-doc t)
157 :     (autoload 'sml-send-buffer "sml-proc" sml-no-doc t))
158 : monnier 32
159 : monnier 33 ;; font-lock setup
160 :    
161 : monnier 39 (defconst sml-keywords-regexp
162 : monnier 319 (sml-syms-re "abstraction" "abstype" "and" "andalso" "as" "before" "case"
163 :     "datatype" "else" "end" "eqtype" "exception" "do" "fn"
164 :     "fun" "functor" "handle" "if" "in" "include" "infix"
165 :     "infixr" "let" "local" "nonfix" "of" "op" "open" "orelse"
166 :     "overload" "raise" "rec" "sharing" "sig" "signature"
167 :     "struct" "structure" "then" "type" "val" "where" "while"
168 : monnier 535 "with" "withtype" "o")
169 : monnier 39 "A regexp that matches any and all keywords of SML.")
170 :    
171 : monnier 892 (defconst sml-tyvarseq-re
172 : monnier 931 "\\(\\('+\\(\\sw\\|\\s_\\)+\\|(\\([,']\\|\\sw\\|\\s_\\|\\s-\\)+)\\)\\s-+\\)?")
173 : monnier 892
174 : monnier 300 (defconst sml-font-lock-keywords
175 :     `(;;(sml-font-comments-and-strings)
176 : monnier 892 (,(concat "\\<\\(fun\\|and\\)\\s-+" sml-tyvarseq-re "\\(\\sw+\\)\\s-+[^ \t\n=]")
177 : monnier 33 (1 font-lock-keyword-face)
178 : monnier 892 (6 font-lock-function-name-face))
179 :     (,(concat "\\<\\(\\(data\\|abs\\|with\\|eq\\)?type\\)\\s-+" sml-tyvarseq-re "\\(\\sw+\\)")
180 : monnier 33 (1 font-lock-keyword-face)
181 : monnier 892 (7 font-lock-type-def-face))
182 : monnier 544 ("\\<\\(val\\)\\s-+\\(\\sw+\\>\\s-*\\)?\\(\\sw+\\)\\s-*[=:]"
183 : monnier 33 (1 font-lock-keyword-face)
184 :     ;;(6 font-lock-variable-def-face nil t)
185 : monnier 394 (3 font-lock-variable-name-face))
186 : monnier 319 ("\\<\\(structure\\|functor\\|abstraction\\)\\s-+\\(\\sw+\\)"
187 : monnier 33 (1 font-lock-keyword-face)
188 :     (2 font-lock-module-def-face))
189 : monnier 319 ("\\<\\(signature\\)\\s-+\\(\\sw+\\)"
190 : monnier 33 (1 font-lock-keyword-face)
191 :     (2 font-lock-interface-def-face))
192 :    
193 : monnier 39 (,sml-keywords-regexp . font-lock-keyword-face))
194 : monnier 33 "Regexps matching standard SML keywords.")
195 :    
196 : monnier 394 (defface font-lock-type-def-face
197 :     '((t (:bold t)))
198 :     "Font Lock mode face used to highlight type definitions."
199 :     :group 'font-lock-highlighting-faces)
200 :     (defvar font-lock-type-def-face 'font-lock-type-def-face
201 :     "Face name to use for type definitions.")
202 : monnier 33
203 : monnier 394 (defface font-lock-module-def-face
204 :     '((t (:bold t)))
205 :     "Font Lock mode face used to highlight module definitions."
206 :     :group 'font-lock-highlighting-faces)
207 :     (defvar font-lock-module-def-face 'font-lock-module-def-face
208 :     "Face name to use for module definitions.")
209 :    
210 :     (defface font-lock-interface-def-face
211 :     '((t (:bold t)))
212 :     "Font Lock mode face used to highlight interface definitions."
213 :     :group 'font-lock-highlighting-faces)
214 :     (defvar font-lock-interface-def-face 'font-lock-interface-def-face
215 :     "Face name to use for interface definitions.")
216 :    
217 : monnier 892 ;;
218 :     ;; Code to handle nested comments and unusual string escape sequences
219 :     ;;
220 : monnier 33
221 : monnier 535 (defsyntax sml-syntax-prop-table
222 :     '((?\\ . ".") (?* . "."))
223 :     "Syntax table for text-properties")
224 :    
225 :     ;; For Emacsen that have no built-in support for nested comments
226 : monnier 300 (defun sml-get-depth-st ()
227 :     (save-excursion
228 :     (let* ((disp (if (eq (char-before) ?\)) (progn (backward-char) -1) nil))
229 :     (foo (backward-char))
230 :     (disp (if (eq (char-before) ?\() (progn (backward-char) 0) disp))
231 :     (pt (point)))
232 :     (when disp
233 :     (let* ((depth
234 :     (save-match-data
235 :     (if (re-search-backward "\\*)\\|(\\*" nil t)
236 :     (+ (or (get-char-property (point) 'comment-depth) 0)
237 :     (case (char-after) (?\( 1) (?* 0))
238 :     disp)
239 :     0)))
240 :     (depth (if (> depth 0) depth)))
241 :     (put-text-property pt (1+ pt) 'comment-depth depth)
242 : monnier 319 (when depth sml-syntax-prop-table))))))
243 : monnier 300
244 :     (defconst sml-font-lock-syntactic-keywords
245 : monnier 535 `(("^\\s-*\\(\\\\\\)" (1 ',sml-syntax-prop-table))
246 :     ,@(unless sml-builtin-nested-comments-flag
247 :     '(("(?\\(\\*\\))?" (1 (sml-get-depth-st)))))))
248 : monnier 300
249 :     (defconst sml-font-lock-defaults
250 : monnier 319 '(sml-font-lock-keywords nil nil ((?_ . "w") (?' . "w")) nil
251 : monnier 707 (font-lock-syntactic-keywords . sml-font-lock-syntactic-keywords)))
252 : monnier 300
253 : monnier 707 ;;;;
254 :     ;;;; Imenu support
255 :     ;;;;
256 : monnier 33
257 : monnier 707 (defvar sml-imenu-regexp
258 :     (concat "^[ \t]*\\(let[ \t]+\\)?"
259 :     (regexp-opt (append sml-module-head-syms
260 :     '("and" "fun" "datatype" "abstype" "type")) t)
261 :     "\\>"))
262 :    
263 :     (defun sml-imenu-create-index ()
264 :     (let (alist)
265 :     (goto-char (point-max))
266 :     (while (re-search-backward sml-imenu-regexp nil t)
267 :     (save-excursion
268 :     (let ((kind (match-string 2))
269 :     (column (progn (goto-char (match-beginning 2)) (current-column)))
270 :     (location
271 : monnier 892 (progn (goto-char (match-end 0))
272 :     (sml-forward-spaces)
273 :     (when (looking-at sml-tyvarseq-re)
274 :     (goto-char (match-end 0)))
275 :     (point)))
276 : monnier 707 (name (sml-forward-sym)))
277 :     ;; Eliminate trivial renamings.
278 :     (when (or (not (member kind '("structure" "signature")))
279 :     (progn (search-forward "=")
280 :     (sml-forward-spaces)
281 :     (looking-at "sig\\|struct")))
282 :     (push (cons (concat (make-string (/ column 2) ?\ ) name) location)
283 :     alist)))))
284 :     alist))
285 :    
286 : monnier 32 ;;; MORE CODE FOR SML-MODE
287 :    
288 : monnier 535 ;;;###Autoload
289 :     (add-to-list 'auto-mode-alist '("\\.s\\(ml\\|ig\\)\\'" . sml-mode))
290 : monnier 32
291 :     ;;;###Autoload
292 : monnier 535 (define-derived-mode sml-mode fundamental-mode "SML"
293 :     "\\<sml-mode-map>Major mode for editing ML code.
294 :     This mode runs `sml-mode-hook' just before exiting.
295 : monnier 32 \\{sml-mode-map}"
296 : monnier 535 (set (make-local-variable 'font-lock-defaults) sml-font-lock-defaults)
297 : monnier 319 (set (make-local-variable 'outline-regexp) sml-outline-regexp)
298 : monnier 707 (set (make-local-variable 'imenu-create-index-function)
299 :     'sml-imenu-create-index)
300 : monnier 700 (set (make-local-variable 'add-log-current-defun-function)
301 :     'sml-current-fun-name)
302 :     ;; forward-sexp-function is an experimental variable in my hacked Emacs.
303 :     (set (make-local-variable 'forward-sexp-function) 'sml-user-forward-sexp)
304 : monnier 768 ;; For XEmacs
305 :     (easy-menu-add sml-mode-menu)
306 :     ;; Compatibility
307 :     (unless (boundp 'skeleton-positions) (set (make-local-variable '@) nil))
308 : monnier 535 (sml-mode-variables))
309 : monnier 32
310 :     (defun sml-mode-variables ()
311 :     (set-syntax-table sml-mode-syntax-table)
312 :     (setq local-abbrev-table sml-mode-abbrev-table)
313 :     ;; A paragraph is separated by blank lines or ^L only.
314 : monnier 33
315 :     (set (make-local-variable 'paragraph-start)
316 :     (concat "^[\t ]*$\\|" page-delimiter))
317 :     (set (make-local-variable 'paragraph-separate) paragraph-start)
318 :     (set (make-local-variable 'indent-line-function) 'sml-indent-line)
319 :     (set (make-local-variable 'comment-start) "(* ")
320 :     (set (make-local-variable 'comment-end) " *)")
321 : monnier 535 (set (make-local-variable 'comment-nested) t)
322 : monnier 378 ;;(set (make-local-variable 'block-comment-start) "* ")
323 :     ;;(set (make-local-variable 'block-comment-end) "")
324 : monnier 892 ;; (set (make-local-variable 'comment-column) 40)
325 : monnier 768 (set (make-local-variable 'comment-start-skip) "(\\*+\\s-*"))
326 : monnier 32
327 : monnier 892 (defun sml-funname-of-and ()
328 :     "Name of the function this `and' defines, or nil if not a function.
329 :     Point has to be right after the `and' symbol and is not preserved."
330 :     (sml-forward-spaces)
331 :     (if (looking-at sml-tyvarseq-re) (goto-char (match-end 0)))
332 :     (let ((sym (sml-forward-sym)))
333 :     (sml-forward-spaces)
334 :     (unless (or (member sym '(nil "d="))
335 :     (member (sml-forward-sym) '("d=")))
336 :     sym)))
337 :    
338 : monnier 32 (defun sml-electric-pipe ()
339 : monnier 319 "Insert a \"|\".
340 : monnier 32 Depending on the context insert the name of function, a \"=>\" etc."
341 :     (interactive)
342 : monnier 319 (sml-with-ist
343 : monnier 334 (unless (save-excursion (skip-chars-backward "\t ") (bolp)) (insert "\n"))
344 :     (insert "| ")
345 : monnier 319 (let ((text
346 :     (save-excursion
347 : monnier 334 (backward-char 2) ;back over the just inserted "| "
348 : monnier 544 (let ((sym (sml-find-matching-starter sml-pipeheads
349 :     (sml-op-prec "|" 'back))))
350 :     (sml-forward-sym)
351 : monnier 334 (sml-forward-spaces)
352 :     (cond
353 :     ((string= sym "|")
354 :     (let ((f (sml-forward-sym)))
355 :     (sml-find-forward "\\(=>\\|=\\||\\)\\S.")
356 :     (cond
357 :     ((looking-at "|") "") ;probably a datatype
358 :     ((looking-at "=>") " => ") ;`case', or `fn' or `handle'
359 :     ((looking-at "=") (concat f " = "))))) ;a function
360 :     ((string= sym "and")
361 :     ;; could be a datatype or a function
362 : monnier 892 (setq sym (sml-funname-of-and))
363 :     (if sym (concat sym " = ") ""))
364 : monnier 334 ;; trivial cases
365 :     ((string= sym "fun")
366 :     (while (and (setq sym (sml-forward-sym))
367 :     (string-match "^'" sym))
368 :     (sml-forward-spaces))
369 :     (concat sym " = "))
370 : monnier 542 ((member sym '("case" "handle" "fn" "of")) " => ")
371 : monnier 544 ;;((member sym '("abstype" "datatype")) "")
372 :     (t ""))))))
373 : monnier 32
374 : monnier 334 (insert text)
375 : monnier 535 (indent-according-to-mode)
376 : monnier 319 (beginning-of-line)
377 :     (skip-chars-forward "\t |")
378 :     (skip-syntax-forward "w")
379 :     (skip-chars-forward "\t ")
380 :     (when (= ?= (char-after)) (backward-char)))))
381 :    
382 : monnier 32 (defun sml-electric-semi ()
383 : monnier 535 "Insert a \;.
384 :     If variable `sml-electric-semi-mode' is t, indent the current line, insert
385 : monnier 32 a newline, and indent."
386 :     (interactive)
387 :     (insert "\;")
388 :     (if sml-electric-semi-mode
389 :     (reindent-then-newline-and-indent)))
390 :    
391 :     ;;; INDENTATION !!!
392 :    
393 :     (defun sml-mark-function ()
394 : monnier 535 "Synonym for `mark-paragraph' -- sorry.
395 : monnier 32 If anyone has a good algorithm for this..."
396 :     (interactive)
397 :     (mark-paragraph))
398 :    
399 :     (defun sml-indent-line ()
400 :     "Indent current line of ML code."
401 :     (interactive)
402 : monnier 544 (let ((savep (> (current-column) (current-indentation)))
403 : monnier 700 (indent (max (or (ignore-errors (sml-calculate-indentation)) 0) 0)))
404 : monnier 544 (if savep
405 :     (save-excursion (indent-line-to indent))
406 :     (indent-line-to indent))))
407 : monnier 32
408 :     (defun sml-back-to-outer-indent ()
409 :     "Unindents to the next outer level of indentation."
410 :     (interactive)
411 :     (save-excursion
412 :     (beginning-of-line)
413 :     (skip-chars-forward "\t ")
414 :     (let ((start-column (current-column))
415 :     (indent (current-column)))
416 :     (if (> start-column 0)
417 :     (progn
418 :     (save-excursion
419 :     (while (>= indent start-column)
420 :     (if (re-search-backward "^[^\n]" nil t)
421 :     (setq indent (current-indentation))
422 :     (setq indent 0))))
423 :     (backward-delete-char-untabify (- start-column indent)))))))
424 :    
425 : monnier 39 (defun sml-find-comment-indent ()
426 :     (save-excursion
427 :     (let ((depth 1))
428 :     (while (> depth 0)
429 :     (if (re-search-backward "(\\*\\|\\*)" nil t)
430 :     (cond
431 : monnier 892 ;; FIXME: That's just a stop-gap.
432 :     ((eq (get-text-property (point) 'face) 'font-lock-string-face))
433 : monnier 39 ((looking-at "*)") (incf depth))
434 : monnier 300 ((looking-at comment-start-skip) (decf depth)))
435 : monnier 39 (setq depth -1)))
436 :     (if (= depth 0)
437 : monnier 334 (1+ (current-column))
438 : monnier 39 nil))))
439 :    
440 : monnier 32 (defun sml-calculate-indentation ()
441 :     (save-excursion
442 : monnier 319 (beginning-of-line) (skip-chars-forward "\t ")
443 :     (sml-with-ist
444 : monnier 334 ;; Indentation for comments alone on a line, matches the
445 :     ;; proper indentation of the next line.
446 : monnier 378 (when (looking-at "(\\*") (sml-forward-spaces))
447 : monnier 334 (let (data
448 :     (sml-point (point))
449 :     (sym (save-excursion (sml-forward-sym))))
450 : monnier 319 (or
451 : monnier 892 ;; Allow the user to override the indentation.
452 : monnier 378 (when (looking-at (concat ".*" (regexp-quote comment-start)
453 :     "[ \t]*fixindent[ \t]*"
454 :     (regexp-quote comment-end)))
455 :     (current-indentation))
456 : monnier 347
457 : monnier 892 ;; Continued comment.
458 : monnier 334 (and (looking-at "\\*") (sml-find-comment-indent))
459 : monnier 300
460 : monnier 319 ;; Continued string ? (Added 890113 lbn)
461 :     (and (looking-at "\\\\")
462 :     (save-excursion
463 :     (if (save-excursion (previous-line 1)
464 :     (beginning-of-line)
465 :     (looking-at "[\t ]*\\\\"))
466 :     (progn (previous-line 1) (current-indentation))
467 :     (if (re-search-backward "[^\\\\]\"" nil t)
468 : monnier 332 (1+ (current-column))
469 : monnier 319 0))))
470 : monnier 300
471 : monnier 892 ;; Closing parens. Could be handled below with `sml-indent-relative'?
472 :     (and (looking-at "\\s)")
473 :     (save-excursion
474 :     (skip-syntax-forward ")")
475 :     (backward-sexp 1)
476 :     (if (sml-dangling-sym)
477 :     (sml-indent-default 'noindent)
478 :     (current-column))))
479 :    
480 : monnier 334 (and (setq data (assoc sym sml-close-paren))
481 :     (sml-indent-relative sym data))
482 : monnier 32
483 : monnier 892 (and (member sym sml-starters-syms)
484 :     (sml-indent-starter sym))
485 : monnier 300
486 : monnier 334 (and (string= sym "|") (sml-indent-pipe))
487 : monnier 300
488 : monnier 319 (sml-indent-arg)
489 :     (sml-indent-default))))))
490 : monnier 300
491 : monnier 892 (defsubst sml-bolp ()
492 :     (save-excursion (skip-chars-backward " \t|") (bolp)))
493 :    
494 :     (defun sml-indent-starter (orig-sym)
495 :     "Return the indentation to use for a symbol in `sml-starters-syms'.
496 :     Point should be just before the symbol ORIG-SYM and is not preserved."
497 :     (let ((sym (unless (save-excursion (sml-backward-arg))
498 :     (sml-backward-spaces)
499 :     (sml-backward-sym))))
500 :     (if (equal sym "d=") (setq sym nil))
501 :     (if sym (sml-get-sym-indent sym)
502 :     ;; FIXME: this can take a *long* time !!
503 :     (setq sym (sml-find-matching-starter sml-starters-syms))
504 :     ;; Don't align with `and' because it might be specially indented.
505 :     (if (and (or (equal orig-sym "and") (not (equal sym "and")))
506 :     (sml-bolp))
507 :     (+ (current-column)
508 :     (if (and sml-rightalign-and (equal orig-sym "and"))
509 :     (- (length sym) 3) 0))
510 :     (sml-indent-starter orig-sym)))))
511 :    
512 : monnier 334 (defun sml-indent-relative (sym data)
513 :     (save-excursion
514 :     (sml-forward-sym) (sml-backward-sexp nil)
515 : monnier 339 (unless (second data) (sml-backward-spaces) (sml-backward-sym))
516 : monnier 334 (+ (or (cdr (assoc sym sml-symbol-indent)) 0)
517 :     (sml-delegated-indent))))
518 :    
519 : monnier 319 (defun sml-indent-pipe ()
520 : monnier 544 (let ((sym (sml-find-matching-starter sml-pipeheads
521 :     (sml-op-prec "|" 'back))))
522 :     (when sym
523 :     (if (string= sym "|")
524 :     (if (sml-bolp) (current-column) (sml-indent-pipe))
525 :     (let ((pipe-indent (or (cdr (assoc "|" sml-symbol-indent)) -2)))
526 : monnier 892 (when (or (member sym '("datatype" "abstype"))
527 :     (and (equal sym "and")
528 :     (save-excursion
529 :     (forward-word 1)
530 :     (not (sml-funname-of-and)))))
531 : monnier 544 (re-search-forward "="))
532 :     (sml-forward-sym)
533 :     (sml-forward-spaces)
534 :     (+ pipe-indent (current-column)))))))
535 : monnier 39
536 : monnier 334 (defun sml-find-forward (re)
537 :     (sml-forward-spaces)
538 :     (while (and (not (looking-at re))
539 :     (progn
540 :     (or (ignore-errors (forward-sexp 1) t) (forward-char 1))
541 :     (sml-forward-spaces)
542 :     (not (looking-at re))))))
543 : monnier 39
544 : monnier 319 (defun sml-indent-arg ()
545 :     (and (save-excursion (ignore-errors (sml-forward-arg)))
546 :     ;;(not (looking-at sml-not-arg-re))
547 :     ;; looks like a function or an argument
548 :     (sml-move-if (sml-backward-arg))
549 :     ;; an argument
550 :     (if (save-excursion (not (sml-backward-arg)))
551 :     ;; a first argument
552 :     (+ (current-column) sml-indent-args)
553 :     ;; not a first arg
554 :     (while (and (/= (current-column) (current-indentation))
555 :     (sml-move-if (sml-backward-arg))))
556 :     (unless (save-excursion (sml-backward-arg))
557 :     ;; all earlier args are on the same line
558 :     (sml-forward-arg) (sml-forward-spaces))
559 :     (current-column))))
560 :    
561 : monnier 334 (defun sml-get-indent (data sym)
562 :     (let ((head-sym (pop data)) d)
563 :     (cond
564 :     ((not (listp data)) data)
565 :     ((setq d (member sym data)) (second d))
566 :     ((and (consp data) (not (stringp (car data)))) (car data))
567 :     (t sml-indent-level))))
568 : monnier 332
569 : monnier 319 (defun sml-dangling-sym ()
570 : monnier 892 "Non-nil if the symbol after point is dangling.
571 :     The symbol can be an SML symbol or an open-paren. \"Dangling\" means that
572 :     it is not on its own line but is the last element on that line."
573 : monnier 32 (save-excursion
574 : monnier 319 (and (not (sml-bolp))
575 :     (< (sml-point-after (end-of-line))
576 : monnier 892 (sml-point-after (or (sml-forward-sym) (skip-syntax-forward "("))
577 : monnier 319 (sml-forward-spaces))))))
578 : monnier 32
579 : monnier 334 (defun sml-delegated-indent ()
580 :     (if (sml-dangling-sym)
581 :     (sml-indent-default 'noindent)
582 :     (sml-move-if (backward-word 1)
583 : monnier 341 (looking-at sml-agglomerate-re))
584 : monnier 334 (current-column)))
585 :    
586 : monnier 319 (defun sml-get-sym-indent (sym &optional style)
587 : monnier 535 "Find the indentation for the SYM we're `looking-at'.
588 : monnier 892 If indentation is delegated, point will move to the start of the parent.
589 :     Optional argument STYLE is currently ignored."
590 : monnier 334 (assert (equal sym (save-excursion (sml-forward-sym))))
591 :     (save-excursion
592 :     (let ((delegate (assoc sym sml-close-paren))
593 :     (head-sym sym))
594 : monnier 339 (when (and delegate (not (eval (third delegate))))
595 : monnier 334 ;;(sml-find-match-backward sym delegate)
596 :     (sml-forward-sym) (sml-backward-sexp nil)
597 :     (setq head-sym
598 : monnier 339 (if (second delegate)
599 : monnier 334 (save-excursion (sml-forward-sym))
600 :     (sml-backward-spaces) (sml-backward-sym))))
601 : monnier 32
602 : monnier 334 (let ((idata (assoc head-sym sml-indent-rule)))
603 :     (when idata
604 :     ;;(if (or style (not delegate))
605 :     ;; normal indentation
606 :     (let ((indent (sml-get-indent idata sym)))
607 :     (when indent (+ (sml-delegated-indent) indent)))
608 :     ;; delgate indentation to the parent
609 :     ;;(sml-forward-sym) (sml-backward-sexp nil)
610 :     ;;(let* ((parent-sym (save-excursion (sml-forward-sym)))
611 :     ;; (parent-indent (cdr (assoc parent-sym sml-indent-starters))))
612 :     ;; check the special rules
613 :     ;;(+ (sml-delegated-indent)
614 :     ;; (or (sml-get-indent indent-data 1 'strict)
615 :     ;; (sml-get-indent parent-indent 1 'strict)
616 :     ;; (sml-get-indent indent-data 0)
617 :     ;; (sml-get-indent parent-indent 0))))))))
618 :     )))))
619 :    
620 : monnier 319 (defun sml-indent-default (&optional noindent)
621 : monnier 333 (let* ((sym-after (save-excursion (sml-forward-sym)))
622 : monnier 319 (_ (sml-backward-spaces))
623 : monnier 333 (sym-before (sml-backward-sym))
624 : monnier 892 (sym-indent (and sym-before (sml-get-sym-indent sym-before)))
625 :     (indent-after (or (cdr (assoc sym-after sml-symbol-indent)) 0)))
626 :     (when (equal sym-before "end")
627 :     ;; I don't understand what's really happening here, but when
628 :     ;; it's `end' clearly, we need to do something special.
629 :     (forward-word 1)
630 :     (setq sym-before nil sym-indent nil))
631 :     (cond
632 :     (sym-indent
633 :     ;; the previous sym is an indentation introducer: follow the rule
634 :     (if noindent
635 :     ;;(current-column)
636 :     sym-indent
637 :     (+ sym-indent indent-after)))
638 :     ;; If we're just after a hanging open paren.
639 :     ((and (eq (char-syntax (preceding-char)) ?\()
640 :     (save-excursion (backward-char) (sml-dangling-sym)))
641 :     (backward-char)
642 :     (sml-indent-default))
643 :     (t
644 : monnier 339 ;; default-default
645 :     (let* ((prec-after (sml-op-prec sym-after 'back))
646 :     (prec (or (sml-op-prec sym-before 'back) prec-after 100)))
647 :     ;; go back until you hit a symbol that has a lower prec than the
648 :     ;; "current one", or until you backed over a sym that has the same prec
649 :     ;; but is at the beginning of a line.
650 :     (while (and (not (sml-bolp))
651 : monnier 892 (while (sml-move-if (sml-backward-sexp (1- prec))))
652 : monnier 339 (not (sml-bolp)))
653 :     (while (sml-move-if (sml-backward-sexp prec))))
654 : monnier 892 (if noindent
655 :     ;; the `noindent' case does back over an introductory symbol
656 :     ;; such as `fun', ...
657 :     (progn
658 :     (sml-move-if
659 :     (sml-backward-spaces)
660 :     (member (sml-backward-sym) sml-starters-syms))
661 :     (current-column))
662 :     ;; Use `indent-after' for cases such as when , or ; should be
663 :     ;; outdented so that their following terms are aligned.
664 :     (+ (if (progn
665 :     (if (equal sym-after ";")
666 :     (sml-move-if
667 :     (sml-backward-spaces)
668 :     (member (sml-backward-sym) sml-starters-syms)))
669 :     (and sym-after (not (looking-at sym-after))))
670 :     indent-after 0)
671 :     (current-column))))))))
672 : monnier 32
673 : monnier 319
674 :     ;; maybe `|' should be set to word-syntax in our temp syntax table ?
675 :     (defun sml-current-indentation ()
676 : monnier 32 (save-excursion
677 : monnier 319 (beginning-of-line)
678 :     (skip-chars-forward " \t|")
679 :     (current-column)))
680 : monnier 32
681 : monnier 300
682 : monnier 544 (defun sml-find-matching-starter (syms &optional prec)
683 :     (let (sym)
684 :     (ignore-errors
685 :     (while
686 :     (progn (sml-backward-sexp prec)
687 :     (setq sym (save-excursion (sml-forward-sym)))
688 :     (not (or (member sym syms) (bobp)))))
689 :     (unless (bobp) sym))))
690 : monnier 319
691 : monnier 700 (defun sml-skip-siblings ()
692 :     (while (and (not (bobp)) (sml-backward-arg))
693 :     (sml-find-matching-starter sml-starters-syms))
694 :     (when (looking-at "in\\>\\|local\\>")
695 :     ;;skip over `local...in' and continue
696 :     (forward-word 1)
697 :     (sml-backward-sexp nil)
698 :     (sml-skip-siblings)))
699 :    
700 :     (defun sml-beginning-of-defun ()
701 :     (let ((sym (sml-find-matching-starter sml-starters-syms)))
702 : monnier 707 (if (member sym '("fun" "and" "functor" "signature" "structure"
703 : monnier 700 "abstraction" "datatype" "abstype"))
704 :     (save-excursion (sml-forward-sym) (sml-forward-spaces)
705 :     (sml-forward-sym))
706 :     ;; We're inside a "non function declaration": let's skip all other
707 :     ;; declarations that we find at the same level and try again.
708 :     (sml-skip-siblings)
709 :     ;; Obviously, let's not try again if we're at bobp.
710 :     (unless (bobp) (sml-beginning-of-defun)))))
711 :    
712 :     (defcustom sml-max-name-components 3
713 :     "Maximum number of components to use for the current function name."
714 :     :group 'sml
715 :     :type 'integer)
716 :    
717 :     (defun sml-current-fun-name ()
718 :     (save-excursion
719 :     (let ((count sml-max-name-components)
720 :     fullname name)
721 :     (end-of-line)
722 :     (while (and (> count 0)
723 :     (setq name (sml-beginning-of-defun)))
724 :     (decf count)
725 :     (setq fullname (if fullname (concat name "." fullname) name))
726 :     ;; Skip all other declarations that we find at the same level.
727 :     (sml-skip-siblings))
728 :     fullname)))
729 :    
730 : monnier 32
731 : monnier 535 ;;; INSERTING PROFORMAS (COMMON SML-FORMS)
732 : monnier 32
733 : monnier 334 (defvar sml-forms-alist nil
734 : monnier 535 "*Alist of code templates.
735 :     You can extend this alist to your heart's content. For each additional
736 : monnier 32 template NAME in the list, declare a keyboard macro or function (or
737 :     interactive command) called 'sml-form-NAME'.
738 :     If 'sml-form-NAME' is a function it takes no arguments and should
739 :     insert the template at point\; if this is a command it may accept any
740 :     sensible interactive call arguments\; keyboard macros can't take
741 : monnier 535 arguments at all. Apropos keyboard macros, see `name-last-kbd-macro'
742 : monnier 32 and `sml-addto-forms-alist'.
743 :     `sml-forms-alist' understands let, local, case, abstype, datatype,
744 :     signature, structure, and functor by default.")
745 :    
746 : monnier 334 (defmacro sml-def-skeleton (name interactor &rest elements)
747 : monnier 768 (when (fboundp 'define-skeleton)
748 :     (let ((fsym (intern (concat "sml-form-" name))))
749 :     `(progn
750 :     (add-to-list 'sml-forms-alist ',(cons name fsym))
751 :     (define-abbrev sml-mode-abbrev-table ,name "" ',fsym)
752 :     (define-skeleton ,fsym
753 :     ,(format "SML-mode skeleton for `%s..' expressions" name)
754 :     ,interactor
755 :     ,(concat name " ") >
756 :     ,@elements)))))
757 : monnier 334 (put 'sml-def-skeleton 'lisp-indent-function 2)
758 : monnier 32
759 : monnier 334 (sml-def-skeleton "let" nil
760 : monnier 768 @ "\nin " > _ "\nend" >)
761 : monnier 32
762 : monnier 334 (sml-def-skeleton "if" nil
763 : monnier 768 @ " then " > _ "\nelse " > _)
764 : monnier 32
765 : monnier 334 (sml-def-skeleton "local" nil
766 : monnier 768 @ "\nin" > _ "\nend" >)
767 : monnier 32
768 : monnier 334 (sml-def-skeleton "case" "Case expr: "
769 : monnier 341 str "\nof " > _ " => ")
770 : monnier 32
771 : monnier 334 (sml-def-skeleton "signature" "Signature name: "
772 :     str " =\nsig" > "\n" > _ "\nend" >)
773 : monnier 32
774 : monnier 334 (sml-def-skeleton "structure" "Structure name: "
775 :     str " =\nstruct" > "\n" > _ "\nend" >)
776 : monnier 32
777 : monnier 334 (sml-def-skeleton "functor" "Functor name: "
778 :     str " () : =\nstruct" > "\n" > _ "\nend" >)
779 :    
780 : monnier 700 (sml-def-skeleton "datatype" "Datatype name and type params: "
781 : monnier 334 str " =" \n)
782 :    
783 : monnier 700 (sml-def-skeleton "abstype" "Abstype name and type params: "
784 : monnier 334 str " =" \n _ "\nwith" > "\nend" >)
785 :    
786 :     ;;
787 :    
788 : monnier 700 (sml-def-skeleton "struct" nil
789 :     _ "\nend" >)
790 :    
791 :     (sml-def-skeleton "sig" nil
792 :     _ "\nend" >)
793 :    
794 :     (sml-def-skeleton "val" nil
795 : monnier 768 @ " = " > _)
796 : monnier 700
797 :     (sml-def-skeleton "fn" nil
798 : monnier 768 @ " =>" > _)
799 : monnier 700
800 :     (sml-def-skeleton "fun" nil
801 : monnier 768 @ " =" > _)
802 : monnier 700
803 :     ;;
804 :    
805 : monnier 334 (defun sml-forms-menu (menu)
806 : monnier 768 (mapcar (lambda (x)
807 :     (let ((name (car x))
808 :     (fsym (cdr x)))
809 :     (vector name fsym t)))
810 :     sml-forms-alist))
811 : monnier 334
812 :     (defvar sml-last-form "let")
813 :    
814 : monnier 341 (defun sml-electric-space ()
815 :     "Expand a symbol into an SML form, or just insert a space.
816 :     If the point directly precedes a symbol for which an SML form exists,
817 :     the corresponding form is inserted."
818 :     (interactive)
819 : monnier 700 (let ((abbrev-mode (not abbrev-mode))
820 :     (last-command-char ?\ )
821 :     ;; Bind `this-command' to fool skeleton's special abbrev handling.
822 :     (this-command 'self-insert-command))
823 :     (call-interactively 'self-insert-command)))
824 : monnier 341
825 : monnier 334 (defun sml-insert-form (name newline)
826 : monnier 535 "Interactive short-cut to insert the NAME common ML form.
827 :     If a prefix argument is given insert a NEWLINE and indent first, or
828 : monnier 32 just move to the proper indentation if the line is blank\; otherwise
829 :     insert at point (which forces indentation to current column).
830 :    
831 :     The default form to insert is 'whatever you inserted last time'
832 : monnier 535 \(just hit return when prompted\)\; otherwise the command reads with
833 : monnier 32 completion from `sml-forms-alist'."
834 : monnier 334 (interactive
835 :     (list (completing-read
836 :     (format "Form to insert: (default %s) " sml-last-form)
837 :     sml-forms-alist nil t nil)
838 :     current-prefix-arg))
839 :     ;; default is whatever the last insert was...
840 :     (if (string= name "") (setq name sml-last-form) (setq sml-last-form name))
841 :     (unless (or (not newline)
842 :     (save-excursion (beginning-of-line) (looking-at "\\s-*$")))
843 :     (insert "\n"))
844 : monnier 892 (unless (/= ?w (char-syntax (preceding-char))) (insert " "))
845 : monnier 334 (let ((f (cdr (assoc name sml-forms-alist))))
846 :     (cond
847 :     ((commandp f) (command-execute f))
848 :     (f (funcall f))
849 :     (t (error "Undefined form: %s" name)))))
850 : monnier 32
851 : monnier 334 ;; See also macros.el in emacs lisp dir.
852 : monnier 32
853 : monnier 334 (defun sml-addto-forms-alist (name)
854 :     "Assign a name to the last keyboard macro defined.
855 :     Argument NAME is transmogrified to sml-form-NAME which is the symbol
856 :     actually defined.
857 : monnier 32
858 : monnier 334 The symbol's function definition becomes the keyboard macro string.
859 : monnier 32
860 : monnier 334 If that works, NAME is added to `sml-forms-alist' so you'll be able to
861 : monnier 535 reinvoke the macro through \\[sml-insert-form]. You might want to save
862 : monnier 334 the macro to use in a later editing session -- see `insert-kbd-macro'
863 :     and add these macros to your .emacs file.
864 : monnier 32
865 : monnier 334 See also `edit-kbd-macro' which is bound to \\[edit-kbd-macro]."
866 :     (interactive "sName for last kbd macro (\"sml-form-\" will be added): ")
867 :     (when (string= name "") (error "No command name given"))
868 :     (let ((fsym (intern (concat "sml-form-" name))))
869 :     (name-last-kbd-macro fsym)
870 :     (message "Macro bound to %s" fsym)
871 :     (add-to-list 'sml-forms-alist (cons name fsym))))
872 : monnier 32
873 : monnier 707 ;;;;
874 :     ;;;; SML/NJ's Compilation Manager support
875 :     ;;;;
876 : monnier 32
877 : monnier 768 (defvar sml-cm-mode-syntax-table sml-mode-syntax-table)
878 :     (defvar sml-cm-font-lock-keywords
879 :     `(,(concat "\\<" (regexp-opt '("library" "group" "is" "structure"
880 :     "functor" "signature" "funsig") t)
881 :     "\\>")))
882 : monnier 535 ;;;###autoload
883 :     (add-to-list 'completion-ignored-extensions "CM/")
884 :     ;;;###autoload
885 :     (add-to-list 'auto-mode-alist '("\\.cm\\'" . sml-cm-mode))
886 :     ;;;###autoload
887 : monnier 768 (define-derived-mode sml-cm-mode fundamental-mode "SML-CM"
888 :     "Major mode for SML/NJ's Compilation Manager configuration files."
889 :     (local-set-key "\C-c\C-c" 'sml-compile)
890 :     (set (make-local-variable 'font-lock-defaults)
891 :     '(sml-cm-font-lock-keywords nil t nil nil)))
892 : monnier 32
893 : monnier 707 ;;;;
894 : monnier 768 ;;;; ML-Lex support
895 : monnier 707 ;;;;
896 : monnier 535
897 : monnier 768 (defvar sml-lex-font-lock-keywords
898 :     (append
899 :     '(("^%\\sw+" . font-lock-builtin-face)
900 :     ("^%%" . font-lock-module-def-face))
901 :     sml-font-lock-keywords))
902 :     (defconst sml-lex-font-lock-defaults
903 :     (cons 'sml-lex-font-lock-keywords (cdr sml-font-lock-defaults)))
904 :    
905 : monnier 707 ;;;###autoload
906 : monnier 768 (define-derived-mode sml-lex-mode sml-mode "SML-Lex"
907 :     "Major Mode for editing ML-Lex files."
908 :     (set (make-local-variable 'font-lock-defaults) sml-lex-font-lock-defaults))
909 : monnier 707
910 : monnier 768 ;;;;
911 :     ;;;; ML-Yacc support
912 :     ;;;;
913 :    
914 : monnier 707 (defface sml-yacc-bnf-face
915 :     '((t (:foreground "darkgreen")))
916 :     "Face used to highlight (non)terminals in `sml-yacc-mode'.")
917 :     (defvar sml-yacc-bnf-face 'sml-yacc-bnf-face)
918 :    
919 :     (defcustom sml-yacc-indent-action 16
920 :     "Indentation column of the opening paren of actions."
921 :     :group 'sml
922 :     :type 'integer)
923 :    
924 :     (defcustom sml-yacc-indent-pipe nil
925 :     "Indentation column of the pipe char in the BNF.
926 :     If nil, align it with `:' or with previous cases."
927 :     :group 'sml
928 :     :type 'integer)
929 :    
930 :     (defcustom sml-yacc-indent-term nil
931 :     "Indentation column of the (non)term part.
932 :     If nil, align it with previous cases."
933 :     :group 'sml
934 :     :type 'integer)
935 :    
936 :     (defvar sml-yacc-font-lock-keywords
937 : monnier 768 (cons '("^\\(\\sw+\\s-*:\\|\\s-*|\\)\\(\\s-*\\sw+\\)*\\s-*\\(\\(%\\sw+\\)\\s-+\\sw+\\|\\)"
938 : monnier 707 (0 (save-excursion
939 :     (save-match-data
940 :     (goto-char (match-beginning 0))
941 :     (unless (or (re-search-forward "\\<of\\>" (match-end 0) 'move)
942 :     (progn (sml-forward-spaces)
943 :     (not (looking-at "("))))
944 : monnier 768 sml-yacc-bnf-face))))
945 :     (4 font-lock-builtin-face t t))
946 :     sml-lex-font-lock-keywords))
947 : monnier 707 (defconst sml-yacc-font-lock-defaults
948 : monnier 768 (cons 'sml-yacc-font-lock-keywords (cdr sml-font-lock-defaults)))
949 : monnier 707
950 :     (defun sml-yacc-indent-line ()
951 :     "Indent current line of ML-Yacc code."
952 :     (let ((savep (> (current-column) (current-indentation)))
953 :     (indent (max (or (ignore-errors (sml-yacc-indentation)) 0) 0)))
954 :     (if savep
955 :     (save-excursion (indent-line-to indent))
956 :     (indent-line-to indent))))
957 :    
958 :     (defun sml-yacc-indentation ()
959 :     (save-excursion
960 :     (back-to-indentation)
961 :     (or (and (looking-at "%\\|\\(\\sw\\|\\s_\\)+\\s-*:") 0)
962 :     (when (save-excursion
963 :     (condition-case nil (progn (up-list -1) nil) (scan-error t)))
964 :     ;; We're outside an action.
965 :     (cond
966 :     ;; Special handling of indentation inside %term and %nonterm
967 :     ((save-excursion
968 :     (and (re-search-backward "^%\\(\\sw+\\)" nil t)
969 :     (member (match-string 1) '("term" "nonterm"))))
970 :     (if (numberp sml-yacc-indent-term) sml-yacc-indent-term
971 :     (let ((offset (if (looking-at "|") -2 0)))
972 :     (forward-line -1)
973 :     (looking-at "\\s-*\\(%\\sw*\\||\\)?\\s-*")
974 :     (goto-char (match-end 0))
975 :     (+ offset (current-column)))))
976 :     ((looking-at "(") sml-yacc-indent-action)
977 :     ((looking-at "|")
978 :     (if (numberp sml-yacc-indent-pipe) sml-yacc-indent-pipe
979 :     (backward-sexp 1)
980 :     (while (progn (sml-backward-spaces)
981 :     (/= 0 (skip-syntax-backward "w_"))))
982 :     (sml-backward-spaces)
983 :     (if (not (looking-at "\\s-$"))
984 :     (1- (current-column))
985 :     (skip-syntax-forward " ")
986 :     (- (current-column) 2))))))
987 :     ;; default to SML rules
988 :     (sml-calculate-indentation))))
989 :    
990 :     ;;;###autoload
991 :     (add-to-list 'auto-mode-alist '("\\.grm\\'" . sml-yacc-mode))
992 :     ;;;###autoload
993 :     (define-derived-mode sml-yacc-mode sml-mode "SML-Yacc"
994 : monnier 768 "Major Mode for editing ML-Yacc files."
995 : monnier 707 (set (make-local-variable 'indent-line-function) 'sml-yacc-indent-line)
996 :     (set (make-local-variable 'font-lock-defaults) sml-yacc-font-lock-defaults))
997 :    
998 : monnier 319 (provide 'sml-mode)
999 : monnier 535
1000 :     ;;; sml-mode.el ends here

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