                 Running Macaulay 2 in Emacs

       -- this file has been automatically generated -- 
                      -- do not edit -- 


running Macaulay 2 in emacs

Because some answers can be very wide, it is a good idea to run Macaulay 2
in a window which does not wrap output lines and allows the
user to scroll horizontally to see the rest of the output.  We
provide a package for "emacs" which implements this, in
'emacs/M2.el'.  It also provides for dynamic completion
of symbols in the language.

There is an ASCII version of this section of the documentation distributed
in the file 'emacs/emacs-hlp.txt'.  It might be useful for you to visit
that file with emacs now, thereby avoiding having to cut and paste bits of
text into emacs buffers for the deomonstrations below.

If you are a newcomer to emacs, start up emacs with the command 
'emacs' and then start up the emacs tutorial with the keystrokes 
'C-H t'.  (The notation 'C-H' indicates that you should type 
'Control-H', by holding down the control key, 
and pressing 'H'.)  The emacs tutorial will introduce you to the
basic keystrokes useful with emacs.  After running through that you will want
to examine the online emacs manual which can be read with 'info'
mode; you may enter or re-enter that mode with the keystrokes 'C-H i'.  
You may also want to purchase (or print out) the emacs manual.  It is cheap,
comprehensive and informative.  Once you have spent an hour with the emacs
tutorial and manual, come back and continue from this point.

Edit your '.emacs' initialization file, located in your home directory,
creating one if necessary.  (Under Windows, this file is called '_emacs',
and your home directory is the one your Desktop folder is in.  If your login
name is 'xxx', then your home directory 'c:/winnt/profiles/xxx' 
under NT and 'c:/windows/profiles/xxx' under Windows 95/98.  In 
any case, the name of the home directory is abbreviated to a single
tilde '~' under emacs.)  Insert into your initialization
file the following line of emacs-lisp code (which can also be found
in the file 'emacs/emacs-hlp.txt', or obtained by running
'help "running Macaulay 2 in emacs"' in Macaulay 2).

(load "/usr/local/Macaulay2-0.9/lib/Macaulay2-0.9/emacs/M2-init.el")

Now edit that line and replace the path by the correct path to Macaulay2's
files on your system.  To find out what that path is, run the following command'getenv "M2HOME"' in Macaulay 2.  Then append '/emacs/M2-init.el'
to the value returned and incorporate it into the 'load' command above.

Loading the file will cause emacs to enter a special mode for editing
Macaulay 2 code whenever a file whose name has the form '*.m2' is
encountered.  It will also provide a special mode for running Macaulay 2 in
an emacs buffer.  It sets the variable 'transient-mark-mode' to have
a different value in each buffer, and sets hooks so that 'transient-mark-mode' will be set to 't' in M2 buffers.  The
effect of this is that the mark is only active occasionally, and then emacs
functions which act on a region of text will refuse to proceed unless the
mark is active.  The 'set-mark' function or the 'exchange-point-and-mark' function will activate the mark, and it will
remain active until some change occurs to the buffer.  The only reason we
recommend the use of this mode is so the same key can be used to evaluate a
line or a region of code, depending on whether the region is active.

Exit and restart emacs with your new initialization file.  
If you are reading this file with emacs, then use the keystrokes
'C-x 2' to divide the buffer containing this file into two windows.
Then press the 'F12' function key to start up 
Macaulay 2 in a buffer named '*M2*'.

If this doesn't start up Macaulay 2, one reason may be that your function
keys are not operable.  In that case press 'C-C m' instead.  (The 
notation 'C-C' is standard emacs notation for Control-C.)  Another
reason may be that you have not installed Macaulay 2 properly - the startup
script ('M2' or 'M2.bat') should be on your path.
A third reason may be that you are in Windows-98 and are using anti-virus 
software such as 'Dr. Solomon's', which can interfere with emacs 
when it tries to run a subprocess.

You may use 'C-x o' freely to switch from one window to the other.
Verify that Macaulay 2 is running by entering a command such as '2+2'.  
Now paste the following text into a buffer, unless you have the ASCII
version of this documentation in an emacs buffer already, position
the cursor on the first line of code, and press the 'F11' function 
key (or 'C-C s') repeatedly to present each line to Macaulay 2.

i1 : R = ZZ/101[x,y,z]
i2 : f = symmetricPower(2,vars R)
i3 : M = cokernel f
i4 : C = resolution M
i5 : betti C

Notice that the input prompts are not submitted to Macaulay 2.

Here is a way to conduct a demo of Macaulay 2 in which the code to be
submitted is not visible on the screen.  Paste the following text into
an emacs buffer.

20!
4 + 5 2^20
-- that's all folks!

