]> code.delx.au - gnu-emacs-elpa/blob - sml-mode.texi
First seemingly acceptable new code.
[gnu-emacs-elpa] / sml-mode.texi
1 \input texinfo @c -*-texinfo-*-
2
3 @comment "@(#)$Name$:$Id$"
4
5 @comment Documentation for the GNU Emacs SML mode.
6 @comment Copyright (C) 1999 (Anon)
7
8 @comment This file is part of the pcl-cvs distribution.
9
10 @comment sml-mode is free software; you can redistribute it and/or modify
11 @comment it under the terms of the GNU General Public License as published by
12 @comment the Free Software Foundation; either version 2 of the License,
13 @comment or (at your option) any later version.
14
15 @comment sml-mode is distributed in the hope that it will be useful,
16 @comment but WITHOUT ANY WARRANTY; without even the implied warranty of
17 @comment MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 @comment GNU General Public License for more details.
19
20 @comment You should have received a copy of the GNU General Public License
21 @comment along with sml-mode; see the file COPYING. If not, write to
22 @comment the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 @setfilename sml-mode.info
25 @settitle SML mode - The Emacs SML editing mode
26 @dircategory Editors
27 @direntry
28 * sml:(sml-mode). Emacs mode for editing SML
29 @end direntry
30 @setchapternewpage on
31
32 @titlepage
33 @sp 5
34 @center @titlefont{Editing and running Standard ML}
35 @center @titlefont{under GNU Emacs}
36 @sp 5
37 @center {SML mode, Version 3.3}
38 @center {April 1997}
39 @sp 2
40 @author Author: Matthew J.@: Morley
41
42 @page
43 @vskip 0pt plus 1filll
44 Copyright @copyright{} (Anon)
45
46 @sp 1
47 @noindent
48 GNU General Public License as published by the Free Software Foundation;
49 either version 2, or (at your option) any later version.
50
51 @sp 1
52 @noindent
53 SML mode is distributed in the hope that it will be useful, but
54 WITHOUT ANY WARRANTY; without even the implied warranty of
55 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
56 Public License for more details.
57
58 @sp 1
59 @noindent
60 You should have received a copy of the GNU General Public License along
61 with GNU Emacs; see the file COPYING. If not, write to the Free Software
62 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
63
64 @end titlepage
65
66 @setchapternewpage off
67 @headings double
68
69 @c ============================================================ TOP NODE
70
71 @node Top, Copying, (dir), (dir)
72
73 @ifinfo
74 @chapter SML Mode Info
75
76 @c == Top, Copying, (dir), (dir) =======================================
77
78 @noindent
79 You are looking at the top node of the Info tree documenting
80 @sc{sml-mode} (Version 3.3). Not all functions are documented here, but
81 those that aren't you probably won't miss. All commands and settable
82 variables have built-in documentation, as per usual Emacs conventions.
83 @end ifinfo
84
85 @menu
86 * Copying:: You can copy SML mode
87 * Introduction:: Setting things up
88 * SML Mode:: Editing SML source
89 * Interaction Mode:: Running ML processes
90 * Configuration:: Menus, highlighting, setting defaults
91 * Credits:: Credit and blame
92
93 Indexes
94 * Command Index:: Commands you can invoke
95 * Variable Index:: Variables you can set
96 * Key Index:: Default keybindings
97
98 Introduction
99 * Distribution:: What this distribution contains
100 * Getting Started:: What to tell Emacs
101 * Getting Help:: How Emacs can help
102
103 SML Mode
104 * Basics:: On entering SML mode
105 * Indentation:: Prettying SML text
106 * Magic Insertion:: Templates and electric keys
107 * SML Mode Defaults:: Variables controlling indentation
108
109 Interaction Mode
110 * Running ML:: Commands to run the ML compiler in a buffer
111 * ML Interaction:: Sending program fragments to the compiler
112 * Tracking Errors:: Finding reported syntax errors
113 * Process Defaults:: Setting defaults for process interaction
114
115 Configuration
116 * Hooks:: Creating hooks
117 * Key Bindings:: Binding commands to keys
118 * Menus:: Taking advantage of bitmapped screens
119 * Highlighting:: Syntax colouring
120 * Advanced Topics:: You may need to speak Emacs Lisp
121 @end menu
122
123
124 @c ============================================================= COPYING
125
126 @node Copying, Introduction, Top, Top
127
128 @ifinfo
129 @chapter Copying
130
131 @c == Copying, Introduction, Top, Top ==================================
132
133 @noindent
134 You can freely copy, modify and redistribute SML mode because it's
135 made available under the liberal terms of the GNU General Public
136 License.
137
138 GNU General Public License as published by the Free Software Foundation;
139 either version 2, or (at your option) any later version.
140
141 SML mode is distributed in the hope that it will be useful, but
142 WITHOUT ANY WARRANTY; without even the implied warranty of
143 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
144 Public License for more details.
145
146 You should have received a copy of the GNU General Public License along
147 with GNU Emacs; see the file COPYING. If not, write to the Free Software
148 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
149
150 @end ifinfo
151
152
153
154
155 @c ======================================================== INTRODUCTION
156
157 @node Introduction, SML Mode, Copying, Top
158
159 @chapter Introduction
160
161 @c == Introduction, SML Mode, Copying, Top =============================
162
163
164 @noindent
165 SML mode is a major mode for Emacs for editing Standard ML. It has
166 some novel bugs, and some nice features:
167
168 @itemize @bullet
169 @item
170 Automatic indentation of sml code---a number of variables to customise
171 the indentation.
172 @item
173 Easy insertion for commonly used templates like let, local, signature,
174 and structure declarations, with minibuffer prompting for types and
175 expressions.
176 @item
177 Magic pipe insertion: @code{|} automatically determines if it is used
178 in a case or fun construct, and indents the next line as appropriate,
179 inserting @code{=>} or the name of the function.
180 @item
181 Inferior shell for running ML. There's no need to leave Emacs, just keep
182 on editing while the compiler runs in another window.
183 @item
184 Automatic ``use file'' in the inferior shell---you can send files,
185 buffers, or regions of code to the ML subprocess.
186 @item
187 Menus, and syntax and keyword highlighting supported for Emacs 19 and
188 derivatives.
189 @item
190 Parsing errors from the inferior shell, and repositioning the
191 source---much like the next-error function used in c-mode.
192 @item
193 SML mode can be easily configured to work with a number of Standard
194 ML compilers, and other SML based tools.
195 @end itemize
196
197 @menu
198 * Distribution:: What this distribution contains
199 * Getting Started:: What to tell Emacs
200 * Getting Help:: How Emacs can help
201 @end menu
202
203
204
205 @c ======================================================== DISTRIBUTION
206
207 @node Distribution, Getting Started, Introduction, Introduction
208
209 @section The SML mode distribution
210
211 @c == Distribution, Getting Started, Introduction, Introduction ========
212
213
214 @noindent
215 The distribution contains several Emacs Lisp files---this is for ease of
216 maintenance, you can concatenate them if you're careful:
217
218 @table @file
219 @item sml-mode.el
220 Main file, and should work in any Emacs editor or version post
221 18.58---it only knows, or thinks it knows, about SML syntax and
222 indentation.
223
224 @item sml-menus.el
225 Menus to access user settable features of the mode, and for those who
226 prefer menus over keys under Emacs 19 and derivatives.
227
228 @item sml-@{hilite,font@}.el
229 Syntax highlighting functions to display keywords in a bold font,
230 comments in italics, etc., using one of Emacs' two popular syntax
231 colouring packages.
232
233 @item sml-proc.el
234 Process interaction requires the @file{comint} package (normally
235 distributed with Emacs 19 and derivatives).
236
237 @item sml-@{poly-ml,mosml@}.el
238 Auxiliary library support for Poly/ML and Moscow ML compilers.
239 @c Set these up to autoload from your @file{.emacs}.
240
241 @end table
242
243 @noindent There is also the Texinfo generated @code{info} file:
244
245 @table @file
246
247 @item sml-mode.@{dvi,info@}
248 @c itemx sml-mode.dvi
249 This file---rudimentary SML mode documentation, and
250
251 @item sml-site.el
252 Configuration file for system-wide installation. Read and edit this file
253 if you are installing SML mode for general use.
254
255 @end table
256
257
258 @c ===================================================== GETTING STARTED
259
260 @node Getting Started, Getting Help, Distribution, Introduction
261
262 @section Getting started
263
264 @c == Getting Started, Getting Help, Distribution, Introduction ========
265
266
267 @noindent
268 With luck your system administrator will have installed SML mode
269 somewhere convenient, so all you have to do is put the line
270
271 @lisp
272 (require 'sml-site)
273 @end lisp
274
275 @noindent
276 in your @file{.emacs} configuration file and all will be well---you can
277 skip the rest of this getting started section. Otherwise you will need
278 to tell Emacs where to find all the SML mode @file{.el} files, and
279 when to use them. The where is addressed by locating the Lisp code on
280 your Emacs Lisp load path---you may have to create a directory for this,
281 say @file{/home/mjm/elisp}, and then insert the following lines in your
282 @file{/home/mjm/.emacs} file@footnote{cf.@: commentary in the site
283 initialisation file @file{sml-site.el}.}:
284
285 @lisp
286 (setq load-path (cons "/home/mjm/elisp" load-path))
287 (autoload 'sml-mode "sml-mode" "Major mode for editing SML." t)
288 @end lisp
289
290 @noindent
291 The first line adjusts Emacs' internal search path so it can locate the
292 Lisp source you have copied to that directory; the second line tells
293 Emacs to load the code automatically when it is needed. You can then
294 switch any Emacs buffer into SML mode by entering the command
295
296 @example
297 M-x sml-mode
298 @end example
299
300 @noindent
301 It is usually more convenient to have Emacs automatically place the
302 buffer in SML mode whenever you visit a file containing ML
303 programs. The simplest way of achieving this is to put something like
304
305 @lisp
306 (setq auto-mode-alist
307 (append '(("\\.sml$" . sml-mode)
308 ("\\.sig$" . sml-mode)
309 ("\\.ML$" . sml-mode)) auto-mode-alist))
310 @end lisp
311
312 @noindent
313 also in your @file{.emacs} file. Subsequently (after a restart), any
314 files with these extensions will be placed in SML mode buffers when
315 you visit them.
316
317
318 You may want to pre-compile the @file{sml-*.el} files (@kbd{M-x
319 byte-compile-file}) for greater speed---byte compiled code loads and
320 runs somewhat faster.
321
322 @c If you are irritated by the fact that there are several @sc{sml}
323 @c mode lisp files concatenate them in the order I listed them (but
324 @c don't include @file{sml-site} which should be kept apart).
325
326
327
328 @c ======================================================== GETTING HELP
329
330 @node Getting Help, , Getting Started, Introduction
331
332 @section Help!
333
334 @c == Getting Help, , Getting Started, Introduction ====================
335
336
337 @noindent
338 You're reading it. Apart from the on-line info tree (@kbd{C-h i} is the
339 Emacs key to enter the @code{info} system---you should follow the brief
340 tutorial if this is unfamiliar), there are further details on specific
341 commands in their documentation strings. Only the most useful
342 SML mode commands are documented in the info tree: to find out more
343 use Emacs' help facilities.
344
345 Briefly, to get help on a specific function use @kbd{C-h f} and enter
346 the command name. All (almost all, then) SML mode commands begin
347 with @code{sml-}, so if you type this and press @key{TAB} (for
348 completion) you will get a list of all commands. Another way is to use
349 @kbd{C-h a} and enter the string @code{sml}. This is command apropos; it
350 will list all commands with that sub-string in their names, and any key
351 binding they may have in the current buffer. Command apropos gives a
352 one-line synopsis of what each command does.
353
354 Some commands are also variables---such things are allowed in Lisp, if
355 not in ML! @xref{Command Index}, for a list of (info) documented
356 functions. @xref{Variable Index}, for a list of user settable variables
357 to control the behaviour of SML mode.
358
359 Before accessing this information on-line from within Emacs you may have
360 to set the variable @code{sml-mode-info}. Put in your @file{.emacs} file
361 something like:
362
363 @vindex sml-mode-info
364 @findex sml-mode-info
365 @kindex @kbd{C-c C-i}
366 @lisp
367 (setq sml-mode-info "/home/mjm/info/sml-mode.info")
368 @end lisp
369
370 @noindent
371 When different from the default this variable should be a string giving
372 the absolute name of the @file{.info} file. Then @kbd{C-c C-i} in
373 SML mode (i.e., the command @kbd{M-x sml-mode-info}) will bring up
374 the manual. This help is also accessible from the menu. (Resetting this
375 variable will not be necessary if your site administrator has been kind
376 enough to install SML mode and its attendant documentation in the
377 Emacs hierarchy.)
378
379
380 @c ============================================================ SML MODE
381
382 @node SML Mode, Interaction Mode, Introduction, Top
383
384 @chapter Editing with SML Mode
385
386 @c == SML Mode, Interaction Mode, Introduction, Top ====================
387
388
389 @noindent
390 Now SML mode provides just a few additional editing commands. Most
391 of the work (@pxref{Credits,,Credit & Blame}) has gone into implementing
392 the indentation algorithm which, if you think about it, has to be
393 complicated for a language like ML. @xref{SML Mode Defaults,,Indentation
394 Defaults}, for details on how to control some of the behaviour of the
395 indentation algorithm. Principal goodies are the `electric pipe'
396 feature, and the ability to insert common SML forms (macros or
397 templates).
398
399 @menu
400 * Basics:: On entering SML mode
401 * Indentation:: Prettying SML text
402 * Magic Insertion:: Templates and electric keys
403 * SML Mode Defaults:: Variables controlling indentation
404 @end menu
405
406
407 @c ============================================================== BASICS
408
409 @node Basics, Indentation, SML Mode, SML Mode
410
411 @section On entering SML mode
412
413 @c == Basics, Indentation, SML Mode, SML Mode ==========================
414
415 @noindent
416
417
418 @deffn Command sml-mode
419 This switches a buffer into SML mode. This is a @emph{major mode} in
420 Emacs. To get out of SML mode the buffer's major mode must be set to
421 something else, like @t{text-mode}. @xref{Getting Started}, for details
422 on how to set this up automatically when visiting an SML file.
423 @end deffn
424
425 Emacs is all hooks of course. A hook is a variable: if the variable is
426 non-nil it binds a list of Emacs Lisp functions to be run in some order
427 (usually left to right). You can customise SML mode with these
428 hooks:
429
430
431 @defvr Hook sml-mode-hook
432 Default: @code{nil}
433
434 This is run every time a new SML mode buffer is created (or if you
435 type @kbd{M-x sml-mode}). This is one place to put your preferred key
436 bindings. @xref{Configuration}, for some examples.
437 @end defvr
438
439
440 @defvr Hook sml-load-hook
441 Default: @code{'sml-mode-version}
442
443 Another, maybe better, place for key bindings. This hook is only run when
444 SML mode is loaded into Emacs. @xref{Configuration}.
445 @end defvr
446
447
448 @deffn Command sml-mode-version
449 Prints the current version of SML mode in the mini-buffer, in case
450 you need to know. I've put it on @code{sml-load-hook} so you can easily
451 tell which version of SML mode you are running.
452 @end deffn
453
454
455
456 @c ========================================================= INDENTATION
457
458 @node Indentation, Magic Insertion, Basics, SML Mode
459
460 @section Automatic indentation
461
462 @c == Indentation, Magic Insertion, Basics, SML Mode ===================
463
464
465 @noindent
466 ML is a complicated language to parse, let alone compile. The
467 indentation algorithm is a little wooden (for some tastes), and the best
468 advice is not to fight it! There are several variables that can be
469 adjusted to control the indentation algorithm (@pxref{SML Mode
470 Defaults,,Customising SML Mode}, below).
471
472
473 @deffn Command sml-indent-line
474 Key: @key{TAB}
475 @kindex @key{TAB}
476
477 This command indents the current line. If you set the indentation of the
478 previous line by hand, @code{sml-indent-line} will indent relative to
479 this setting.
480 @end deffn
481
482
483 @deffn Command sml-indent-region
484 Key: @kbd{C-M-\}
485 @kindex @kbd{C-M-\}
486
487 Indent the current region. Be patient if the region is large (like the
488 whole buffer).
489 @end deffn
490
491
492 @deffn Command sml-back-to-outer-indent
493 Key: @kbd{M-@key{TAB}}
494 @kindex @kbd{M-@key{TAB}}
495
496 Unindents the line to the next outer level of indentation.
497 @end deffn
498
499
500
501 Further indentation commands that Emacs provides (generically, for all
502 modes) that you may like to recall:
503
504 @itemize @minus
505 @item
506 @kbd{M-x newline-and-indent}
507
508 On @key{LFD} by default.
509 @kindex @key{LFD}
510 Insert a newline, then indent according to the major mode. @xref{Program
511 Indent,,Indentation for Programs,emacs,The Emacs Editor Manual}, for
512 details.
513
514 @item
515 @kbd{M-x indent-rigidly}
516
517 On @kbd{C-x @key{TAB}} by default.
518 @kindex @kbd{C-x @key{TAB}}
519 Moves all lines in the region right by its argument (left, for negative
520 arguments). @xref{Indentation,,,emacs,The Emacs Editor Manual}.
521
522 @item
523 @kbd{M-x indent-for-comment}
524
525 On @kbd{M-;} by default.
526 @kindex @kbd{M-;}
527 Indent this line's comment to comment column, or insert an empty
528 comment. @xref{Comment Commands,,,emacs,The Emacs Editor
529 Manual}.
530
531 @item
532 @kbd{M-x indent-new-comment-line}
533
534 On @kbd{M-@key{LFD}} by default.
535 @kindex @kbd{M-@key{LFD}}
536 Break line at point and indent, continuing comment if within one.
537 @xref{Multi-Line Comments,,,emacs,The Emacs Editor Manual}.
538 @end itemize
539
540 @kindex @kbd{C-x ;}
541 As with other language modes, @kbd{M-;} gives you a comment at the end
542 of the current line. The column where the comment starts is determined
543 by the variable @code{comment-column}---default is 40, but it can be
544 changed with @code{set-comment-column} (on @kbd{C-x ;} by default).
545
546
547 @c ===================================================== MAGIC INSERTION
548
549 @node Magic Insertion, SML Mode Defaults, Indentation, SML Mode
550
551 @section Electric features
552
553 @c == Magic Insertion, SML Mode Defaults, Indentation, SML Mode ========
554
555
556 @noindent
557 Electric keys are generally pretty irritating, so those provided by
558 SML mode are fairly muted. The only truly electric key is @kbd{;},
559 and this has to be enabled to take effect.
560
561
562 @deffn Command sml-electric-pipe
563 Key: @kbd{M-|}
564 @kindex @kbd{M-|}
565
566 When the point is in a `case' statement this opens a new line, indents
567 and inserts @code{| =>} leaving point just before the double arrow; if
568 the enclosing construct is a `fun' declaration, the newline is indented
569 and the function name copied at the appropriate column. Generally, try
570 it whenever a @code{|} is wanted---you'll like it!
571 @end deffn
572
573
574 @deffn Command sml-electric-semi
575 Key: @kbd{;}
576 @kindex @kbd{;}
577
578 Just inserts a semi-colon, usually. The behaviour of this command is
579 governed by the variable @code{sml-electric-semi-mode}.
580 @end deffn
581
582
583 @defvr {Command, Variable} sml-electric-semi-mode
584 Default: @code{nil}
585
586 If this variable is @code{nil}, @code{sml-electric-semi} just inserts a
587 semi-colon, otherwise it inserts a semi-colon and a newline, and indents
588 the newline for SML. The command toggles the value of the variable; if
589 you give the command a prefix argument (i.e., @kbd{C-u M-x
590 sml-electric-semi-mode}) this always disables the electric effect of
591 @kbd{;}.
592 @end defvr
593
594
595 @deffn Command sml-insert-form
596 Key: @kbd{C-c @key{RET}}
597 @kindex @kbd{C-c @key{RET}}
598
599 Interactive short-cut to insert common ML forms (a.k.a.@: macros, or
600 templates). Recognised forms are `let', `local', `case', `abstype',
601 `datatype', `signature', `structure', and `functor'. Except for `let'
602 and `local', these will prompt for appropriate parameters like functor
603 name and signature, etc.. This command prompts in the mini-buffer, with
604 completion.
605
606 By default @kbd{C-c @key{RET}} will insert at point, with the
607 indentation of the current column; if you give a prefix argument (i.e.,
608 @kbd{C-u C-c @key{RET}}) the command will insert a newline first,
609 indent, and then insert the template.
610 @end deffn
611
612 @code{sml-insert-form} is also extensible: see @ref{Configuration} for
613 further details.
614
615
616
617 @c ======================================================= MODE DEFAULTS
618
619 @node SML Mode Defaults, , Magic Insertion, SML Mode
620
621 @section Indentation defaults
622
623 @c == SML Mode Defaults, , Magic Insertion, SML Mode ===================
624
625
626 @noindent
627 Several variables try to control the indentation algorithm and other
628 features of SML mode. For these user settable variables there is
629 generally a function of the same name that does the job---look for them
630 in the menu under @emph{Format/Mode Variables}.
631
632
633 @defvr {Command, Variable} sml-indent-level
634 @findex sml-indent-level
635 Default: @code{4}
636
637 This variable controls the block indentation level. The command prompts
638 for a numeric value unless a numeric prefix is provided instead. For
639 example @kbd{M-2 M-x sml-indent-level} will set the variable to 2
640 without prompting.
641 @end defvr
642
643
644 @defvr {Command, Variable} sml-pipe-indent
645 @findex sml-pipe-indent
646 Default: @code{-2}
647
648 This variable adjusts the indentation level for lines that begin with a
649 @code{|} (after any white space). The extra offset is usually negative.
650 The command prompts for a numeric value unless a numeric prefix is
651 provided instead.
652 @end defvr
653
654
655 @defvar sml-paren-lookback
656 Default: @code{1000}
657
658 The number of characters the indentation algorithm searches for an
659 opening parenthesis. 1000 characters is about 30-40 lines; larger values
660 mean slower indentation. If the value of the variable is @code{nil} this
661 means the indentation algorithm won't look back at all.
662 @end defvar
663
664
665 If the default values are not acceptable you can set these variables
666 permanently in your @file{.emacs} file. @xref{Configuration}, for
667 details and examples. Three further variables control the behaviour of
668 indentation.
669
670
671 @defvr {Command, Variable} sml-case-indent
672 @findex sml-case-indent
673 Default: @code{nil}
674
675 How to indent `case' expressions:
676
677 @iftex
678 @example
679 @r{If @code{t}:} @r{If @code{nil}:}
680 case expr case expr of
681 of exp1 => ... exp1 => ...
682 | exp2 => ... | exp2 => ...
683 @end example
684 @end iftex
685 @ifinfo
686 @example
687 If @code{t}: If @code{nil}:
688 case expr case expr of
689 of exp1 => ... exp1 => ...
690 | exp2 => ... | exp2 => ...
691 @end example
692 @end ifinfo
693
694 The first seems to be the standard in SML/NJ. The second is the (nicer?)
695 default.
696 @end defvr
697
698
699 @defvr {Command, Variable} sml-nested-if-indent
700 @findex sml-nested-if-indent
701 Default: @code{nil}
702
703 Nested `if-then-else' expressions have the following indentation
704 depending on the value.
705
706 @iftex
707 @example
708 @r{If @code{t}:} @r{If @code{nil}:}
709 if exp1 then exp2 if exp1 then exp2
710 else if exp3 then exp4 else if exp3 then exp4
711 else if exp5 then exp6 else if exp5 then exp6
712 else exp7 else exp7
713 @end example
714 @end iftex
715 @ifinfo
716 @example
717 If @code{t}: If @code{nil}:
718 if exp1 then exp2 if exp1 then exp2
719 else if exp3 then exp4 else if exp3 then exp4
720 else if exp5 then exp6 else if exp5 then exp6
721 else exp7 else exp7
722 @end example
723 @end ifinfo
724 @end defvr
725
726
727 @defvr {Command, Variable} sml-type-of-indent
728 @findex sml-type-of-indent
729 Default: @code{t}
730
731 Determines how to indent `let', `struct', etc..
732
733 @iftex
734 @example
735 @r{If @code{t}:} @r{If @code{nil}:}
736 fun foo bar = let fun foo bar = let
737 val p = 4 val p = 4
738 in in
739 bar + p bar + p
740 end end
741 @end example
742 @end iftex
743 @ifinfo
744 @example
745 If @code{t}: If @code{nil}:
746 fun foo bar = let fun foo bar = let
747 val p = 4 val p = 4
748 in in
749 bar + p bar + p
750 end end
751 @end example
752 @end ifinfo
753
754 @code{sml-type-of-indent} will not have any effect if the starting
755 keyword is the first word on the line.
756 @end defvr
757
758 @c end vtable
759
760
761 @c ========================================================= INTERACTION
762
763 @node Interaction Mode, Configuration, SML Mode, Top
764
765 @chapter Running ML under Emacs
766
767 @c == Interaction Mode, Configuration, SML Mode, Top ===================
768
769
770 @noindent
771 The most useful feature of SML mode is that it provides a convenient
772 interface to the compiler. How serious users of ML put up with a
773 teletype interface to the compiler is beyond me@.@.@. but perhaps there
774 are other interfaces to compilers that require one to part with serious
775 money. Such remarks can quickly become dated---in this case, let's hope
776 so!
777
778 Anyway, SML mode provides an interaction mode,
779 @code{inferior-sml-mode}, where the compiler runs in a separate buffer
780 in a window or frame of its own. You can use this buffer just like a
781 terminal, but it's usually more convenient to mark some text in the
782 SML mode buffer and have Emacs communicate with the sub-process. The
783 features discussed below are syntax-independent, so they should work
784 with a wide range of ML-like tools and compilers. @xref{Process
785 Defaults}, for some hints.
786
787 @findex inferior-sml-mode
788 @code{inferior-sml-mode} is a specialisation of the @file{comint}
789 package that comes with GNU Emacs and GNU XEmacs.
790
791
792 @menu
793 * Running ML:: Commands to run the ML compiler in a buffer
794 * ML Interaction:: Sending program fragments to the compiler
795 * Tracking Errors:: Finding reported syntax errors
796 * Process Defaults:: Setting defaults for process interaction
797 @end menu
798
799
800
801 @c ========================================================== RUNNING ML
802
803 @node Running ML, ML Interaction, Interaction Mode, Interaction Mode
804
805 @section Starting the compiler
806
807 @c == Running ML, ML Interaction, Interaction Mode, Interaction Mode ==
808
809 @noindent
810 Start your favourite ML compiler with the command
811
812 @example
813 @kbd{M-x run-sml}
814 @end example
815
816 @noindent
817 This creates a process interaction buffer that inherits some key
818 bindings from SML mode and from @file{comint} (@pxref{Shell Mode, ,
819 , emacs, The Emacs Editor Manual}). Starting the ML compiler adds some
820 functions to SML mode buffers so that program text can be
821 communicated between editor and compiler (@pxref{ML Interaction}).
822
823 The name of the ML compiler is the first thing you should know how to
824 specify:
825
826
827 @defvar sml-program-name
828 Default: @code{"sml"}
829
830 The program to run as ML. You might need to specify the full path name
831 of the program.
832 @end defvar
833
834
835 @defvar sml-default-arg
836 Default: @code{""}
837
838 Useful for Poly/ML users who may supply a database file, or others who
839 have wrappers for setting various options around the command to run the
840 compiler. Moscow ML people might set this to @code{"-P full"}, etc..
841 @end defvar
842
843 The variable @code{sml-program-name} is a string holding the name
844 of the program @emph{as you would type it at the shell}. You
845 can always choose a program different to the default by invoking
846
847 @example
848 @kbd{C-u M-x run-sml}
849 @end example
850
851 @noindent
852 With the prefix argument Emacs will prompt for the command name and any
853 command line arguments to pass to the compiler. Thereafter Emacs will
854 use this new name as the default, but for a permanent change you should
855 set this in your @file{.emacs} with, e.g.:
856
857 @lisp
858 (setq sml-program-name "nj-sml")
859 @end lisp
860
861 @noindent
862 You probably shouldn't set this in @code{sml-mode-hook} because that
863 will interfere if you occasionally run a different compiler (e.g.,
864 @code{poly} or @code{hol90}).
865
866
867
868 @deffn Command run-sml
869 Launches ML as an inferior process in another buffer; if an ML process
870 already exists, just switch to the process buffer. A prefix argument
871 allows you to edit the command line to specify the program, and any
872 command line options.
873 @end deffn
874
875
876 @defvr Hook inferior-sml-mode-hook
877 Default: @code{nil}
878
879 @kbd{M-x run-sml} runs @code{comint-mode-hook} and
880 @code{inferior-sml-mode-hook} hooks in that order, but @emph{after} the
881 compiler is started. Use @code{inferior-sml-mode-hook} to set any
882 @code{comint} buffer-local configurations for SML mode you like.
883 @end defvr
884
885
886 @defvr Hook inferior-sml-load-hook
887 Default: @code{nil}
888
889 This hook is analogous to @code{sml-load-hook} and is run just after the
890 code for @code{inferior-sml-mode} is loaded into Emacs. Use this to set
891 process defaults, and preferred key bindings for the interaction buffer.
892 @end defvr
893
894
895 @deffn Command switch-to-sml
896 Key: @kbd{C-c C-s}
897 @kindex @kbd{C-c C-s}
898
899 Switch from the SML buffer to the interaction buffer. By default point
900 will be placed at the end of the process buffer, but a prefix argument
901 will leave point wherever it was before. If you try @kbd{C-c C-s} before
902 an ML process has been started, you'll just get an error message to the
903 effect that there's no current process buffer.
904 @end deffn
905
906
907 @deffn Command sml-cd
908 When started, the ML compiler's default working directory is the
909 current buffer's default directory. This command allows the working
910 directory to be changed, if the compiler can do this. The variable
911 @code{sml-cd-command} specifies the compiler command to invoke
912 (@pxref{Process Defaults}).
913 @end deffn
914
915
916
917 @c @findex inferior-sml-mode
918 @c It's unlikely you will ever need this, but @code{inferior-sml-mode} is
919 @c the command that will put the current buffer into ML interaction mode.
920 @c Note that if you try @kbd{C-c C-s} before an ML process has been
921 @c started, you'll just get an error message to the effect that there's no
922 @c current process buffer.
923
924
925
926 @c ======================================================== SENDING TEXT
927
928 @node ML Interaction, Tracking Errors, Running ML, Interaction Mode
929
930 @section Speaking to the compiler
931
932 @c == ML Interaction, Tracking Errors, Running ML, Interaction Mode ====
933
934
935 @noindent
936 Several commands are defined for sending program fragments to the
937 running compiler. Each of the following commands takes a prefix argument
938 that will switch the input focus to the process buffer afterwards
939 (leaving point at the end of the buffer):
940
941
942 @deffn Command sml-load-file
943 Key: @kbd{C-c C-l}
944 @kindex @kbd{C-c C-l}
945
946 Send a `use file' command to the current ML process. The variable
947 @code{sml-use-command} is used to define the correct template for the
948 command to invoke (@pxref{Process Defaults}). The default file is the
949 file associated with the current buffer, or the last file loaded if you
950 are in the interaction buffer.
951 @end deffn
952
953
954
955 @deffn Command sml-send-region
956 @findex sml-send-region-and-go
957 Key: @kbd{C-c C-r}
958 @kindex @kbd{C-c C-r}
959
960 Send the current region of text in the SML buffer.
961 @code{sml-send-region-and-go} is a similar command for you to bind in
962 SML mode if you wish: it'll send the region and then switch-to-sml.
963 @end deffn
964
965 @deffn Command sml-drag-region
966 Key: @kbd{M-S-down-mouse-1}
967 @kindex @kbd{M-S-down-mouse-1}
968
969 It's sometimes irritating to do all that @kbd{C-@@} and @kbd{C-c C-r}
970 stuff to send regions to the ML process, so if you are running Emacs
971 under X Windows (say) you can do the same job by holding down both the
972 @key{SHIFT} and @key{META} keys, and dragging with mouse button one over
973 the region. This will temporarily highlight the region as you move the
974 mouse, like @code{mouse-drag-region} (i.e., @kbd{down-mouse-1}),
975 and send the highlighted text straight into the jaws of the ML compiler.
976
977 If you only click the mouse button, instead of dragging, the region of
978 text sent to the compiler is delimited by the current position of point
979 and the place where you click the mouse. In neither case will the
980 command set the region.
981 @end deffn
982
983 @c @deffn Command sml-send-function
984 @c @findex sml-send-function-and-go
985
986 @c Send the enclosing `function' definition. Contrary to the suggestive
987 @c name, this command @emph{does not} try to determine the extent of the
988 @c function definition because that is too difficult with ML. Instead
989 @c this just sends the enclosing @emph{paragraph} (delimited by blank
990 @c lines or form-feed characters).
991 @c @end deffn
992
993 @deffn Command sml-send-buffer
994 Key: @kbd{C-c C-b}
995 @kindex @kbd{C-c C-b}
996
997 Send the contents of the current buffer to ML.
998 @end deffn
999
1000 @c Two further commands are defined for you to bind to keys if you wish:
1001 @c @code{sml-send-region-and-go} and @code{sml-send-function-and-go}. Both
1002 @c automatically switch to the interaction buffer.
1003
1004
1005 By and large, Emacs can nowadays quite happily send large chunks of text
1006 to its subprocesses (@file{comint} does input splitting). However, it is
1007 still probably safest@footnote{XEmacs 19.11 users are warned that
1008 changing the default @code{sml-temp-threshold} may well cause XEmacs to
1009 hang; they seem to have fixed the problem in 19.12 and above.} to send
1010 larger program fragments to ML via the temporary file mechanism. This,
1011 for @code{sml-send-region} and other SML mode commands that use it
1012 in some way, takes advantage of the ML compiler's ability to open a file
1013 and compile the contents by making a temporary file of the indicated
1014 text. Two variables of interest are:
1015
1016
1017 @defvar sml-temp-threshold
1018 Default: @code{0}
1019
1020 Determines what constitutes a large program fragment. A value of 512,
1021 say, will declare half a kilobyte a suitable threshold and larger
1022 fragments will be sent via a temporary file. A value of 0 means
1023 @emph{all} text is sent via a temporary file; the value @code{nil}
1024 inhibits the temporary file mechanism altogether.
1025 @end defvar
1026
1027
1028 @defvar sml-temp-file
1029 Default: @code{(make-temp-name "/tmp/ml")}
1030
1031 A string that gives the name of the temporary file to use. This
1032 default ensures Emacs will invent a unique name for this purpose for
1033 use throughout the rest of the editing session. Only one temporary
1034 file is used.
1035 @end defvar
1036
1037
1038 Another reason, you might well say @emph{the reason}, for using the
1039 temporary file mechanism is that error messages reported by the ML
1040 compiler (@pxref{Tracking Errors}) are generally useless to SML mode
1041 unless a real file is associated with the input (an embedded @emph{use
1042 file} will count as a real file). Of course, this all rather depends on
1043 the compiler producing sensible error messages, and on SML mode
1044 being able to parse them.
1045
1046
1047 @c ===================================================== TRACKING ERRORS
1048
1049 @node Tracking Errors, Process Defaults, ML Interaction, Interaction Mode
1050
1051 @section Finding errors
1052
1053 @c == Tracking Errors, Process Defaults, ML Interaction, Interaction Mode
1054
1055
1056 @noindent
1057 SML mode provides one customisable function for locating the source
1058 position of errors reported by the compiler. This should work whether
1059 you type @code{use "puzzle.sml";} into the interaction buffer, or use
1060 one of the mechanisms provided for sending programs directly to the
1061 compiler---@pxref{ML Interaction}.
1062
1063
1064 @deffn Command sml-next-error
1065 @findex sml-skip-errors
1066 Key: @kbd{C-c`}
1067 @kindex @kbd{C-c`}
1068
1069 Jump to the source location of the next error reported by the compiler.
1070 If the function bound to @code{sml-error-parser} returns a range of
1071 character positions for the location of the error in the source file,
1072 @code{sml-next-error} will put the mark at the end of the range with
1073 point at the beginning; it may also highlight the region specified; it
1074 will also echo the one-line text of the error message if the error
1075 parser returns one.@footnote{Does @code{sml-error-parser} return these
1076 nice things? The answer is complicated! @xref{Advanced Topics}, and the
1077 docstring @kbd{C-h v sml-error-parser}.}
1078
1079 If you enter @kbd{C-u C-c`} instead, the command (a.k.a.@:
1080 @code{sml-skip-errors}) skips past all the remaining error messages and
1081 removes any error overlay in the current buffer. Note that @kbd{C-c`}
1082 also works in the ML interaction buffer (by default).
1083 @end deffn
1084
1085
1086 @defvr {Variable, Command} sml-error-overlay
1087 @findex sml-error-overlay
1088 Default: @code{t}
1089
1090 Legal default values for this buffer-local variable are @code{t} and
1091 @code{nil}. The variable attains a local value in each SML mode
1092 buffer when the default is @code{t}; in this case the local value is an
1093 overlay (or @emph{extent} in XEmacs speak), and this means
1094 @code{sml-next-error} will highlight errors in the buffer when it can.
1095 If the default is @code{nil} it stays that way and @code{sml-next-error}
1096 will not highlight anything, ever.
1097
1098 The command @kbd{M-x sml-error-overlay} will set the overlay around the
1099 current region, or remove the overlay if a prefix argument is given
1100 (i.e., @kbd{C-u M-x sml-error-overlay} removes the overlay, but this
1101 functionality can be accessed from the menu to save typing).
1102 @end defvr
1103
1104
1105 Note that SML mode will usually locate errors relative to the start
1106 of the last major program fragment sent to the compiler (via
1107 @code{sml-load-file}, etc.), but if you don't use the temporary file
1108 mechanism to communicate text to the ML process (@pxref{Process
1109 Defaults}), errors will generally not be located at all.
1110
1111
1112 @c ==================================================== PROCESS DEFAULTS
1113
1114 @node Process Defaults, , Tracking Errors, Interaction Mode
1115
1116 @section Process defaults
1117
1118 @c == Process Defaults, , Tracking Errors, Interaction Mode ============
1119
1120 @noindent
1121 The process interaction code is independent of the compiler used,
1122 deliberately, so SML mode will work with a variety of ML compilers
1123 and ML-based tools. There are therefore a number of variables that may
1124 need to be set correctly before SML mode can speak to the compiler.
1125 Things are by default set up for Standard ML of New Jersey, but
1126 switching to a new system is quite easy---very easy if you are using
1127 Poly/ML or Moscow ML as these are supported by libraries bundled with
1128 SML mode.
1129
1130
1131
1132 @defvar sml-use-command
1133 Default: @code{"use \"%s\""}
1134
1135 Use file command template. Emacs will replace the @code{%s} with a file
1136 name. Note that Emacs requires double quote characters inside strings
1137 to be quoted with a backslash.
1138 @end defvar
1139
1140
1141 @defvar sml-cd-command
1142 Default: @code{"OS.FileSys.chDir \"%s\""}
1143
1144 Compiler command to change the working directory. Not all ML systems
1145 support this feature (well, Edinburgh (core) ML didn't), but they
1146 should.
1147 @end defvar
1148
1149
1150 @defvar sml-prompt-regexp
1151 Default: @code{"^[\-=] *"}
1152
1153 Matches the ML compiler's prompt: @file{comint} uses this for various
1154 purposes.
1155 @end defvar
1156
1157
1158 To customise error reportage for different ML compilers you need to set
1159 two further variables before @code{sml-next-error} can be useful:
1160
1161
1162 @defvar sml-error-regexp
1163 Default: @code{sml-smlnj-error-regexp}
1164
1165 This is the regular expression for matching the start of an error
1166 message. The default matches the Standard ML of New Jersey compiler's
1167 Error and Warning messages. If you don't want stop at Warnings try, for
1168 example:
1169 @example
1170 "^[-= ]*.+:[0-9]+\\.[0-9]+.+Error:"
1171 @end example
1172 If you're using Edinburgh (core) ML try @code{"^Parse error:"}.
1173 @end defvar
1174
1175
1176 @defvar sml-error-parser
1177 Default: @code{'sml-smlnj-error-parser}
1178
1179 The function that actually parses the error message. Again, the default
1180 is for SML/NJ. If you need to change this you may have to do a little
1181 Emacs Lisp programming.
1182 @end defvar
1183
1184
1185 Note that bundled libraries supply an @code{sml-mosml-error-parser} and
1186 an @code{sml-poly-ml-error-parser}, and set all the attendant compiler
1187 variables. @xref{Advanced Topics}, for tips on how to program your own
1188 compiler extension to SML mode.
1189
1190
1191 @c A typical way of (re)setting these variables correctly is to put
1192 @c something in your @file{.emacs} file that resembles
1193
1194 @c @example
1195 @c (setq sml-use-command "PolyML.use \"%s\"")
1196 @c (setq sml-prompt-regexp "^[>#] *")
1197 @c @end example
1198
1199 @c @noindent
1200 @c probably on @code{inferior-sml-load-hook} (but @pxref{Configuration},
1201 @c first).
1202
1203
1204 @c ======================================================= CONFIGURATION
1205
1206 @node Configuration, Credits, Interaction Mode, Top
1207
1208 @chapter Configuration Summary
1209
1210 @c == Configuration, Credits, Interaction Mode, Top ===================
1211
1212 @c @footnote{@url{http://www.ahl.co.uk/}}
1213 @c @footnote{@url{http://www.dina.kvl.dk/~sestoft/mosml.html}}
1214
1215 @noindent
1216 This (sort of pedagogic) section gives more information on how to
1217 configure SML mode: menus, key bindings, hooks and highlighting are
1218 discussed, along with a few other random topics. First, though, the
1219 auxiliary files @file{sml-poly-ml.el} and @file{sml-mosml.el} define
1220 defaults for these popular (?) ML compilers---Poly/ML and Moscow ML,
1221 respectively. One way to setup SML mode to use Moscow ML is to add
1222 to your @file{.emacs}:
1223
1224 @example
1225 (defun my-mosml-setup () "Initialise inferior SML mode for Moscow ML."
1226 (load-library "sml-mosml.el")
1227 (setq sml-program-name "/home/mjm/mosml/bin/mosml"))
1228 (add-hook 'inferior-sml-load-hook 'my-mosml-setup)
1229 @end example
1230
1231 @noindent
1232 which creates a hook function @code{my-mosml-setup} and adds it to
1233 @code{inferior-sml-load-hook} so that the defaults for
1234 @code{sml-error-regexp} and its ilk (@pxref{Process Defaults}) are
1235 correctly initialised; I have to set @code{sml-program-name} explicitly
1236 here because that directory isn't on my (Unix) PATH. The story is
1237 similar if you use Poly/ML.
1238 Note, by the way, that order matters here: the @code{load-library} call
1239 comes first because the default for @code{sml-program-name} in
1240 @file{sml-mosml.el} is just @code{"mosml"}.
1241
1242 @c @example
1243 @c (eval-after-load "sml-proc" '(my-mosml-setup))
1244 @c @end example
1245 @c @noindent
1246 @c is perhaps a better way to achieve the same effect, but last time I
1247 @c looked this wouldn't work in XEmacs.
1248
1249 The auxiliary libraries bundled with SML mode define commands
1250 @code{sml-mosml} and @code{sml-poly-ml} (there's also an
1251 @code{sml-smlnj} for uniformity); these commands prompt for suitable
1252 values for @code{sml-program-name} and @code{sml-default-arg} before
1253 starting the compiler and setting the other process defaults. A prefix
1254 argument will give you the builtin defaults with no questions asked.
1255
1256 @menu
1257 * Hooks:: Creating them
1258 * Key Bindings:: Binding commands to keys
1259 * Menus:: Taking advantage of bitmapped screens
1260 * Highlighting:: Syntax colouring
1261 * Advanced Topics:: You may need to speak Emacs Lisp
1262 @end menu
1263
1264
1265 @c =============================================================== HOOKS
1266
1267 @node Hooks, Key Bindings, Configuration, Configuration
1268
1269 @section Hooks
1270
1271 @c == Hooks, Key Bindings, Configuration, Configuration ================
1272
1273
1274 @noindent
1275 One way to set SML mode variables (@pxref{SML Mode
1276 Defaults,,Indentation Defaults}), and other defaults, is through the
1277 @code{sml-mode-hook} in your @file{.emacs}. A simple example:
1278
1279 @lisp
1280 (defun my-sml-mode-hook () "Local defaults for SML mode"
1281 (setq sml-indent-level 2) ; conserve on horizontal space
1282 (setq words-include-escape t) ; \ loses word break status
1283 (setq indent-tabs-mode nil)) ; never ever indent with tabs
1284 (add-hook 'sml-mode-hook 'my-sml-mode-hook)
1285 @end lisp
1286 @noindent
1287 The body of @code{my-sml-mode-hook} is a sequence of bindings. In this
1288 case it is not really necessary to set @code{sml-indent-level} in a hook
1289 because this variable is global (most SML mode variables are). With
1290 similar effect:
1291
1292 @lisp
1293 (setq sml-indent-level 2)
1294 @end lisp
1295 @noindent
1296 anywhere in your @file{.emacs} file (but probably on
1297 @code{sml-load-hook}). The variable @code{indent-tabs-mode} is
1298 automatically made local to the current buffer whenever it is set
1299 explicitly, so it @emph{must} be set in a hook if you always want
1300 SML mode to behave like this. The same goes for the buffer-local
1301 @code{sml-error-overlay}; since this is globally @code{t} by default,
1302 set it globally @code{nil} if you never want errors highlighted:
1303
1304 @lisp
1305 (setq-default sml-error-overlay nil)
1306 @end lisp
1307 @noindent
1308 Again, on @code{sml-load-hook} would probably be the best place.
1309
1310
1311 Another hook is @code{inferior-sml-mode-hook}. This can be used to
1312 control the behaviour of the interaction buffer through various
1313 variables meaningful to @file{comint}-based packages:
1314
1315 @lisp
1316 (defun my-inf-sml-mode-hook () "Local defaults for inferior SML mode"
1317 (add-hook 'comint-output-filter-functions 'comint-truncate-buffer)
1318 (setq comint-scroll-show-maximum-output t)
1319 (setq comint-input-autoexpand nil))
1320 (add-hook 'inferior-sml-mode-hook 'my-inf-sml-mode-hook)
1321 @end lisp
1322 @noindent
1323 Again, the body is a sequence of bindings. Unless you run several ML
1324 compilers simultaneously under one Emacs, this hook will normally only
1325 get run once. You might want to look up the documentation (@kbd{C-h v}
1326 and @kbd{C-h f}) for these buffer-local @code{comint} things.
1327
1328
1329 @c ======================================================== Key Bindings
1330
1331 @node Key Bindings, Menus, Hooks, Configuration
1332
1333 @section Key bindings
1334
1335 @c == Key Bindings, Menus, Hooks, Configuration ========================
1336
1337
1338 @noindent
1339 Customisation (in Emacs) usually entails putting favourite commands on
1340 easily remembered keys. Two `keymaps' are defined in SML mode: one
1341 is effective in program text buffers (@code{sml-mode-map}) and the other
1342 is effective in interaction buffers (@code{inferior-sml-mode-map}).
1343 The initial design ensures that (many of) the default key bindings from
1344 the former keymap will also be available in the latter (e.g.,
1345 @kbd{C-c`}).
1346
1347 Type @kbd{C-h m} in an SML mode buffer to find the default key
1348 bindings (and similarly in an ML interaction buffer), and use the hooks
1349 provided to install your preferred key bindings. Given that the keymaps
1350 are global (variables):
1351
1352 @lisp
1353 (defun my-sml-load-hook () "Global defaults for SML mode"
1354 (define-key sml-mode-map "\C-cd" 'sml-cd)
1355 (define-key sml-mode-map "\C-co" 'sml-error-overlay))
1356 (add-hook 'sml-load-hook 'my-sml-load-hook)
1357 @end lisp
1358 @noindent
1359 This has the effect of binding @code{sml-cd} to the key @kbd{C-c d}, and
1360 the command @code{sml-error-overlay} to the key @kbd{C-c o}. If you want
1361 the same behaviour from @kbd{C-c d} in the ML buffer:
1362
1363 @lisp
1364 (defun my-inf-sml-load-hook () "Global defaults for inferior SML mode"
1365 (define-key inferior-sml-mode-map "\C-cd" 'sml-cd)
1366 ;; NB. for SML/NJ '96
1367 (setq sml-cd-command "OS.FileSys.chDir \"%s\""))
1368 (add-hook 'inferior-sml-load-hook 'my-inf-sml-load-hook)
1369 @end lisp
1370
1371 There is nothing to stop you rebuilding the entire keymap for
1372 SML mode and the ML interaction buffer in your @file{.emacs} of
1373 course: SML mode won't define @code{sml-mode-map} or
1374 @code{inferior-sml-mode-map} if you have already done so.
1375
1376
1377 @c =============================================================== Menus
1378
1379 @node Menus, Highlighting, Key Bindings, Configuration
1380
1381 @section Menus
1382
1383 @c == Menus, Highlighting, Key Bindings, Configuration =================
1384
1385
1386 @noindent
1387 Menus are useful for fiddling with mode defaults and finding out what
1388 keys commands are on if you are forgetful (not all commands are listed
1389 in the menu). For menus to appear in the menu bar under GNU Emacs or GNU
1390 XEmacs, the editor must be able to find one of two packages---i.e., one
1391 or both must be on your @code{load-path}. The first option is
1392 @file{easymenu} which is distributed with GNU Emacs. Easy!
1393
1394 The second option is @file{auc-menu} which was written by Per Abrahamsen
1395 and distributed with AUCTeX, but it is independently available from the
1396 IESD lisp archive@footnote{@url{ftp://sunsite.auc.dk/packages/auctex/}}
1397 at Aalborg. You'll also find @file{auc-menu} is available from the LCD
1398 archive@footnote{@url{ftp://archive.cis.ohio-state.edu/pub/gnu/emacs/elisp-archive/misc/}},
1399 the main repository for all Emacs Lisp. The advantage of @file{auc-menu}
1400 is that it works with XEmacs too.
1401
1402 Notice that certain menu entries are not illuminated at first---these
1403 are generally functions that depend on there being an ML process running
1404 with which to communicate.
1405
1406
1407 @c ======================================================== Highlighting
1408
1409 @node Highlighting, Advanced Topics, Menus, Configuration
1410
1411 @section Syntax colouring
1412
1413 @c == Highlighting, Advanced Topics, Menus, Configuration ==============
1414
1415
1416 @noindent
1417 Highlighting is very handy for picking out keywords in the program text,
1418 spotting misspelled kewyords, and, if you have Emacs' @file{ps-print}
1419 package installed (you usually do these days), obtaining pretty, even
1420 colourful code listings---quite properly for your colourful ML programs.
1421
1422 @vindex sml-font-lock-extra-keywords
1423 @vindex sml-font-lock-auto-on
1424
1425 Various highlight (hilite, if you spell real bad!) packages are
1426 available for GNU Emacs 19, and GNU XEmacs. SML mode can use either
1427 @file{hilit19} which only comes with Emacs, or @file{font-lock} which is
1428 the package of choice with XEmacs. If you are not familiar with these
1429 highlight packages you'll have to check their sources for installation
1430 guidelines, etc..
1431
1432 Use @code{sml-load-hook} to tell Emacs which scheme you prefer for
1433 SML mode. For example:
1434
1435 @lisp
1436 (add-hook 'sml-load-hook '(lambda () (require 'sml-font)))
1437 @end lisp
1438
1439 @noindent
1440 This ensures the SML extensions to @file{font-lock} will be available
1441 once SML mode loads (from @file{sml-font.el}---if you prefer
1442 @file{hilit19} you should @code{(require 'sml-hilite)} instead.
1443
1444 The variable @code{sml-font-lock-extra-keywords} is for further
1445 customising @file{font-lock} for SML mode. The value of the variable
1446 should be a list of strings, each of which is a regular expression that
1447 should match the desired keyword exactly. Here's an example:
1448
1449 @lisp
1450 (setq sml-font-lock-extra-keywords
1451 '("\\babstraction\\b" "\\bfunsig\\b" "=>" "::"))))
1452 @end lisp
1453
1454 @noindent
1455 The @code{\b} marks a word boundary, according to the syntax table
1456 defined for SML mode. Backslash must be quoted inside a string.
1457 @xref{Regexps,,,emacs,The Emacs Editor Manual}, for a summary of Emacs'
1458 regular expression syntax.
1459
1460
1461 Finally, the variable @code{sml-font-lock-auto-on} can be used to
1462 control whether or not @file{font-lock} should be enabled by default in
1463 SML mode buffers; it is enabled by default. The @code{sml-hilite}
1464 package is customisable, but only with regard to colour changes.
1465
1466
1467 @c ===================================================== ADVANCED TOPICS
1468
1469 @node Advanced Topics, , Highlighting, Configuration
1470
1471 @section Advanced Topics
1472
1473 @c == Advanced Topics, , Highlighting, Configuration ===================
1474
1475 @menu
1476 * Forms:: These forms are bloody useless; can't we have better ones?
1477 * Indents:: I hate that indentation algorithm; can't I suppress it?
1478 * Multi ML:: Can SML mode handle more than one compiler running at once?
1479 * Other ML:: What needs to be done to support other ML compilers?
1480 @end menu
1481
1482
1483 @node Forms, Indents, Advanced Topics, Advanced Topics
1484
1485 @flushright
1486 @emph{These forms are bloody useless; can't we have better ones?}
1487 @end flushright
1488
1489 @sp 1
1490 @noindent
1491 You can indeed. @code{sml-insert-form} is extensible so all you need to
1492 do is create the macros yourself. Define a @emph{keybord macro}
1493 (@kbd{C-x (} <something> @kbd{C-x )}) and give it a suitable name:
1494 @code{sml-addto-forms-alist} prompts for a name, say @code{NAME}, and
1495 binds the macro @code{sml-form-NAME}. Thereafter @kbd{C-c @key{RET}
1496 NAME} will insert the macro at point, and @kbd{C-u C-c @key{RET} NAME}
1497 will insert the macro after a @code{newline-and-indent}. If you want to
1498 keep your macros from one editing session to the next, go to your
1499 @file{.emacs} file and call @code{insert-kbd-macro}; you'll need
1500 to add @code{NAME} to @code{sml-forms-alist} permanently yourself:
1501
1502 @lisp
1503 (defun my-sml-load-hook () "Global defaults for SML mode"
1504 ;; whatever else you do
1505 (setq sml-forms-alist (cons '("NAME") sml-forms-alist)))
1506 @end lisp
1507
1508 If you want to create templates like `case' that prompt for parameters
1509 you'll have to do some Lisp programming. The @code{tempo} package looks
1510 like a good stating point. You can always overwrite your own macros, but
1511 the builtin forms for `let', etc., can't be overwritten.
1512
1513
1514 @node Indents, Multi ML, Forms, Advanced Topics
1515
1516 @sp 1
1517 @flushright
1518 @emph{I hate that indentation algorithm; can't I suppress it?}
1519 @end flushright
1520
1521 @sp 1
1522 @noindent
1523 Ah, yes, a common complaint. It's actually very easy to use SML mode
1524 without the troublesome @code{sml-indent-line}:
1525
1526 @lisp
1527 (defun my-sml-load-hook () "Global defaults for SML mode"
1528 ;; whatever else you do
1529 (fset 'sml-indent-line 'ignore))
1530 @end lisp
1531 @noindent
1532 though @code{indent-relative-maybe} may conceivable be more useful than
1533 @code{ignore}.
1534
1535
1536 @node Multi ML, Other ML, Indents, Advanced Topics
1537
1538 @sp 1
1539 @flushright
1540 @emph{Can SML mode handle more than one compiler running at once?}
1541 @end flushright
1542
1543 @findex sml-buffer
1544 @vindex sml-buffer
1545 @sp 1
1546 @noindent
1547 The question is whether you can! See the @code{sml-buffer} variable's
1548 on-line help (@kbd{C-h v sml-buffer}). Note that the SML mode
1549 compiler variables (@pxref{Process Defaults}) are all buffer-local, so
1550 you can even switch between different ML compilers, not just different
1551 invocations of the same one. Well, you @emph{can}.
1552
1553
1554
1555 @node Other ML, , Multi ML, Advanced Topics
1556
1557 @sp 1
1558 @flushright
1559 @emph{What needs to be done to support other ML compilers?}
1560 @end flushright
1561
1562 @sp 1
1563 @noindent
1564 Not that much really, at least not to create minimal support. The
1565 interface between SML mode and the compiler is determined by the
1566 variables
1567 @code{sml-use-command},
1568 @code{sml-cd-command},
1569 @code{sml-prompt-regexp}
1570 (which are easy to get right), and
1571 @code{sml-error-regexp}, and
1572 @code{sml-error-parser} (which are more tricky).
1573 The general template to follow in setting this up
1574 is in the files @file{sml-@{poly-ml,mosml@}.el}.
1575 These rules will not change, I hope:
1576
1577 @itemize @bullet
1578 @item
1579 @code{sml-next-error} uses @code{sml-error-regexp} to locate the start
1580 of the next error report in the ML interaction buffer (@var{P})
1581
1582 @item
1583 @code{sml-next-error} calls @code{sml-error-parser}, passing @var{P}, and
1584 expects up to five return values in this order:
1585
1586 @enumerate
1587 @item file name in which the error occurs (@var{F})
1588 @item start line of the error (@var{L} > 0)
1589 @item start column of the error (@var{C})
1590 @item an Emacs Lisp expression to be @code{eval}'d
1591 at (@var{L},@var{C}) in @var{F} (@var{EOE})
1592 @item the actual text of the one-line error report (@var{MSG})
1593 @end enumerate
1594
1595
1596 @item
1597 @code{sml-error-parser} can assume that @var{P} is the start of the next
1598 error message that the user is interested in---since she defines this
1599 point by defining @code{sml-error-regexp}.
1600
1601 @item
1602 What @code{sml-error-parser} returns is a list. In the event of problems,
1603 I foresee the following needs:
1604
1605 @itemize -
1606 @item if the file is the standard input,
1607 return @code{("std_in" @var{L} @var{C})}
1608 @item if the file cannot be inferred,
1609 return @code{(nil @var{L} @var{C})}
1610 @item if @var{L}=0, or the start cannot be inferred,
1611 return @code{(@var{F} nil @var{C})}
1612 @item if the start column cannot be inferred,
1613 return @code{(@var{F} @var{L} 1)}
1614 @end itemize
1615 @end itemize
1616
1617 There's no need to return anything else. However, if you do want the
1618 errorful text in @var{F} highlighted you should return a simple Lisp
1619 expression in the fourth argument that'll compute the region. @var{EOE}
1620 will be called with point at character (@var{L},@var{C}) in @var{F}, and
1621 should move point to the end of the errorful text. In fact, @var{EOE}
1622 can actually do anything you wish, but in the simplest cases it'll just
1623 @code{(forward-char 45)}, or
1624
1625 @lisp
1626 (progn (forward-line 4) (forward-char 37))
1627 @end lisp
1628 @noindent
1629 etc.. If it does more, make sure it leaves point at the end of the
1630 region in @var{F}---use @code{save-excursion} if switching buffers.
1631 @var{MSG}, if returned, will be echoed in the minibuffer.
1632
1633 @c ============================================================== CREDIT
1634
1635 @c H A C K A T T A C K O N
1636 @c page
1637 @c H A C K A T T A C K O F F
1638
1639 @node Credits, Command Index, Configuration, Top
1640
1641 @unnumbered Credit & Blame
1642
1643 @c == Credits, Command Index, Configuration, Top =======================
1644
1645 @noindent
1646 SML Mode was written originally by Lars Bo Nielsen for Emacs 18.5n;
1647 later hacked for comint by Olin Shivers (who called it @t{ml-mode});
1648 much later hacked by myself because it didn't seem to work@dots{} Fritz
1649 Knabe brilliantly posted the @code{hilit19} and @code{font-lock}
1650 functions on the net. Lars probably would recognise much of what
1651 remains, yet now there're menus, syntax highlighting, support for
1652 various ML compilers, Texinfo (hey!), and more than a little hope it'll
1653 work with a variety of Emacs 19s. But there are still things to do. Lars
1654 wrote:
1655 @quotation
1656 @emph{The indentation algorithm still can be fooled. I don't know if it will
1657 ever be 100% right, as this means it will have to actually parse all of
1658 the buffer up to the actual line [@dots{}].}
1659 @end quotation
1660 @noindent
1661 This is still the main cause of grief; SML's syntax is a nightmare for
1662 Emacs modes, and of course opinions vary about proper indentation. But
1663 there may be something we can do@dots{}
1664
1665 @c ======================================================= COMMAND INDEX
1666
1667 @headings singleafter
1668
1669 @node Command Index, Variable Index, Credits, Top
1670
1671 @unnumbered Command Index
1672
1673 @c == Command Index, Variable Index, Credits, Top ======================
1674
1675 @printindex fn
1676
1677 @c ====================================================== VARIABLE INDEX
1678
1679 @c node Variable Index, , Command Index, Top
1680 @node Variable Index, Key Index, Command Index, Top
1681
1682 @unnumbered Variable Index
1683
1684 @c == Variable Index, Key Index, Command Index, Top ====================
1685
1686 @printindex vr
1687
1688 @c =========================================================== KEY INDEX
1689
1690 @node Key Index, , Variable Index, Top
1691
1692 @unnumbered Key Index
1693
1694 @c == Key Index, , Variable Index, Top =================================
1695
1696 @printindex ky
1697
1698 @contents
1699 @bye