next up previous contents
Next: 10 A Typical Session Up: Elf Users Guide Previous: 8 Elf Server Shell

9 Elf Server Emacs Command Summary

The Emacs interface to Elf provides support for

We recommend the use of XEmacs, but most features (with the exception of font-lock mode) should also work in FSF Gnu-Emacs, Versions 19.xx. The Emacs code is relatively well documented, and you can use standard help functions such as C-h m (to get help on the current major mode) or C-h f <function> (to get help on an individual function), or simply browse through the sources.

To use the Elf mode effectively, put into your .emacs file:

(setq load-path (cons "/afs/cs/user/fp/courses/comp-ded/lib/emacs" load-path))

(autoload 'elf-mode "elf-menus" "Major mode for editing Elf source." t)
(autoload 'elf-server "elf-menus" "Run an inferior Elf server." t)
(autoload 'elfsml "elf-menus" "Run an inferior ElfSML process." t)

(setq auto-mode-alist
      (cons '("\\ .elf$" . elf-mode)
            (cons '("\\ .quy$" . elf-mode)
                  auto-mode-alist)))

(setq elf-server-program "/afs/cs/user/fp/courses/comp-ded/bin/elf-server")
(setq elfsml-program "/afs/cs/user/fp/courses/comp-ded/bin/elfsml")

The documentation below was generated with C-h m while in Elf mode in Emacs. My apologies for the long verbatim environment, but it is difficult to keep this information updated and consistent.

Elf Mode:
Major mode for editing Elf code.
Tab indents for Elf code.
Delete converts tabs to spaces as it moves back.
M-C-q indents all lines in current Elf paragraph (declaration or query).

Elf mode also provides commands to maintain groups of Elf source files
(configurations) and communicate with an Elf server which type-checks or
executes declarations or queries.  It also supports quick jumps to the
(presumed) source of error message that may arise during parsing or
type-checking.

Customisation: Entry to this mode runs the hooks on elf-mode-hook.
See also the hints for the .emacs file given below.

Mode map
========

TAB             elf-indent-line
DEL             backward-delete-char-untabify
button3         elf-menu
C-c             Prefix Command
C-i             elf-indent-line
M-C-q           elf-indent-paragraph

C-c TAB         elf-server-interrupt
C-c LFD         elf-server-send-newline
C-c .           elf-complete
C-c ;           elf-server-send-semicolon
C-c =           elf-goto-error
C-c ?           elf-completions-at-point
C-c `           elf-next-error
C-c c           elf-type-const
C-c e           elf-expected-type-at-point
C-c p           elf-type-at-point
C-c q           tags-query-replace
C-c s           tags-search
C-c C-c         elf-save-check-config
C-c C-d         elf-check-declaration
C-c C-e         elf-solve-query
C-c C-i         elf-server-interrupt
C-c C-j         elf-server-send-newline
C-c C-q         elf-check-query
C-c C-s         elf-save-check-file


Overview
========

The basic architecture is that Emacs sends commands to an Elf server which
runs as an inferior process, usually in the buffer *elf-server*.  Emacs in
turn interprets or displays the replies from the Elf server.  Since a typical
Elf application comprises several files, Emacs maintains a configuration
in a file, usally called CONFIG.  This file contains declarations of the form
  -static FILENAME
  -dynamic FILENAME
  -query FILENAME
for static, dynamic, and query files, respectively.  The declarations
must be in dependency order.  A configuration is established with the
command M-x elf-server-configure.

When a new file is switched to Elf mode (typically done automatically if a
file has extension `.elf' or `.quy' and the `auto-mode-alist' is set correctly
(see below)), the user is asked whether to add the new file to the current
configuration.  The CONFIG file will be updated automatically if necessary.

The files in the current configuration can be checked in sequence with
C-c C-c, queries can be sent with C-c C-e.  An optional prefix argument
specifies how many solutions to search for, 0 means ask interactively, and -1
to find all.  If a type error should arise during these or related operations,
the command C-c ` visits the presumed source of the type error in a separate
buffer.

Summary of most common commands:
 M-x elf-server                     start Elf server
 M-x elf-server-configure           configure Elf server from CONFIG file
 M-x elf-save-check-config C-c C-c  save, check & load configuration
 M-x elf-save-check-file   C-c C-s  save, check & load current file
 M-x elf-check-declaration C-c C-d  type-check declaration at point
 M-x elf-solve-query       C-c C-e  execute query at point
 M-x elf-server-display    M-x elf-server-display  display Elf server buffer
 M-x elf-tag                        create TAGS file of current configuration

There are a number of commands to check declarations or obtain type
information from the Elf server.  However, the only commands that actually
change the global signature consulted by the type checker are the file-level
commands `elf-check-config', `elf-save-check-config'(C-c C-c), and
`elf-save-check-file'(C-c C-s).  Thus, it will occasionally be necessary to
call one of these commands (typically C-c C-s) to make new declarations
available to subsequent declarations in the same file.  Since the Elf syntax
does not distinguish between declarations and queries, Emacs assumes the
current paragraph is a declaration unless the Query minor mode has been
switched on (see `elf-query-mode').

Individual Commands
===================

Configurations, Declarations, and Queries

  elf-save-check-config                   C-c C-c
   Save its modified buffers and then check the current Elf configuration.
   With prefix argument also displays Elf server buffer.
   If necessary, this will start up an Elf server process.

  elf-save-check-file                     C-c C-s
   Save buffer and then check it by giving a command to the Elf server.
   With prefix argument also displays Elf server buffer.

  elf-check-declaration                   C-c C-d
   Send the current declaration to the Elf server process for checking.
   With prefix argument, subsequently display Elf server buffer.

  elf-check-query                         C-c C-q
   Send the current query to the Elf server process for type-checking.
   Note that this will not execute the query (see function elf-solve-query).
   With prefix argument also display Elf server buffer.

  elf-solve-query                         C-c C-e
   Send the current query to the Elf server process to be solved.
   Variable `elf-solve-default' determines how many solutions to search for
   (default: 1).  An optional prefix argument overrides this variable: 0 means
   to wait after each solution (as in Prolog's top level), -1 means to find
   all solutions.  You can ask for more solutions with C-c ;
   or return to the server's command interpreter with C-c LFD.

Subterm at Point

  elf-type-at-point                       C-c p
   Display the type of the subterm at point in the current Elf paragraph.

   The subterm at point is the smallest subterm whose printed representation
   begins to the left of point and extends up to or beyond point.  After this
   and similar commands applicable to subterms, the current region (between
   mark and point) is set to encompass precisely the selected subterm.  In
   XEmacs, it will thus be highlighted under many circumstances.  In other
   versions of Emacs C-x C-x will indicate the extent of
   the region.

   The type computed for the subterm at point takes contextual information
   into account.  For example, if the subterm at point is a constant with
   implicit arguments, the type displayed will be the instance of the constant
   (unlike M-x elf-type-const (C-c c), which yields the absolute
   type of a constant).

  elf-expected-type-at-point              C-c e
   Display the type expected at the point in the current declaration.

   This replaces the subterm at point by an underscore _ and determines the
   type that _ would have to have for the whole declaration to be valid.  This
   is useful for debugging in places where inconsistent type constraints have
   arisen.  Error messages may be given, but will not be correctly interpreted
   by Emacs, since the string sent to the server may be different from the
   declaration in the buffer.

  elf-type-const                          C-c c
   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.

  elf-completions-at-point                C-c ?
   List the possible completions of the term at point based on type
   information.

   The possible completions are numbered, and the function elf-complete
   (C-c .) can be used subsequently to replace the term at point
   with one of the alternatives.

   Above the display of the alternatives, the type of the subterm at
   point is shown, since it is this type which is the basis for listing
   the possible completions.

   In the list of alternatives, a variable X free in the remaining declaration
   is printed ^X, and a bound variable x may be printed as !x.  These marks
   are intended to aid in the understanding of the alternatives, but
   must be removed in case the alternative is copied literally into the
   input declaration (as, for example, after the C-c . command).

  elf-complete                            C-c .
   Pick the alternative N from among possible completions.
   This replaces the current region with the given pattern.  The list of
   completions must be generated with the command elf-completions-at-point
   (C-c ?).

Server State

  elf-server                              M-x elf-server
   Start an Elf server process in a buffer named *elf-server*.

  elf-server-interrupt                    C-c TAB
   Interrupt the Elf server-process.

  elf-server-quit                         M-x elf-server-quit
   Kill the Elf server process.

  elf-server-restart                      M-x elf-server-restart
   Restarts server and re-initializes configuration.
   This is primarily useful during debugging of the Elf server code or
   if the Elf server is hopelessly wedged.

Tags (for other, call C-h tag or see `etags' documentation)

  elf-tag                                 M-x elf-tag
   Create tags file TAGS for current configuration CONFIG.
   If current configuration is names CONFIGx, tags file will be named TAGx.
   Errors are displayed in the Elf server buffer.

Error Handling

  elf-next-error                          C-c `
   Find the next error by parsing the Elf server or ElfSML buffer.

  elf-goto-error                          C-c =
   Go to the error reported on the current line or below.

Server Parameters

  elf-chatter                             M-x elf-chatter
   Sets the level of chatter in the Elf server.  Default is 2.

  elf-trace                               M-x elf-trace
   Sets the level of tracing in the Elf server.  Default is 0 (no tracing).

Editing

  elf-indent-region                       M-x elf-indent-region
   Indent each line of the region as Elf code.

Minor Modes
===========

Associated minor modes are Query (usually switched on automatically
in query files, explicitly toggled with elf-query-mode) and 2ElfSML
(toggled with elf-to-elfsml-mode).

Related Major Modes
===================

Related major modes are Elf Server (for the Elf server buffer) and ElfSML (for
an inferior ElfSML process).  Both modes are based on the standard Emacs
comint package and inherit keybindings for retrieving preceding input.

Customization
=============

The following variables may be of general utility.

 elf-solve-default default number of solutions searched for
                   in C-c C-e; 0 means interactive, -1 means all.
                   Override with a prefix argument to C-c C-e.

 elf-indent        amount of indentation for nested Elf expressions

 elf-infix-regexp  matches infix operators that are treated special for
                   purposes of indentation

 elf-save-silently if non-nil, modified buffers in the current configuration
                   will be saved without confirmation during C-c C-c

 elf-server-program  full pathname of Elf server program
 elfsml-program      full pathname of ElfSML program

The following is a typical section of a .emacs initialization file.

; If elf.el lives in some non-standard directory, you must tell emacs
; where to get it. This may or may not be necessary.
(setq load-path (cons "/afs/cs/project/ergo/research/elf/emacs" load-path))

(autoload 'elf-mode "elf" "Major mode for editing Elf source." t)
(autoload 'elf-server "elf" "Run an inferior Elf server." t)
(autoload 'elfsml "elf" "Run an inferior ElfSML process." t)

(setq auto-mode-alist
      (cons '("\\ .elf$" . elf-mode)
            (cons '("\\ .quy$" . elf-mode)
                     auto-mode-alist)))

; The Elf server binary has an odd name or location
(setq elf-server-program "/afs/cs/project/ergo/research/elf/bin/elf-server")
(setq elfsml-program "/afs/cs/project/ergo/research/elf/bin/elfsml")

; Sample customization of key bindings for Elf mode
;(setq elf-mode-hook '((lambda ()
; (define-key elf-mode-map "\M-\t" 'comint-replace-by-expanded-filename)
; )))



fp@cs