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

5. Running ML under Emacs

The most useful feature of SML mode is that it provides a convenient interface to the compiler. How serious users of ML put up with a teletype interface to the compiler is beyond me... but perhaps there are other interfaces to compilers that require one to part with serious money. Such remarks can quickly become dated--in this case, let's hope so!

Anyway, SML mode provides an interaction mode, inferior-sml-mode, where the compiler runs in a separate buffer in a window or frame of its own. You can use this buffer just like a terminal, but it's usually more convenient to mark some text in the SML mode buffer and have Emacs communicate with the sub-process. The features discussed below are syntax-independent, so they should work with a wide range of ML-like tools and compilers. See section 5.4 Process defaults, for some hints.

inferior-sml-mode is a specialisation of the `comint' package that comes with Emacs and XEmacs.

5.1 Starting the compiler  Commands to run the ML compiler in a buffer
5.2 Speaking to the compiler  Sending program fragments to the compiler
5.3 Finding errors  Finding reported syntax errors
5.4 Process defaults  Setting defaults for process interaction


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

5.1 Starting the compiler

Start your favourite ML compiler with the command

 
M-x run-sml

This creates a process interaction buffer that inherits some key bindings from SML mode and from `comint' (see section `Shell Mode' in The Emacs Editor Manual). Starting the ML compiler adds some functions to SML mode buffers so that program text can be communicated between editor and compiler (see section 5.2 Speaking to the compiler).

The name of the ML compiler is the first thing you should know how to specify:

Variable: sml-program-name
Default: "sml"

The program to run as ML. You might need to specify the full path name of the program.

Variable: sml-default-arg
Default: ""

Useful for Poly/ML users who may supply a database file, or others who have wrappers for setting various options around the command to run the compiler. Moscow ML people might set this to "-P full", etc..

The variable sml-program-name is a string holding the name of the program as you would type it at the shell. You can always choose a program different to the default by invoking

 
C-u M-x run-sml

With the prefix argument Emacs will prompt for the command name and any command line arguments to pass to the compiler. Thereafter Emacs will use this new name as the default, but for a permanent change you should set this in your `.emacs' with, e.g.:

 
(setq sml-program-name "nj-sml")

Command: run-sml
Launches ML as an inferior process in another buffer; if an ML process already exists, just switch to the process buffer. A prefix argument allows you to edit the command line to specify the program, and any command line options.

Hook: inferior-sml-mode-hook
Default: nil

M-x run-sml runs comint-mode-hook and inferior-sml-mode-hook hooks in that order, but after the compiler is started. Use inferior-sml-mode-hook to set any comint buffer-local configurations for SML mode you like.

Command: switch-to-sml
Key: C-c C-s

Switch from the SML buffer to the interaction buffer. By default point will be placed at the end of the process buffer, but a prefix argument will leave point wherever it was before. If you try C-c C-s before an ML process has been started, you'll just get an error message to the effect that there's no current process buffer.

Command: sml-cd
When started, the ML compiler's default working directory is the current buffer's default directory. This command allows the working directory to be changed, if the compiler can do this. The variable sml-cd-command specifies the compiler command to invoke (see section 5.4 Process defaults).


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

5.2 Speaking to the compiler

Several commands are defined for sending program fragments to the running compiler. Each of the following commands takes a prefix argument that will switch the input focus to the process buffer afterwards (leaving point at the end of the buffer):

Command: sml-load-file
Key: C-c C-l

Send a `use file' command to the current ML process. The variable sml-use-command is used to define the correct template for the command to invoke (see section 5.4 Process defaults). The default file is the file associated with the current buffer, or the last file loaded if you are in the interaction buffer.

Command: sml-send-region
Key: C-c C-r

Send the current region of text in the SML buffer. sml-send-region-and-go is a similar command for you to bind in SML mode if you wish: it'll send the region and then switch-to-sml.

Command: sml-send-buffer
Key: C-c C-b

Send the contents of the current buffer to ML.


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

5.3 Finding errors

SML mode provides one customisable function for locating the source position of errors reported by the compiler. This should work whether you type use "puzzle.sml"; into the interaction buffer, or use one of the mechanisms provided for sending programs directly to the compiler---see section 5.2 Speaking to the compiler.

Command: next-error
Key: C-x`

Jump to the source location of the next error reported by the compiler. All the usual error-navigation commands are available, see see section `Compilation Mode' in The Emacs Editor Manual.


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

5.4 Process defaults

The process interaction code is independent of the compiler used, deliberately, so SML mode will work with a variety of ML compilers and ML-based tools. There are therefore a number of variables that may need to be set correctly before SML mode can speak to the compiler. Things are by default set up for Standard ML of New Jersey, but switching to a new system is quite easy.

Variable: sml-use-command
Default: "use \"%s\""

Use file command template. Emacs will replace the %s with a file name. Note that Emacs requires double quote characters inside strings to be quoted with a backslash.

Variable: sml-cd-command
Default: "OS.FileSys.chDir \"%s\""

Compiler command to change the working directory. Not all ML systems support this feature (well, Edinburgh (core) ML didn't), but they should.

Variable: sml-prompt-regexp
Default: "^[-=>#] *"

Matches the ML compiler's prompt: `comint' uses this for various purposes.

To customise error reportage for different ML compilers you need to set two further variables before next-error can be useful:

Variable: sml-error-regexp-alist

Alist that specifies how to match errors in compiler output. Each elt has the form (REGEXP FILE-IDX LINE-IDX [COLUMN-IDX FILE-FORMAT...]) If REGEXP matches, the FILE-IDX'th subexpression gives the file name, and the LINE-IDX'th subexpression gives the line number. If COLUMN-IDX is given, the COLUMN-IDX'th subexpression gives the column number on that line. If any FILE-FORMAT is given, each is a format string to produce a file name to try; %s in the string is replaced by the text matching the FILE-IDX'th subexpression.


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

This document was generated by XEmacs shared group account on December, 19 2009 using texi2html 1.65.