[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Editing with SML Mode

Now SML mode provides just a few additional editing commands. Most of the work has gone into implementing the indentation algorithm which, if you think about it, has to be complicated for a language like ML. See section Indentation Defaults, for details on how to control some of the behaviour of the indentation algorithm. Principal goodies are the `electric pipe' feature, and the ability to insert common SML forms (macros or templates).

4.1 On entering SML mode  
4.2 Automatic indentation  Prettying SML text
4.3 Electric features  Templates and electric keys
4.4 Indentation defaults  Variables controlling indentation

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 On entering SML mode

Command: sml-mode
This switches a buffer into SML mode. This is a major mode in Emacs. To get out of SML mode the buffer's major mode must be set to something else, like text-mode. See section 3.2 Getting started, for details on how to set this up automatically when visiting an SML file.

Emacs is all hooks of course. A hook is a variable: if the variable is non-nil it binds a list of Emacs Lisp functions to be run in some order (usually left to right). You can customise SML mode with these hooks:

Hook: sml-mode-hook
Default: nil

This is run every time a new SML mode buffer is created (or if you type M-x sml-mode). This is one place to put your preferred key bindings. See section 6. Configuration Summary, for some examples.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 Automatic indentation

ML is a complicated language to parse, let alone compile. The indentation algorithm is a little wooden (for some tastes), and the best advice is not to fight it! There are several variables that can be adjusted to control the indentation algorithm (see section Customising SML Mode, below).

Command: indent-for-tab-command
Key: TAB

This command indents the current line. If you set the indentation of the previous line by hand, indent-for-tab-command will indent relative to this setting.

Command: indent-region
Key: C-M-\

Indent the current region. Be patient if the region is large (like the whole buffer).

Command: sml-back-to-outer-indent
Key: M-TAB

Unindents the line to the next outer level of indentation.

Further indentation commands that Emacs provides (generically, for all modes) that you may like to recall:

As with other language modes, M-; gives you a comment at the end of the current line. The column where the comment starts is determined by the variable comment-column---default is 40, but it can be changed with set-comment-column (on C-x ; by default).

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 Electric features

Electric keys are generally pretty irritating, so those provided by SML mode are fairly muted. The only truly electric key is ;, and this has to be enabled to take effect.

Command: sml-electric-pipe
Key: M-|

When the point is in a `case' statement this opens a new line, indents and inserts | => leaving point just before the double arrow; if the enclosing construct is a `fun' declaration, the newline is indented and the function name copied at the appropriate column. Generally, try it whenever a | is wanted--you'll like it!

Command: sml-electric-space
Key: M-SPC

When the point is after a keyword like `let', this inserts the corresponding predefined skeleton if one exists. Else it just inserts a space. Another way to insert those skeletons is to use sml-insert-form, described below.

Command: sml-electric-semi
Key: ;

Just inserts a semi-colon, usually. The behaviour of this command is governed by the variable sml-electric-semi-mode.

Variable: sml-electric-semi-mode
Default: nil

If this variable is nil, sml-electric-semi just inserts a semi-colon, otherwise it inserts a semi-colon and a newline, and indents the newline for SML.

Command: sml-insert-form
Key: C-c RET

Interactive short-cut to insert common ML forms (a.k.a. macros, or templates). Recognised forms are `let', `local', `case', `abstype', `datatype', `signature', `structure', and `functor'. Except for `let' and `local', these will prompt for appropriate parameters like functor name and signature, etc.. This command prompts in the mini-buffer, with completion.

By default C-c RET will insert at point, with the indentation of the current column; if you give a prefix argument (i.e., C-u C-c RET) the command will insert a newline first, indent, and then insert the template.

sml-insert-form is also extensible: see 6. Configuration Summary for further details.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 Indentation defaults

Several variables try to control the indentation algorithm and other features of SML mode. Most of them are still in flux so they are not described here yet. If the default values are not acceptable you can set these variables permanently in your `.emacs' file. See section 6. Configuration Summary, for details and examples.

Variable: sml-indent-level
Default: 4

This variable controls the block indentation level.

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on October, 2 2007 using texi2html