Press 'M-F11' with your cursor in this buffer to designate it as
the source for the Macaulay 2 commands.  (The notation 'M-F11' means 
that while holding the 'Meta' key down, you should press the 'F11' 
key.  The Meta key is the Alt key on some keyboards, or it can be simulated by 
pressing Escape (just once) and following that with the key you wanted to press 
while the meta key was held down.)  Then position your cursor (and thus the 
emacs point) within the line containing '20!'.  Now press 'M-F12'
to open up a new frame called 'DEMO' for the '*M2*' window with
a large font suitable for use with a projector, and with your cursor in that
frame, press 'F11' a few times to conduct the demo.  (If the font or frame is the
wrong size, you may have to create a copy of the file 'M2.el'
with a version of the function 'M2-demo' modified to fit your screen.)

One press of 'F11' brings the next line of code forward into the
'*M2*' buffer, and the next press executes it.  Use 'C-x 5 0' 
when you want the demo frame to go away.

There is a way to send a region of text to Macaulay 2: simply select a region
of text, making sure the mark is active (as described above) and press 'F11'.
Try that on the list below; put it into an emacs buffer, move your cursor to the 
start of the list, press 'M-C-@' or 'M-C-space' to mark the list, 
and then press 'F11' to send it to Macaulay 2.  (The notation 'M-C-@' 
means: while holding down the Meta key and the Control key press the '@' key, 
for which you'll also need the shift key.)

{a,b,c,d,e,f,
g,h,i,j,k,l,
m,n}

We have developed a system for incorporating Macaulay 2 interactions into TeX
files.  Here is an example of how that looks.  Paste the following text
into an emacs buffer.

The answer, 4, is displayed after the output label ``{\tt o1\ =}''.
Multiplication is indicated with the traditional {\tt *}.
<<<1*2*3*4>>>
Powers are obtained as follows.
<<<2^100>>>

The bits in brackets can be submitted to Macaulay 2 easily.  Position your
cursor at the top of the buffer and press 'F10.'  The cursor will move 
just past the first '<<<', and the emacs mark will be positioned just 
before the '>>>'.  Thus '1*2*3*4' is the region, and it will
even be highlighted if you have set the emacs variable 'transient-mark-mode'
to 't' for this buffer.  Pressing 'F11' will send '1*2*3*4' 
to Macaulay 2 for execution: try it now.  A sequence of such Macaulay 2 commands 
can be executed by alternately pressing 'F10' and 'F11'.  You may
also use 'M-F10' to move backward to the previous bracketed expression.

Now let's see how we can handle wide and tall Macaulay 2 output.  Execute the
following line of code.

random(R^20,R^{6:-2})

Notice that the long lines in the Macaulay 2 window, instead of being wrapped
around to the next line, simply disappear off the right side of the screen,
as indicated by the dollar signs in the rightmost column.  Switch to the
other window and practice scrolling up and down with 'M-v' and 'C-v', 
and scrolling left and right with the function key 'F3' (or 'C-C <') 
and the function key 'F4' (or 'C-C >').  Notice how the use of
'C-E' to go to the end of the line
sends the cursor to the dollar sign at the right hand side of the screen;
that's where the cursor will appear whenever you go to a position off the
screen to the right.  Then use the 'F2' function key (or 'C-C .') to 
scroll the text so the cursor appears at the center of the screen.  Use 'C-A' to 
move to the beginning of the line and then the 'F2' function key 
(or 'C-C .') to bring the left margin back into view.

You may use the 'F5' function key or (or 'C-C ?') to 
toggle whether long lines are truncated or wrapped; initially they are truncated.

Now go to the very end of the '*M2*' buffer with 'M->' and 
experiment with keyword completion.  Type 'reso' and then press the 
'TAB' key.  Notice how the word is completed to 'resolution'
for you.  Delete the word with 'M-DEL', type 'res'
and then press the 'TAB' key.  The possible completions are displayed 
in a window.  Switch to it with the 'F8' key, move to the desired 
completion, select it with the 'RETURN' key, and then return to the 
'*M2*' buffer with 'C-X o'.  Alternatively, if you have a
mouse, use the middle button to select the desired completion.

Experiment with command line history in the '*M2*' buffer.  Position 
your cursor at the end of the buffer, and then use 'M-p' and 'M-n' 
to move to the previous and next line of input remembered in the history.  When you 
get to one you'd like to run again, simply press return to do so.  Or edit it
slightly to change it before pressing return.

Assuming you have installed the "w3" emacs web browser,
you may explore the documentation by positioning the cursor near a documented
word such as 'List' and pressing 'C-C d'.  Alternatively,
when the prompt appears, you can type the key whose documentation should be
found.