The Twelf mode for Emacs provides some functions and utilities for
editing Twelf source and for interacting with an inferior Twelf server
process which can load configurations, files, and individual
declarations and track the source location of errors. It also provides
an interface to the tags package which allows simple editing of groups
of files, constant name completion, and locating of constant
declarations within the files of a configuration.

Note that in order to use the Emacs interface you need to include the
line

The Twelf mode in Emacs provides support for editing and indentation,
syntax highlighting (including colors) (see section 13.13 Syntax Highlighting),
and communication commands for interacting with a Twelf server running
as an inferior process to Emacs. It defines a menu which is added to
the menu bar, usually at the top of each Emacs frame.

Many commands apply to the current declaration, which is the declaration
in which we find the Emacs cursor (not the cursor of the window system).
If the cursor is between declarations, the declaration after point is
considered current. From the point of view of Emacs, single
declarations never include consecutive blank lines, which provides some
insulation against missing closing delimiters.

Normally, Twelf mode is entered automatically when a Twelf source file
is edited (see section 13.14 Emacs Initialization), but it can also be switched on or
off directly with M-x twelf-mode.

The Twelf mode provides simple commands which cause the server to load
or reload the current configuration, the file edited in the current
buffer, or just the declaration at point. Each of these command can be
preceded by a prefix argument (for example, C-u C-c C-c) which
will select the Twelf server buffer after completion of the command.
The Twelf server buffer can also be forced to be shown with the C-c
C-u Emacs command.

C-c C-c

M-x twelf-save-check-config

Save its modified buffers and then check the current Twelf configuration.
With prefix argument also displays Twelf server buffer.
If necessary, this will start up an Twelf server process.

C-c C-s

M-x twelf-save-check-file

Save buffer and then check it by giving a command to the Twelf server.
In Twelf Config minor mode, it reconfigures the server.
With prefix argument also displays Twelf server buffer.

C-c C-d

M-x twelf-check-declaration

Send the current declaration to the Twelf server process for checking.
With prefix argument also displays Twelf server buffer.

C-c c

M-x twelf-type-const

Display the type of the constant before point.
Note that the type of the constant will be `absolute' rather than the
type of the particular instance of the constant.

C-c C-u

M-x twelf-server-display

Display Twelf server buffer, moving to the end of output.
With prefix argument also selects the Twelf server buffer.

The Twelf Emacs mode provides a simple interface to the tracer.
While tracing or breakpoints are on, you should be in the
Emacs server buffer to type your input directly to the server
as described in section 11.5 Tracing and Breakpoints.

Error messages by the Twelf server are flagged with the filename and an
educated guess as to the source of the error (see section 4.6 Error Messages).
These can be interpreted by Emacs to jump directly to the suspected
site.

Sometimes, the server buffer and the the server itself believe to have
different working directories. In that case, error tracking may not be
able to find the file, and an explicit call to OS.chDir
or M-x cd in the server buffer may be required.

C-c `

M-x twelf-next-error

Find the next error by parsing the Twelf server or Twelf-SML buffer.
Move the error message on the top line of the window;
put the cursor at the beginning of the error source. If the
error message specifies a range, the mark is placed at the end.

C-c =

M-x twelf-goto-error

Go to the error reported on the current line or below.
Also updates the error cursor to the current line.

The server state consists of the current configuration and a number of
parameters described in section 12 Twelf Server. The current configuration
is often set implicitly, with the C-c C-c command in a
configuration buffer, but it can also be set explicitly.

C-c <

M-x twelf-set

Sets the Twelf parameter PARM to VALUE.
When called interactively, prompts for parameter and value, supporting
completion.

C-c >

M-x twelf-get

Prints the value of the Twelf parameter PARM.
When called interactively, prompts for parameter, supporting completion.

C-c C-i

M-x twelf-server-interrupt

Interrupt the Twelf server process.

M-x twelf-server

Start an Twelf server process in a buffer named *twelf-server*.
Any previously existing process is deleted after confirmation.
Optional argument PROGRAM defaults to the value of the variable
twelf-server-program.
This locally re-binds `twelf-server-timeout' to 15 secs.

M-x twelf-server-configure

Initializes the Twelf server configuration from CONFIG-FILE.
A configuration file is a list of relative file names in
dependency order. Lines starting with % are treated as comments.
Starts a Twelf servers if necessary.

M-x twelf-reset

Reset the global signature of Twelf maintained by the server.

M-x twelf-server-quit

Kill the Twelf server process.

M-x twelf-server-restart

Restarts server and re-initializes configuration.
This is primarily useful during debugging of the Twelf server code or
if the Twelf server is hopelessly wedged.

M-x twelf-server-send-command

Restarts server and re-initializes configuration.
This is primarily useful during debugging of the Twelf server code or
if the Twelf server is hopelessly wedged.

Tags files provide a convenient way to group files, such as
Twelf configurations. See the documentation for the Emacs etags
package for more information.

M-x twelf-tag

Create tags file for current configuration.
If the current configuration is sources.cfg, the tags file is TAGS.
If current configuration is named FILE.cfg, tags file will be named FILE.tag
Errors are displayed in the Twelf server buffer.

M-.

M-x find-tag TAG

Selects the buffer that the tag is contained in and puts point at
its definition.

C-x 4 .

M-x find-tag-other-window TAG

Selects the buffer that TAG is contained in in another window
and puts point at its definition.

C-c q

M-x tags-query-replace FROM TO

Query-replace-regexp FROM with TO through all files listed in tags table.

There is some support for interacting with Twelf, even when it is
run within ML, rather than as a stand-alone server. You can start
an SML in which you intend to run Twelf with M-x twelf-sml;
the buffer will then be in Twelf-SML mode.

If you intend to send command to a buffer running Twelf in SML (rather
than the Twelf server), you can switch to a minor mode 2Twelf-SML with
M-x twelf-to-twelf-sml.

M-x twelf-sml

Run an inferior Twelf-SML process in a buffer *twelf-sml*.
If there is a process already running in *twelf-sml*, just
switch to that buffer. With argument, allows you to change the program
which defaults to the value of twelf-sml-program. Runs the hooks from
twelf-sml-mode-hook (after the comint-mode-hook is run).

Twelf also provides syntax highlighting, which helps make Elf code more
readable. This highlighting can use different colors and faces.
Unfortunately, the necessary libraries are at present not standardized
between XEmacs and FSF Emacs, which means that highlighting support is
less general and less portable than the plain Twelf mode.

At present, highlighting has not been extensively tested in various
versions of Emacs, but the font-lock mode provided in
`emacs/twelf-font.el' seems to work at least in XEmacs version
19.16 and FSF Emacs version 19.34. The alternative highlight mode
provided in `emacs/twelf-hilit' appears to work in FSF Emacs 19.34.

Unlike other font-lock modes, Twelf's fontification is not `electric' in
that it does not fontify as one types. One has to explicitly issue a
command to fontify the current Twelf declaration or current buffer,
since single-line highlighting is too error-prone and multi-line
immediate highlighting is not well supported in current versions of font
lock mode.