The Emacs mode
mma.el is a major programming mode for GNU Emacs and
XEmacs for writing Mathematica package files (
.m-files). It provides:
- a basic indentation machine
- font-lock support
- function-menu support for XEmacs
- imenu support for GNU Emacs
- some simple functions for activating/deactivating mathematica debug code For a more detailed description of the indentation machine and the debug code feature see below.
The source code of
mma.el you will find here. The current
mma.el is 1.32.
If you want to be informed about new
mma.el or if you have any suggestions, just send me an
It works with GNU Emacs 20.4 or later and XEmacs 20.4 or later. It was tested on GNU Emacs 20.4, XEmacs 20.4, and XEmacs 21.3.
To use the mma-mode you should add the following to your local
(autoload 'mma-mode "mma.el" "Mathematica package file mode" t) (setq auto-mode-alist (cons '("\.m\'" . mma-mode) auto-mode-alist))
This automatically turns on mma-mode for files with the suffix
loading. To start the mode by hand simply type
For a full description of its features see the documentation strings
(especially of the function
mma-mode), the comments in the source
file, and the customization group
The indentation machine works as follows:
If point is on the leading whitespace of the current line, indents as far as the preceding non-empty line and moves point to the first non-whitespace character of the line.
If point is not on the leading whitespace of the current line, indents
by steps of
If called with prefix argument, aligns rest of current line with the
next whitespace character position in previous lines (point is denoted
---------- Buffer: foo.m ---------- MyOptionName -> MyValue Another-!--> Value ---------- Buffer: foo.m ----------
Calling with prefix argument yields:
---------- Buffer: foo.m ---------- MyOptionName -> MyValue Another -!--> Value ---------- Buffer: foo.m ----------
(Difficult to explain. Just try it and see the result.)
If called with negative prefix argument, aligns with whitespace in following lines.
mma-indent-align-at-eolp specifies if
indents by steps of
mma-indentation (value is
nil) or aligns to
whitespace (value is non-
nil) if point is at the end of line.
Activating/Deactivating debug code:
Since Mathematica does not provide a source code debugger, I often find myself writing pieces of code like
Print[ "value1= ", somevariable ];
when I am debugging my Mathematica functions, removing them as soon as the bug is fixed - and inserting them back on if another bug occurs. To simplify this procedure you can mark debug code with a special marker comment like this
(*: DEBUG MyFunction :*) Print[ "value1= ", somvevariable ]; (*: ENDDEBUG :*)
(Use the function
mma-debug-insert to insert a debug code
skeleton). Each debug code has a marker, in the above example it is
“MyFunction”. The functions
activate or deactivate your debug code. Both take a regexp as argument
and act only on debug code which marker matches the regexp. Thus,
(mma-debug-off "MyFun.*") would turn off the above debug code (i.e.,
it inserts additional comments surrounding the
(mma-debug-on ".*") turns on all debug code. The variable
mma-debug-fontify determines whether to re-fontify the buffer after
a change to the debug code.
Customizing the variables
mma-debug-end you can change the special markers for you
Note: Mathematica is a registered trademark of Wolfram Research, Inc.