[sci.math.symbolic] Emacs as a front end for Mathematica?

dancon@ut-emx.UUCP (Dan Connolly) (03/21/90)

I use Mathematica remotely from a variety of hosts, and
I'm getting tired of the command-line-interface front end.
(I don't think there's anything wrong with it. It does it's
job just fine. I want a bigger job done.)

It strikes me that the Mathematica command-line-interface is
almost exactly the same as the Lisp read-eval-print loop.

Now emacs supports fairly sophisticated interaction with the
Lisp read-eval-print loop, and it's been interfaced to other

How about an emacs math-mode to put a nicer face on Mathematica?

I suppose running a shell inside emacs and running Mathematica
from there will provide cut and paste, but certainly one could
build some more smarts into emacs. I don't have any really good
ideas, but I'm going to start playing.

I'm completely new to e-lisp programming, so if anybody has
any suggestions -- if there are any packages out there that
could be easily made into a math-mode, I'd love to hear about

Dan Connolly

jmberkey@watnow.waterloo.edu (J. Michael Berkley) (03/21/90)

> On 20 Mar 90 20:16:43 GMT, dancon@ut-emx.UUCP (Dan Connolly) said:

DC> I use Mathematica remotely from a variety of hosts, and
DC> I'm getting tired of the command-line-interface front end.

I don't know about a Mathematica front end, but Bruno Salvy
(salvy@inria.inria.fr) wrote a nice Maple mode for emacs.

 Mike Berkley, University of Waterloo

reiner@isy.liu.se (Reiner Lenz) (03/21/90)

jmberkey@watnow.waterloo.edu (J. Michael Berkley) writes:

>> On 20 Mar 90 20:16:43 GMT, dancon@ut-emx.UUCP (Dan Connolly) said:

>DC> I use Mathematica remotely from a variety of hosts, and
>DC> I'm getting tired of the command-line-interface front end.

>I don't know about a Mathematica front end, but Bruno Salvy
>(salvy@inria.inria.fr) wrote a nice Maple mode for emacs.

> Mike Berkley, University of Waterloo
> PAMI Lab
> jmberkley@watnext.waterloo.edu
> {utai,uunet}!watmath!watnext!jmberkley

I use a program called fep = (front end processor).

Here is the startup line for mathematica:

exec /usr/local/bin/sun3/fep $mathdir/$machdir/mathexe \
	-pwpath '{"'$mathdir/Install'"}' \

Here is the README File from fep:

Copyright (c) 1987,1988 by Software Research Associates, Inc.

FEP is a general purpose front end for any line-oriented command on
UNIX. This command was developed on Berkeley UNIX, but will probably
run on most UNIX system which have pseudo tty and the select system

Making FEP

	Just type 'make'.
	If your system is running ASCII UNIX or some compatible system,
	the -DKANJI flag makes fep handle kanji character input.

Using FEP

	See man page fep.1 for detail.
	The help command (ESC-?) and show-bindings command (^X-^B) are
	very convenient when running fep.


	Distribution without fee is permitted as long as all
	copyright notices are included.

Any comments will be greatly appreciated. Have fun.

			Kazumasa Utashiro
			Software Research Associates, Inc.
			1-1-1 Hirakawa-cho, Chiyoda-ku, Tokyo 102, Japan
				UUCP:	kddlab!srava.sra.junet!utashiro
				ARPA:	utashiro%sra.junet@uunet.uu.net
				JUNET:	utashiro@sra.junet

