ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial
Web Hosting by 1&1

11.1 Setting the Mark

Here are some commands for setting the mark:

C-<SPC>
Set the mark at point, and activate it (set-mark-command).
C-@
The same.
C-x C-x
Set the mark at point, and move point where the mark was (exchange-point-and-mark).
Drag-Mouse-1
Set point and the mark around the text you drag across.
Mouse-3
Set the mark at point, then move point to where you click (mouse-save-then-kill).
Shifted motion keys
Set the mark at point if the mark is inactive, then move point.

The most common way to set the mark is with C-<SPC> (set-mark-command)1. This sets the mark where point is, and activates it. You can then move point away, leaving the mark behind.

For example, suppose you wish to convert part of the buffer to upper case. To accomplish this, go to the beginning of the desired text, type C-<SPC>, and move point until the desired portion of text is highlighted. Now type C-x C-u (upcase-region). This converts the text in the region to upper case, and then deactivates the mark.

The command C-x C-x (exchange-point-and-mark) exchanges the positions of point and the mark, keeping the region unchanged. If the mark is inactive, Emacs first reactivates the mark wherever it was last set. C-x C-x is useful when you are satisfied with the position of point but want to move the other end of the region (where the mark is). Using C-x C-x a second time, if necessary, puts the mark at the new position with point back at its original position.

You can also set the mark with the mouse. If you press the left mouse button (down-mouse-1) and drag the mouse across a range of text while holding down this button, this sets the mark where you first pressed the mouse button and puts point where you release it. Alternatively, clicking the right mouse button (mouse-3) sets the mark at point and then moves point to where you clicked. Using the mouse to mark a region also copies the region into the kill ring (see Kill Ring). See Mouse Commands, for a more detailed description of these mouse commands.

Finally, you can set the mark by holding down the shift key while typing certain cursor motion commands (such as S-<right>, S-C-f, S-C-n, etc.) This is referred to as shift-selection. This sets the mark at point before moving point, but only if there is no active mark set via shift-selection. The mark set by mouse commands and by shift-selection behaves slightly differently from the usual mark: any subsequent unshifted cursor motion command deactivates it automatically. For details, See Shift Selection.

Whenever the mark is active, you can deactivate it by typing C-g (see Quitting). The mark is also automatically deactivated after certain non-motion commands.

Footnotes

[1] There is no C-<SPC> character in ASCII; usually, typing C-<SPC> on a text terminal gives the character C-@. This key is also bound to set-mark-command, so unless you are unlucky enough to have a text terminal that behaves differently, you might as well think of C-@ as C-<SPC>.

blog comments powered by Disqus