Magma mode for emacs

A useful mode for emacs to edit MAGMA code. In addition to syntactic coloration and indentation, it features an interactive buffer to evaluate your code on the fly. Several magma sessions can be launched at the same time. This feature is described in this section.

Download: magma-mode.el

This mode was written from scratch and may contain some bugs. Feel free to send me suggestions, bug reports, patches or insults.
To use the magma mode, copy this file in the .emacs.d directory in your home directory, and just add these few lines in your .emacs file:

(load "~/.emacs.d/magma-mode.el")
(setq auto-mode-alist (append '(("\\.mgm$\\|\\.m$" . magma-mode)) auto-mode-alist))

The second line allows emacs to automatically activate the magma-mode when editing files with extensions .m or .mgm. To activate the magma mode anyway, you can run it with M-x magma-mode.

Magma mode variables

There are several parameters that you can tweak. You can modify them in your .emacs file.
The syntax is (setq variable-name value).

Variable name Default value Description
magma-interactive-program "magma" The name of the magma program to be launched in the interactive buffer. If magma is in you PATH, the default should be OK, else you can change it to the full path to your magma program.
magma-interactive-buffer-name "magma" Will be surrounded by `*' to make the interactive buffer name. Change it if you want your interactive buffer to be called differently. For multiple interactive buffers, the name is extended with -i where i is the number of the interactive buffer.
magma-indent-level 4 Space for indentation.
magma-electric-level 1 0 means no electric features,
1 allows auto indentation when typing a semi-colon,
2 includes 1 and adds automatic closing of < ( [ {.

Magma mode keymap

Usual emacs commands to move in a magma program are provided (M-a, M-e, C-M-a, C-M-e). The following table shows the interactive functions available in Magma mode. For MapleV mode users, some alternative bindings are also provided. However, we recommend the user to use the Magma bindings (left-most column).

Command Alternative Description
C-c o Switches to the magma interactive buffer. If the magma interactive buffer is not opened, opens it in a new frame. This command will probably be the first one you want to type.
C-c C-o C-c C-c g Opens the magma interactive buffer in a new window (rather than in a new frame like with `C-c o'). This may be more suitable for users who do not use emacs under X.
C-c C-e Evaluates the current expression/selected region in the interactive buffer and go to the beginning of the next expression/end of the selected region. Typically the most used command.
C-c C-b C-c C-c b Evaluates the whole buffer in the interactive buffer.
C-c C-r C-c C-c r Evaluates the selected region in the interactive buffer and go to the end of the selected region.
C-c C-u Evaluates the whole buffer until the current point.
C-c C-f C-c C-c p Evaluates the current function in the interactive buffer and go to the end of the function definition. Does not work outside a function.
C-c C-p Evaluates the current paragraph in the interactive buffer and go to the end of the paragraph. That is a block of code separated by 2 blank lines. If outside a block, evaluates the next one.
C-c C-w Evaluates the current word in the interactive buffer (shows signatures for intrinsics, values for variables).
C-c C-l C-c C-c RET Evaluates the current line in the interactive buffer.
C-c C-h C-? Displays Magma help for a prompted topic in a buffer named after the `magma-interactive-buffer-name' with the suffix -help (e.g. *magma-help*). Default topic is the current word. If an optional prefix argument is given, (e.g. C-u C-c C-h) the help is shown in the default web browser.
C-c C-i C-c C-c i Interrupts the current magma session. Useful to stop long computations.
C-c C-k C-c C-c k Kills the current magma session. Useful to kill frozen sessions.
C-c C-a Restarts the magma session in the interactive buffer.

Multiple magma sessions

You can run several magma sessions in multiple buffers. The newly created buffers are named after the `magma-interactive-buffer-name' with an added suffix -n where n is the number of the buffer. For example, a buffer called *magma-1* can be created. To run a command on a specific buffer, the command has to be prefixed with a numeric argument.
For instance, to evaluate an expression in buffer number 3 :
C-u 3 C-c C-e
To switch to the buffer number 8 in the same frame:
C-u 8 C-c C-o

The default (no prefix argument) is the buffer 0. You can change this default with C-c C-n, the number of the new default buffer will be asked.

The multiple sessions feature includes also the possibility to "broadcast" an evaluation/kill/interrupt command to all active buffers, that is all the magma interactive buffers that were explicitly opened with one of the previous command. All the commands are the same with a C-c C-x instead of C-c.
For instance, to evaluate the whole buffer in all active magma interactive buffers:
C-c C-x C-b
To kill all the active magma interactive buffers:
C-c C-x C-k

Back