Here is the man page:
.\" Copyright (c) 1987, 1988 by Software Research Associates, Inc.
.\" $Header: fep.1,v 4.0 88/08/05 20:22:31 utashiro Rel $
.TH FEP 1L "5 Aug 1988" "SRA Distribution"
fep \(em general purpose front end processor
\fBfep\fR [\|-\fBemacs\fR\||\|-\fBvi\fR\|] \fI\s-1UNIX\s0-command\fR
.I Fep
is a general purpose front end processor applicable to most UNIX commands
that features \fIvi\fP\|(1)- or \fIemacs\fR\|(1)-like line editing and
a command history mechanism like that of \fIcsh\fR\|(1).
Choice of editing style is made by selecting either
the emacs mode or the vi mode
(named for the editors they emulate),
specified either by command line option or
by setting a variable interactively or in the start-up file
or environment EDITMODE (see editmode variable).
The default key bindings are shown below for both edit modes.
These can be customized using the fep-bind command.
.B Emacs Bindings
Here follow the default key bindings for the emacs mode.
Each function name should be self-explanatory.
The function names are defined as similarly to Gosling's emacs as possible.
.ta 1.5i
^@	mark
^A	beginning-of-line
^B	backward-character
^D	delete-next-character
^E	end-of-line
^F	forward-character
^I	insert-tab
^J	new-line
^K	kill-to-end-of-line
^L	clear-screen
^M	new-line
^N	next-history
^P	previous-history
^T	previous-history
^Y	yank-from-kill-buffer
^^	toggle-transparency
^X-^B	show-bindings
^X-^H	show-history
^X-^C	terminate
^X-^D	send-eof
^X-^L	repaint
^X-(	start-script
^X-)	end-script
esc-b	backward-word
esc-B	backward-word
esc-d	delete-next-word
esc-D	delete-next-word
esc-f	forward-word
esc-F	forward-word
esc-h	delete-previous-word
esc-H	delete-previous-word
esc-l	list-file-name
esc-L	list-file-name
esc-esc	expand-file-name
esc-?	help
esc-_	invoke-shell
esc-<	search-reverse
esc->	search-forward
.if t .sp .3v
/* Bindings inherited from the tty driver */
.if t .sp .3v
erase	delete-previous-character
kill	delete-line
rprnt	reprint
werase	delete-previous-word
lnext	literal-next
.B Vi bindings
The vi mode has two sub-modes,
the command mode and the text insert mode.
The commands of vi are emulated as correctly as possible.
Here is a list of the default key bindings of the vi mode
that differ from normal vi commands.
The tty driver control characters are also inherited in this mode.
n	search-reverse
N	search-forward
^A	expand-file-name
^L	list-file-name
^N	next-history
^P	previous-history
^R	reprint
^^	toggle-transparency
^X-^B	show-bindings
^X-^H	show-history
^X-^L	repaint
^X-^X	expand-file-name
^X-^C	terminate
^X-^D	send-eof
^X-l	list-file-name
^X-L	list-file-name
^X-?	help
^X-(	start-script
^X-)	end-script
.B Built-in commands
.I Fep
has some built-in commands
that are not passed to the child process but
understood and processed by fep itself.
These commands can be issued from the terminal or from the start-up file.
.RS 3n
.IP "\fBfep-bind \fIfunction-name key-binding\fR"
Change key bindings.
For example,
to bind the function
.I list-file-name
to the string "^X-^X",
type the following:
.if t .sp 0.3v
.if n .sp 1
\h'\w'MMMMM'u'fep-bind list-file-name "\\^X\\^X"
.if t .sp 0.3v
.if n .sp 1
\fBfep-alias\fP \fIname\fP
\fBfep-alias\fP \fIname string\fP
The first form prints all aliases.
The second form prints the alias for \fIname\fP.
The last form set the alias for \fIname\fP to \fIstring\fP.
If you use
.I fep
without \fIauto-tty-fix\fP, following alias could be usefull.
.if t .sp .3v
.if n .sp 1
\h'\w'MMMMM'u'if\ $command\ ==\ sh
\h'\w'MMMMMMMMMM'u'fep-alias\ more\ "fep-command\ more"
\h'\w'MMMMMMMMMM'u'fep-alias\ vi\ "fep-command\ vi"
.if t .sp .3v
.if n .sp 1
.IP "\fBfep-unalias\fP \fIlist\fP"
Remove alias for each name in \fIlist\fP.
.IP "\fBfep-set\fP \fIvariable = value\fR"
Set a variable of \fIfep\fP to some value.
.IP "\fBfep-unset\fP \fIvariable\fR"
Unset a variable.
\fBfep-cd\fP [ \fIdirectory\fR ]
\fBfep-chdir\fP [ \fIdirectory\fR ]
Change directory.
It sometimes happens that a child process has changed directory,
.I fep
is still in the old directory.
In such a case, neither \fIlist-file-name\fR nor \fIexpand-file-name\fR
will function as expected.
This command allows you to change
.IR fep 's
current working directory (default = home directory).
.IP "\fBfep-pwd\fP"
.IR fep 's
current working directory.
.IP "\fBfep-history\fP [ \fInumber of line\fR ]"
Show the history of commands under
.IR fep .
.IP "\fBfep-echo\fP \fIarguments\fR"
Only print the arguments.
Variable names can be used prefixed by the "$" character.
.IP "\fBfep-source\fP \fIfile\fR"
Read the specified file and execute it.
The contents of the file are not sent to sub-processes.
.IP "\fBfep-save-history\fP [ \fInumber of lines to save\fR ] \fIfile\fR"
Save the current history buffer in the specified file.
.IP "\fBfep-read-history\fP  [ \fIfile\fR ]"
Read in the command history from the specified file.
The default file is the value of the \fIhistory-file\fP variable.
This file name is understood as a path relative to the home directory.
If you want to specify the name relative to the current directory instead,
prefix the path by "./".
\fBfep-command\fP \fIcommand\fP
\fBfep-!\fP \fIcommand\fP
Execute \fIcommand\fP.
.IP "\fBquit-fep\fP"
Kill the sub-process and exit.
.IP \fBfep-suspend\fP
.I fep
In the unlikely possibility that
.I fep
falls into a dead-lock in which
the sub-processes have stopped but
.I fep
is still running,
use one of these commands to escape from the situation.
\fBfep-read-from-file\fP \fIfile\fP
\fBfep-<\fP \fIfile\fP
Read data from specified file and send them to sub-process.
The sub-process will read the data from the file as if they are typed
at the keyboard.
\fBfep-read-from-command\fP \fIcommand\fP
\fBfep-<!\fP \fIcommand\fP
Send output of specified command to sub-process.
\fBfep-start-script [ \fIscript-file\fP ]
\fBfep-script [ \fIscript-file\fP ]
Start to send input and output to a script file.
If \fIscript-file\fP is specified, it is used.
If not the value of the variable \fIscript-file\fP will be used.
Stop scripting.
.IP "\fBfep-show-bind\fP"
Print current binding information.
.IP "\fBfep-repaint\fP [ \fIline\fP ]"
Repaint last output from command to screen.
``\fIline\fP'' specifies number of lines to repaint
(default is screenful maximum). See also ``\fIauto-repaint\fP'' and
``\fIclear-repaint\fP'' variables.
.B Control structures
.RS 3n
\fBfep-if\fP \fIexpression\fP
\fBfep-elseif\fP \fIexpression\fP
Only four control structures are supported but that seems enough.
.I Expression
allows only the two operators "==" and "!=".
.ce 0
Variables can be referenced by prefixing with the "$" character.
The "\fIfep-\fR" prefix of the built-in functions and the above operators
can be abbreviated in commands that
.I fep
executes from a file.
.\" ------------------------------------------------------------ Comment
.B Comment
Lines starting with the character "#" are ignored by
.IR fep .
.I fep
encounters a comment in interaction, it is sent to the sub-process.
In reading from a file, comments will merely be ignored.
.\" ------------------------------------------------------------ Variables
.B Variables
.I Fep
uses some variables.
.RS 3n
.ta 3i
.IP "\fBeditmode\fP	default: emacs"
This variable defines the mode for command line editing.
Key bindings will be set for the appropriate defaults
when this variable is changed.
.I Fep
first looks at the environment variable
then looks at any command line arguments,
and finally reads in the
.I .feprc
start-up file.
.IP "\fBexpand-tilde\fP	default: on"
.I Fep
expands "~" to the real home directory name by the expand-file-name function
when this variable is set.
.IP "\fBignore-empty-line\fP	default: on"
If this variable is set, empty command lines are not saved in the history file.
.IP "\fBignore-same-line\fP	default: on"
If this variable is set,
command lines identical to the previous command line
are not saved to the history file.
.IP "\fBalarm-on-eof\fP	default: off"
If this variable is set
AND the function send-eof is not bound to the eof character
AND the variable ignore-eof is not set,
an alarm message will be displayed once
the first time eof is encountered on an empty line.
.IP "\fBhistory\fR	default: 100"
.I Fep
maintains a history file of the length specified by this variable.
.IP "\fBsavehist\fR	default: off"
.I savehist
is set
.I fep
saves the number of history entries specified by
value of this variable in the file named in the variable
.I history-file
on terminating.
.IP "\fBhistory-file\fP	default: .fephistory"
Contains the name of the history file for reading from and writing to.
If the file described by this variable exists,
.I fep
will read the file into the history buffer on start up
and then save the current session's history when it exits.
.IP "\fBshowhist\fR	default: terminal size"
This variable specifies the number of history lines to be displayed by the
.I show-history
.IP "\fBignore-eof\fP	default: off"
.I Fep
never worries about the eof character if this variable is set.
.IP "\fBnoalias\fP	default: off"
If set, command aliasing won't be done.
.IP "\fBcrt\fP	default: terminal size"
If set, more message is shown during printing the key bindings
on each number of line specified by this variable.
.IP "\fBcommand\fP	default: \fIcommand-name\fR"
.I Fep
set this variable to the command name of the sub-process when it starts up.
.IP "\fBshell\fR	default: /bin/sh"
Describe the command name to be invoked by 
.IR invoke-shell .
.IP "\fBauto-tty-fix\fP	default: on"
If this variable is set,
.I fep
looks at the tty mode of the sub-command,
and if the tty mode has changed,
.I fep
fixes the tty mode of standard out and
sets the transparency flag according to the mode.
If this variable is not set, the automatic tty mode check is not done,
so you have to change the tty mode and transparency explicitly using the
\fItoggle-transparency\fP function.
.IP "\fBtty-fix-bell\fP	default: off"
If this variable is set,
.I fep
rings the bell when the tty mode is changed.
.IP "\fBscript-file\fP	default: fepscript"
This variable is used by the
.I fep-start-script
command and by the
.I start-script
.IP "\fBdelimiters\fP	default: SPACE & TAB"
The contents of this variable are treated as delimiting characters for
file name expantion and file name list.
.IP "\fBauto-repaint\fP	default: off"
If this variable is set, \fIfep\fP automatically repaints the screen
after restarting.
.IP "\fBclear-repaint\fP	default: off"
If this variable is set, \fIfep\fP clears the screen before repainting.
.IP "\fBprompt\fP	default: see below"
.I Fep
outputs a prompt after executing built-in functions.
The default string is set to the NULL string,
but there are some default prompt strings for some common commands such as
.I sh, dbx, lpc, mail, "sendmail -bt"
.I calc.
However, since
.I fep
doesn't care about what program is running,
the same prompt is still output when you are executing
.I bc
.IR sh .
You can change the value of prompt and other variables in the start-up file
as follows:
.if t .sp .3v
.if n .sp 1
\h'\w'MMMMM'u'if $command == sh
\h'\w'MMMMMMMMMM'u'set prompt = "$ "
.B Start-Up File
.I Fep
executes the file ".feprc" in the home directory of the user
if it is found there when starting up.
It looks for arguments on the command line first,
and only then reads the ".feprc" file,
so the file has higher priority.
.B "Functions"
.ta \w'delete-previous-character\ \ \ 'u
abort	Abort function
backward-Word	Backward word (non-space)
backward-character	Backward character
backward-word	Backward word (alpha-numeric)
beginning-of-line	Jump to beginning of line
clear-screen	Clear screen
delete-line	Delete whole line
delete-next-Word	Delete next word (non-space)
delete-next-character	Delete next character
delete-next-word	Delete next word (alpha-numeric)
delete-previous-Word	Delete previous word (non-space)
delete-previous-character	Delete previous character
delete-previous-word	Delete previous word (alpha-numeric)
delete-to-kill-buffer	Delete resion to buffer
end-of-line	Jump to end of line
end-script	End script
expand-file-name	Expand file name
fix-transparency	Check tty and change transparency mode
forward-Word	Forward word (non-space)
forward-character	Forward character
forward-to-end-of-Word	Forward to end of word (non-space)
forward-to-end-of-word	Forward to end of word (alpha-numeric)
forward-word	Forward word (alpha-numeric)
help	Show help
ignore	Ignore
insert-and-flush	Insert the character and flush buffer
insert-tab	Insert tab
invoke-shell	Invoke shell process
kill-to-end-of-line	Delete current position to eol
kill-to-top-of-line	Delete tol to current position
list-file-name	List file name
literal-next	Treat next character as literal
mark	Mark position
new-line	Insert newline
next-history	Get next history
previous-history	Get previous history
repaint	Repaint screen
reprint	Reprint line
search-forward	Search forward last !history
search-reverse	Search backward last !history
self-insert	Insert the character
send-eof	Send eof
show-bindings	Show binding table
show-history	Show history
start-script	Start script
suspend	Suspend fep
terminate	Terminate fep
toggle-transparency	Change transparency mode
vi-c	Vi c? commands
vi-d	Vi d? commands
vi-edit	Vi edit commands
vi-ins-edit	Vi insert mode
vi-motion	Vi cursor motion commands
vi-new-line	Vi new line
vi-num	Vi prefix number
yank-from-kill-buffer	Yank from kill buffer
Probably only the function name "\fItoggle-transparency\fR"
is hard to understand.
This function is provided for entering non-line-oriented tools
from a line-oriented tool using
.IR fep .
Assume a situation where you are using
.IR sh (1)
.IR fep ,
and then invoke
.IR vi (1).
.I fep
intercepts all input for editing,
.I vi
cannot work correctly.
You can escape from this annoying situation using the
"\fItoggle-transparency\fR" function which is bound to the
.I Control-^
key by default.
Of course, it is also necessary to return to the normal mode after exiting vi.
Note, however, that this tty mode fix can also be done automatically.
If the
.I auto-tty-fix
variable is set,
.I fep
looks at the tty mode of the sub-command and fixes the tty mode of standard
input accordingly.
.I Fep
can handle SHIFT-JIS kanji code if compiled with the -DKANJI flag.
Copyright (c) 1987, 1988 by Software Research Associates, Inc.
Distribution without fee is allowed as long as
all copyright notices are included.
K. Utashiro
Software Research Associates, Inc., Japan.
.ta \w'JUNET:  'u
UUCP:	kddlab!srava.sra.junet!utashiro
ARPA:	utashiro%sra.junet@uunet.uu.net
JUNET:	utashiro@sra.junet
.ta \w'~/.feprc,\ ./.feprc\ \ \ 'u
\^~/.feprc,\ ./.feprc	start-up file
\^~/.fephistory	default history file
\^./fepscript	default script file
While working on the program the author sometimes lost his mind,
whereupon so did the program.
"Kleinphi macht auch Mist"
Reiner Lenz | Dept. EE.                 |
            | Linkoeping University	| email:	reiner@isy.liu.se
            | S-58183 Linkoeping/Sweden |