Next: , Up: Frames

21.1 Mouse Commands for Editing

Mouse-1
Move point to where you click (mouse-set-point).
Drag-Mouse-1
Activate the region around the text selected by dragging, and put the text in the primary selection (mouse-set-region).
Mouse-2
Move point to where you click, and insert the contents of the primary selection there (mouse-yank-primary).
Mouse-3
If the region is active, move the nearer end of the region to the click position; otherwise, set mark at the current value of point and point at the click position. Save the resulting region in the kill ring; on a second click, kill it (mouse-save-then-kill).

The most basic mouse command is mouse-set-point, which is invoked by clicking with the left mouse button, Mouse-1, in the text area of a window. This moves point to the position where you clicked. If that window was not the selected window, it becomes the selected window.

Normally, if the frame you clicked in was not the selected frame, it is made the selected frame, in addition to selecting the window and setting the cursor. On the X Window System, you can change this by setting the variable x-mouse-click-focus-ignore-position to t. In that case, the initial click on an unselected frame just selects the frame, without doing anything else; clicking again selects the window and sets the cursor position.

Holding down Mouse-1 and “dragging” the mouse over a stretch of text activates the region around that text (mouse-set-region), placing the mark where you started holding down the mouse button, and point where you release it (see Mark). In addition, the text in the region becomes the primary selection (see Primary Selection).

If you change the variable mouse-drag-copy-region to a non-nil value, dragging the mouse over a stretch of text also adds the text to the kill ring. The default is nil.

If you move the mouse off the top or bottom of the window while dragging, the window scrolls at a steady rate until you move the mouse back into the window. This way, you can select regions that don't fit entirely on the screen. The number of lines scrolled per step depends on how far away from the window edge the mouse has gone; the variable mouse-scroll-min-lines specifies a minimum step size.

Clicking with the middle mouse button, Mouse-2, moves point to the position where you clicked and inserts the contents of the primary selection (mouse-yank-primary). See Primary Selection. This behavior is consistent with other X applications. Alternatively, you can rebind Mouse-2 to mouse-yank-at-click, which performs a yank at point.

If you change the variable mouse-yank-at-point to a non-nil value, Mouse-2 does not move point; it inserts the text at point, regardless of where you clicked or even which of the frame's windows you clicked on. This variable affects both mouse-yank-primary and mouse-yank-at-click.

Clicking with the right mouse button, Mouse-3, runs the command mouse-save-then-kill. This performs several actions depending on where you click and the status of the region:

The mouse-save-then-kill command also obeys the variable mouse-drag-copy-region (described above). If the value is non-nil, then whenever the command sets or adjusts the active region, the text in the region is also added to the kill ring. If the latest kill ring entry had been added the same way, that entry is replaced rather than making a new entry.

Whenever you set the region using any of the mouse commands described above, the mark will be deactivated by any subsequent unshifted cursor motion command, in addition to the usual ways of deactivating the mark. See Shift Selection.

Some mice have a “wheel” which can be used for scrolling. Emacs supports scrolling windows with the mouse wheel, by default, on most graphical displays. To toggle this feature, use M-x mouse-wheel-mode. The variables mouse-wheel-follow-mouse and mouse-wheel-scroll-amount determine where and by how much buffers are scrolled. The variable mouse-wheel-progressive-speed determines whether the scroll speed is linked to how fast you move the wheel.