To: mathgroup@yoda.ncsa.uiuc.edu
Subject: Math mode for GNU Emacs
Date: Tue, 17 Apr 90 10:59:20 PDT
From: jacobson@cello.hpl.hp.com
Associated file: math.el
Here is a GNU Emacs package for use with Mathematica.
Its main features are:
* Editing of multi-line "cells" before submission.
* Limited error checking before submission
* Copying of earlier cells by name or by pointing.
* Go to the point of an error in a .m file.
* On-line help
* Symbol completion
* Interrupts
Installation: Copy the stuff below the ======== line below to math.el in whatever directory you put emacs-lisp stuff in. (If you don't know, type go to the *scratch* buffer, type load-path C-u C-x C-e. If none of those directories are writable by you, ask an emacs expert to make you directory for your own private emacs stuff.)
Check the $Path variable of your version of Mathematica. Edit the Mathematica-search-path variable, which is set in the 3rd line beyond the legalese (or just make make sure it is set before loading this) to match. Use nil for the current working directory. Also make sure that the emacs variable math-process-string (just below Mathematica-search-path) reflects the location of Mathematica on your system.
When you want to use math-mode, first type M-x load-library RET math RET
After loading, type M-x math to start a copy of Mathematica. Edit an input cell using normal editing commands, the submit with ESC-RET.
If Mathematica detects a syntax error, it will be indicated with "^--error". Fix the error, cut out the "^--error", and resubmit.
You can complete Mathematica symbols, in both the working buffer and in other math-mode buffers, with ESC-TAB. Do not try this when Mathematica is busy or chaos will result.
You can get help on Mathematica symbols, in both the working buffer and in other math-mode buffers, with C-h e or C-h E (the latter is more verbose). Again, don't try this when Mathematica is busy. HP users, please note that C-h and DEL are usually reversed in most GNU Emacs installations.
You can copy cells to the end of the buffer with C-c C-y. It will ask for what cell you want in the minibuffer.
copies cell number
copies the previous In cell if the cursor is after the
last In[..], otherwise copies the cell the cursor is in.
This latter case will copy an In cell, an Out cell containing
no blank lines (especially useful with InputForm), or
just any block of text. This also works from any math-mode
buffer, but copies to the math process buffer (one
with an active Mathematica process--normally *math*, but
it be changed with set-math-process-buffer).
With a prefix arg, the option will back over incarnation boundaries of Mathematica. See the on-line help for math-copy-cell for more info.
C-c C-c interrupts Mathematica (as well is it can be interrupted).
When it gives you the prompt, type your response followed by ESC-RET.
C-c 9 is equivalent to kill -9 .
If you have read in a .m file with "<<", and have gotten a response of the form
": : syntax error in ..."
you can go directly to the point of the error by typing C-c C-e. This is very useful because the line numbers are almost always wrong. This function counts lines the way Mathematica does. (There are reports of this not working with older versions of Emacs.)
C-h e, C-h E, (help commands), and ESC-TAB (math-complete-symbol) depend on a running Mathematica process. C-c C-y affects a buffer expected to have a running Mathematica process. These commands can all be used from a buffer that does not have a running Mathematica process, in which case they affect a buffer that does. The default is *math*, the buffer created by the math command, but the buffer can be changed with M-x set-math-process-buffer. Different buffers can have different associated math process buffers.
Bugs/limitations:
If the input is does not form a complete statement, Mathematica may hang waiting for more input. If this happens, type a RET to add a blank line, then ESC-RET to send an empty cell, which will clear Mathematica's input buffer. Cut away the new prompt, fix the cell and resubmit. Do not just fix the input and hit ESC-RET, as Mathematica will get the concatenation of both the first submission and the second. (You can demonstrate incomplete statements on the input "5+".)
If you change Mathematica's $Path variable, C-c C-e may be unable to find the file (or may find the wrong file). A solution short of changing the Mathematica-search-path variable (using M-x set-variable) is to visit the file, then use M-x goto-matherr-line.
The code that locates errors after typing ESC-RET depends on certain output being delevered from the process in complete chunks. Emacs documentation explicitly forbids relying on this property. Therefore this feature may be unreliable or non-portable.
Fancy installation:
You can avoid having to explicitly load the math package by putting the following lines in your .emacs file
(autoload 'math "math" "Starts Mathematica in a separate buffer" t)
(autoload 'math-mode "math" "A mode for running Mathematica
or editing Mathematica source files." t)
(autoload 'start-math "math" "Starts Mathematica in the current
buffer" t)
(setq auto-mode-alist (cons '("\\.m$" . math-mode) auto-mode-alist))
Math-mode will run faster if you "byte-compile" it. Type M-x
byte-compile-file math.el (make sure the directory is right).
Enjoy,
-- David Jacobson
================================