Emacs Support for SML


The Emacs Text Editor

Emacs is an extensible, customizable, self-documenting display editor. Among its many features, it has special modes ("major modes") for editing and running programs of various languages. In particular, there is a major mode, SML-MODE, that provides support for editing and running SML programs.

Emacs is included in macOS, and will almost certainly be installed on Linux systems. It can also be installed on Windows machines. Information about installing Emacs is included below.

Introduction to SML-MODE

To run sml (or smlcus — see below) as a child process of Emacs, one types

  META-x run-sml RET

Editing a source file whose name ends with .sml (or .sig) causes Emacs to enter the major mode SML-MODE, at which point typing

  CTRL-h m

(or META-x describe-mode RET) will cause a summary of the mode to be printed. One can send the contents of the source file to sml by typing

  CTRL-c CTRL-b

If sml reports that the source file contains errors, then typing

  CTRL-x `

will cause the cursor of the sml buffer to be positioned at the first error message, and cause the cursor of the source file to be placed at the location of the error itself. The next error can then be examined by typing CTRL-x ` again, and so on.

If you want SML-MODE to run smlcus instead of sml, include the following line in your .emacs file:

  (setq sml-program-name "smlcus")

You'll have to exit and re-enter Emacs for the above change to take effect.

Further information on SML-MODE is available via Emacs's info function (type META-x info RET m smlRET).

Installing Emacs

Installing Emacs on Linux

In the unlikely case that Emacs isn't already installed on a Linux machine, it can be obtained from www.gnu.org/software/emacs/emacs.html.

Installing Emacs on macOS

The version of Emacs that's distributed with macOS can only be run within a terminal. Instead, you will probably want to install Emacs for macOS.

Installing Emacs on Windows

Emacs will have to be installed on Windows machines. Information about the Windows version of Emacs, including instructions for obtaining and installing Emacs on Windows, can be found at www.gnu.org/software/emacs/windows/ntemacs.html.

Installing SML-MODE

The SML-MODE distribution is available as a compressed tarball, as a zip archive and as a directory.

Installing SML-MODE on Linux

See the file INSTALL for instructions on installing SML-MODE on a machine running Linux, making use of the supplied makefile, and running as root. The makefile will byte-compile the .el files, producing .elc files. The .el and .elc files will go in your site-lisp directory, which will be called something like /usr/share/emacs/site-lisp. Then put the line

  (load "sml-mode-startup")
in your .emacs file. The Info file sml-mode.info will be put by the makefile in the Info directory, which will be something like /usr/share/info. The makefile will add a link to this file to the Info top-level node, using the command (modify the directory as needed)

  install-info --info-file=sml-mode.info --info-dir=/usr/share/info

Installing SML-MODE on macOS

The procedure for installing SML-MODE on macOS is very similar to that one for Linux. The difference is that, assuming you've installed Emacs.app, the site-lisp directory will be called

  /Applications/Emacs.app/Contents/Resources/site-lisp

and the info directory will be called

  /Applications/Emacs.app/Contents/Resources/info

and so the makefile will have to be modified to use these directories. (When the makefile byte-compiles .el files, it will use the terminal version of Emacs. You can also install SML-MODE for that terminal version.)

Installing SML-MODE on Windows

On a Windows machine, you'll have to install the mode by hand, working by analogy with the installation under Linux. Byte-compile the .el files using the Emacs function byte-compile-file. The .el and .elc files will go in your site-lisp directory, which will be called something like c:\emacs\site-lisp, and the line

  (load "sml-mode-startup")

should be placed in your .emacs file. The Info file sml-mode.info should be put in the Info directory, which will be called something like c:\emacs\info. You should edit the file dir of the Info directory so that it includes a pointer to sml-mode.info.


Alley Stoughton (Alley.Stoughton@gmail.com)