next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc > getting started > using Macaulay2 with emacs > using Macaulay2 with emacs after it has been set up

using Macaulay2 with emacs after it has been set up

In this section, we show by example how to use the Macaulay2 emacs interface. We assume that you have already set up this interface, as described in setting up the Macaulay2 emacs interface. After creating or changing the .emacs file mentioned there, you need to exit and restart emacs. For the rest of this section, we assume that you are running emacs.

The aspects of this interface that we describe include

Before starting, note that when we say to type M-x M2, what we really mean is: press the x key while holding down the meta key (on Macs this is either the option key or the apple key, depending on how your emacs is set up); type M2; and then press the return (or enter) key after that. Similarly, C-c means to press the c key while holding down the control key, and C-x 2 means to press x while holding down the control key, then to press 2; this time do not press enter.

Use the keystrokes C-x 2 to divide the buffer containing this file into two windows. Then press the f12 key or type M-x M2 to start up Macaulay2 in a buffer named *M2*. (The command line used to start Macaulay2 may be edited before being run if you use a prefix argument with the above command: press C-u just before.)

If f12 doesn't start up Macaulay2, one reason may be that your function keys are not operable. In that case press C-c m instead. Another reason may be that you have not installed Macaulay2 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 Macaulay2 is running by entering a command such as 2+2. Now create (using C-x C-f) a file, named something like foo.m2 (the final .m2 is important, as it informs emacs to use the Macaulay2 mode). Paste the following text into a buffer. If you wish, save the file using C-x C-s.

    R = QQ[x,y,z]
    f = symmetricPower(2,vars R)
    M = cokernel f
    C = resolution M
    betti C

Position the cursor on the first line of code, and press the f11 function key repeatedly to present each line to Macaulay2. If you select several lines using the mouse, then pressing f11 will present the entire selection to Macaulay2. Try this on some of these lines.


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. (On the mac, hold down the option key while clicking the mouse)

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.


Now let's see how we can handle wide and tall Macaulay2 output. Execute the following line of code (put it in your foo.m2 buffer, and then press f11)

printWidth=0; random(R^20,R^{6:-2})
Setting printWidth to zero removes line wrapping in the buffer, sometimes useful to view large matrices.

Notice that the long lines in the Macaulay2 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 or little arrows 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 LinearAlgebra (or C-c >). In modern emacs implementations where mouse clicking works, click on the arrow to scroll in that direction. In these versions of emacs, typing C-e, or C-a to get at the end or beginning of the line also horizontally scrolls the text to that position. Older emacs tend to need a bit more: 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.