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

(In the above, M-x means hold down the meta/alt/option modifier key, and then press x. You can also type Esc and then x. And RET is the Return key.)

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

SML-MODE installed using Emacs's package manager, MELPA. If you haven't already added

  (require 'package)
  (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  (package-initialize)

to your .emacs customization file (located in your home directory (create it if it doesn't exist)), you should do so. (Everytime you update .emacs, you should then exit and restart Emacs.)

Then run the following commands within Emacs,

  M-x package-refresh-contents RET

followed by

  M-x package-install RET sml-mode RET

Alley Stoughton (Alley.Stoughton@gmail.com)