# GNU emacs support

SRC Modula-3 comes with a mode for editing Modula-3 programs under `gnuemacs`. Here is a list of the main features this mode provides:

- Indenting/pretty-printing

  Modula-3 mode provides two methods of formatting code, one ``batch'' and one ``interactive.'' The batch method invokes the program `m3pp`, which takes a program unit such as a procedure and formats it completely. The `gnuemacs` commands (and their keyboard shortcuts) that invoke `m3pp` are:

  `M-x m3::pp-buffer` (C-c b)
    Pretty prints the current buffer.

  `M-x m3::pp-region` (C-c r)
    Pretty-prints the code between mark and point.

  `M-x m3::pp-unit` (C-c u)
    Pretty-prints the ``unit'' containing the cursor. (A unit is a top-level construct such as `CONST`, `TYPE`, `VAR`, or `PROCEDURE`.)

  The other method of formatting text is a more traditional one for `gnuemacs`, in which the language mode provides a key that indents the current line appropriately. In keeping with the convention used in modes for other languages such as Lisp and C, the key used is `TAB`. Typing `TAB` on a line indents the current line in a way that is (we hope) appropriate given the lines that precede it.

  The two formatting methods are not mutually exclusive; perhaps you like the way `m3pp` lines up columns in declarations, but you also like to keep things indented while you type. You can use the electric mode to get things close, then invoke `m3pp` when you're done.

- Avoidance of typing

  Modula-3 mode offers some aid if you don't like typing a lot of uppercase keywords. The `TAB` actually serves double duty; it not only indents the current line, but when invoked at the end of a word, it attempts to complete the current word as a keyword. For example `b TAB` expands the `b` to `BEGIN`, provided the `b` appears in a context where `BEGIN` may be a valid keyword. There are some fairly extensive rules governing the contexts in which a given keyword is a valid completion; the net result is that it is seldom necessary to type more than one letter to get the correct completion. If you specify a non-unique prefix of a set of keywords, it chooses the first in an ordering intended to capture frequency of use; it also presents the other choices, and typing `TAB` repeatedly cycles through these choices.

  A pair of related features are ```END`-completion'' and ```END`-matching.'' If the elisp variable `m3::electric-end` is set to `'all`, completing the keyword `END` has the additional effect of finding the construct that the `END` completes. If that construct is a an interface, module, or procedure, it fills in the name of the completed construct after the `END`; otherwise, it inserts a comment containing the keyword of the completed construct. If `m3::electric-end` is `'proc-mod`, it only fills in real names, never keyword comments. Independently, a non-`nil` value of the elisp variable `m3::blink-end-matchers` causes completion of `END` to blink the cursor briefly at the beginning of the completed construct.

- Finding files

  The key `C-c i` is bound to `m3::show-interface`, which expects the point to be in an interface name, and attempts to find that interface and display it in another window. It uses a built-in list of directories. The default value of this list is the one used at SRC; other sites will probably need to modify this.

  The key `C-c m` is bound to `m3::show-implementation`. This attempts to find the module that implements the interface in the current buffer. As distributed, this function relies on SRC-specific conventions. Obviously, this may not work outside of SRC, and `m3::show-implementation` may need to be re-implemented or abandoned.

To have the Modula-3 mode automatically invoked when visiting a Modula-3 source file, you should put in your `.emacs`:

        (autoload 'modula-3-mode "modula3")
        (setq auto-mode-alist
             (append '(("\\.ig$" . modula-3-mode)
                       ("\\.mg$" . modula-3-mode)
                       ("\\.i3$" . modula-3-mode)
                       ("\\.m3$" . modula-3-mode))
                       auto-mode-alist))

It is also convenient to have the lines:

        (setq completion-ignored-extensions
           (append '(".mo" ".mx" ".mc" ".io" ".ix") completion-ignored-extensions))

so that you don't get the files with those extensions offered as possible completions.

Your system administrator may have inserted these lines in the default macro files for your system.

## Tags

There is also a program to build tags file for Modula-3 programs: `m3tags`; see the manpage for the details. When the system is installed, a tag file for the public interfaces is built. To access it, you need in your `.emacs` (or in the system initialization file) the line:

        (visit-tags-table "LIB_USE/FTAGS")

where `LIB_USE` is the place where the Modula-3 libraries have been installed.

    Last modified on Mon Jul 22 12:51:08 PDT 1996 by heydon
         modified on Fri Apr 22 11:35:32 PDT 1994 by kalsow
         modified on Thu Jan  7 18:40:57 PST 1993 by muller