Emacs windows and the mouse
Several useful techniques are available for using the mouse with Emacs windows.
You can use the mouse to perform many of the functions described in the Split and partition your Emacs session section. These window actions are done on the mode line.
In new versions of Emacs, special areas of the mode line have their own mouse bindings. For instance, if your mode line displays whether you have mail (it does so by writing the word Mail), then clicking that word on the mode line in certain ways with the mouse starts a new buffer for your mail; clicking the buffer name in the mode line switches the buffer in that window to the next buffer in your buffer list. These are called tooltips and are shown with a pop-up box that appears when you mouse over the particular area of the mode line. Aside from these special tooltips, the following commands work anywhere on the mode line.
C-B2 combination clicked on the mode line splits
the window horizontally at the place you click. If you're too close to
either end of the window, the split is the minimal amount possible. (You make
this combination by pressing and holding the Ctrl key and then clicking the
middle mouse button.)
C-B2 combination on the scrollbar splits the
window vertically at the place you click. If you're too close to either
end of the window, the split is the minimal amount. (Note that this currently
doesn't work with some of the X toolkits that implement the scrollbar.)
Try splitting the window with the mouse:
Exit Emacs, if it's running, by typing
C-x C-c. Start it up again with one of the sample files:
$ emacs innocence
Open the second sample file in a new vertical window: Type
C-x 4 f experience Enter.
Your Emacs session should look like Figure 1. Try the
C-B2mouse combination in the middle of the top mode line (somewhere just after the word Top) to split the top window horizontally at that point.
Split the bottom window horizontally at about the same point with a
C-B2mouse combination on its mode line—again, somewhere just after the word Top.
Click and drag
B1on the small vertical bar beneath the scrollbars of the two new windows you just created to adjust them so that all four windows are approximately the same size. If your Emacs frame is too small to display the text in all four windows, you can adjust the size of its X client frame using your window manager controls.
You can move to any Emacs window with the mouse by clicking
B1 (the first mouse button) on a blank area of the
mode line of the window you want to move to. (In new versions of Emacs, clicking
the buffer name changes the visible buffer in that window to the next buffer in
the buffer list.) The window whose mode line you click becomes the active
window, and the active cursor is moved to the current point in that window.
You can also use the mouse to move anywhere in the visible portion of another
window: To do so, click
B1 in the window. Point moves
to the place where you click.
Try moving between the four windows you just created:
Move to the upper-right window by clicking
B1in a blank area of its mode line, and then type
C-u 349 C-nto move down in the file.
Move back to the upper-left window by clicking
B1on any character in the visible buffer window, and then type
C-s Till C-s C-s C-ato refocus the display elsewhere in the buffer.
Take a break from the mouse, and move to the lower-left window by typing
C-x o C-x o, as you learned in the Move to another window section. Type
C-u 286 C-nto move down in the buffer.
B1somewhere just after the buffer name of the mode line on the lower-right window to make it the active window. Type
C-s jour C-lto shift the view in this window to elsewhere in the buffer.
You can also use the mouse on the mode line to resize windows. This is an alternative to what you learned previously in the Resize a window section.
To make a window taller or shorter, click and drag the mode line with
B1. To make a window thinner or wider, click and drag
the tiny vertical bar beneath its scrollbar.
Try adjusting the size of your windows with the mouse:
Click and drag
B1and the tiny vertical bar beneath the scrollbar of the upper-right window just a bit, so the width of the upper-right window shrinks by a few characters and the upper-left window grows enough that all the characters on each line appear in the window of both buffers. (You might also have to grow the Emacs frame using your window manager's controls.)
Make the two bottom windows smaller by clicking and dragging
B1on the mode line, so the bottom windows shrink by a few lines.
If you've followed all the steps in this section, your Emacs session should look something like Figure 7.
Figure 7. Making and resizing Emacs windows with the mouse
To delete a window, click
B3 on its mode line. Click
B2 on a blank area of the mode line to kill
all the other windows and make that window enlarge to fill the entire
Get rid of some windows:
B3on the mode line of the upper-left window to delete the window. The upper-right window expands over to the left to fill the space; now this window is the active window.
B2on its mode line to delete the two windows beneath it and make this upper window fill the entire Emacs frame.
Sometimes the mouse pointer in X gets in the way of your Emacs session—you select an Emacs frame and begin editing, and the mouse pointer is hovering somewhere over your text.
If you find this annoying, you can use
mouse-avoidance-mode to change the behavior of the
mouse pointer. This mode offers several techniques, as described in
Table 4. Styles of Emacs mouse-pointer avoidance
||Make the mouse pointer move quickly away to a random position in the frame whenever the cursor gets close to it.|
||Banish the mouse pointer to the upper-right corner of the window as soon as you start typing.|
||Synonym for |
||Move the mouse pointer to the upper-right corner of the window (like
||Make the mouse pointer instantly jump to a random position in the frame whenever the cursor gets close to it.|
||No mouse avoidance (the default).|
||Move the mouse pointer as in |
It's best with a demonstration. Try it now:
M-x mouse-avoidance-mode Enter cat-and-mouse Enterto turn on mouse-avoidance mode.
Move to the scratch buffer: Type
C-x b *scratch* Enter.
Move the mouse pointer so that it's just a few inches to the left of the cursor, and start typing a line of text: "
When the cat wants to play the mouse runs away." The mouse pointer should scoot off as soon as the cursor gets near it.