comparison man/mark.texi @ 88155:d7ddb3e565de

sync with trunk
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 00:03:54 +0000
parents 23a1cea22d13
children
comparison
equal deleted inserted replaced
88154:8ce476d3ba36 88155:d7ddb3e565de
1 @c This is part of the Emacs manual. 1 @c This is part of the Emacs manual.
2 @c Copyright (C) 1985,86,87,93,94,95,1997,2001 Free Software Foundation, Inc. 2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2001, 2002,
3 @c 2003, 2004, 2005 Free Software Foundation, Inc.
3 @c See file emacs.texi for copying conditions. 4 @c See file emacs.texi for copying conditions.
4 @node Mark, Killing, Help, Top 5 @node Mark, Killing, Help, Top
5 @chapter The Mark and the Region 6 @chapter The Mark and the Region
6 @cindex mark 7 @cindex mark
7 @cindex setting a mark 8 @cindex setting a mark
83 84
84 There are two ways to set the mark with the mouse. You can drag mouse 85 There are two ways to set the mark with the mouse. You can drag mouse
85 button one across a range of text; that puts point where you release the 86 button one across a range of text; that puts point where you release the
86 mouse button, and sets the mark at the other end of that range. Or you 87 mouse button, and sets the mark at the other end of that range. Or you
87 can click mouse button three, which sets the mark at point (like 88 can click mouse button three, which sets the mark at point (like
88 @kbd{C-@key{SPC}}) and then moves point (like @kbd{Mouse-1}). Both of 89 @kbd{C-@key{SPC}}) and then moves point where you clicked (like
89 these methods copy the region into the kill ring in addition to setting 90 @kbd{Mouse-1}). Both of these methods copy the region into the kill
90 the mark; that gives behavior consistent with other window-driven 91 ring in addition to setting the mark; that gives behavior consistent
91 applications, but if you don't want to modify the kill ring, you must 92 with other window-driven applications, but if you don't want to modify
92 use keyboard commands to set the mark. @xref{Mouse Commands}. 93 the kill ring, you must use keyboard commands to set the mark.
94 @xref{Mouse Commands}.
93 95
94 @kindex C-x C-x 96 @kindex C-x C-x
95 @findex exchange-point-and-mark 97 @findex exchange-point-and-mark
96 Ordinary terminals have only one cursor, so there is no way for Emacs 98 When Emacs was developed, terminals had only one cursor, so Emacs
97 to show you where the mark is located. You have to remember. The usual 99 does not show where the mark is located--you have to remember. If you
98 solution to this problem is to set the mark and then use it soon, before 100 enable Transient Mark mode (see below), then the region is highlighted
99 you forget where it is. Alternatively, you can see where the mark is 101 when it is active; you can tell mark is at the other end of the
100 with the command @kbd{C-x C-x} (@code{exchange-point-and-mark}) which 102 highlighted region. But this only applies when the mark is active.
101 puts the mark where point was and point where the mark was. The extent 103
102 of the region is unchanged, but the cursor and point are now at the 104 The usual solution to this problem is to set the mark and then use
103 previous position of the mark. In Transient Mark mode, this command 105 it soon, before you forget where it is. Alternatively, you can see
104 also reactivates the mark. 106 where the mark is with the command @kbd{C-x C-x}
107 (@code{exchange-point-and-mark}) which puts the mark where point was
108 and point where the mark was. The extent of the region is unchanged,
109 but the cursor and point are now at the previous position of the mark.
110 In Transient Mark mode, this command also reactivates the mark.
105 111
106 @kbd{C-x C-x} is also useful when you are satisfied with the position 112 @kbd{C-x C-x} is also useful when you are satisfied with the position
107 of point but want to move the other end of the region (where the mark 113 of point but want to move the other end of the region (where the mark
108 is); do @kbd{C-x C-x} to put point at that end of the region, and then 114 is); do @kbd{C-x C-x} to put point at that end of the region, and then
109 move it. Using @kbd{C-x C-x} a second time, if necessary, puts the mark at 115 move it. Using @kbd{C-x C-x} a second time, if necessary, puts the mark at
111 117
112 For more facilities that allow you to go to previously set marks, see 118 For more facilities that allow you to go to previously set marks, see
113 @ref{Mark Ring}. 119 @ref{Mark Ring}.
114 120
115 @kindex C-@@ 121 @kindex C-@@
116 There is no such character as @kbd{C-@key{SPC}} in ASCII; when you 122 There is no such character as @kbd{C-@key{SPC}} in @acronym{ASCII};
117 type @key{SPC} while holding down @key{CTRL}, what you get on most 123 when you type @key{SPC} while holding down @key{CTRL} on a text
118 ordinary terminals is the character @kbd{C-@@}. This key is actually 124 terminal, what you get is the character @kbd{C-@@}. This key is also
119 bound to @code{set-mark-command}. But unless you are unlucky enough to 125 bound to @code{set-mark-command}--so unless you are unlucky enough to
120 have a terminal where typing @kbd{C-@key{SPC}} does not produce 126 have a text terminal where typing @kbd{C-@key{SPC}} does not produce
121 @kbd{C-@@}, you might as well think of this character as 127 @kbd{C-@@}, you might as well think of this character as
122 @kbd{C-@key{SPC}}. Under X, @kbd{C-@key{SPC}} is actually a distinct 128 @kbd{C-@key{SPC}}.
123 character, but its binding is still @code{set-mark-command}.
124 129
125 @node Transient Mark 130 @node Transient Mark
126 @section Transient Mark Mode 131 @section Transient Mark Mode
127 @cindex mode, Transient Mark 132 @cindex mode, Transient Mark
128 @cindex Transient Mark mode 133 @cindex Transient Mark mode
180 deactivates the mark. This means any subsequent command that operates 185 deactivates the mark. This means any subsequent command that operates
181 on a region will get an error and refuse to operate. You can make the 186 on a region will get an error and refuse to operate. You can make the
182 region active again by typing @kbd{C-x C-x}. 187 region active again by typing @kbd{C-x C-x}.
183 188
184 @item 189 @item
190 If Delete Selection mode is also enabled, some commands delete the
191 region when used while the mark is active. @xref{Graphical Kill}.
192
193 @item
185 Quitting with @kbd{C-g} deactivates the mark. 194 Quitting with @kbd{C-g} deactivates the mark.
186 195
187 @item 196 @item
188 Commands like @kbd{M->} and @kbd{C-s}, that ``leave the mark behind'' in 197 Commands like @kbd{M->} and @kbd{C-s}, that ``leave the mark behind'' in
189 addition to some other primary purpose, do not activate the new mark. 198 addition to some other primary purpose, do not activate the new mark.
190 You can activate the new region by executing @kbd{C-x C-x} 199 You can activate the new region by executing @kbd{C-x C-x}
191 (@code{exchange-point-and-mark}). 200 (@code{exchange-point-and-mark}).
192 201
193 @item 202 @item
194 @kbd{C-s} when the mark is active does not alter the mark. 203 Commands that normally set the mark before moving long distances (like
204 @kbd{M-<} and @kbd{C-s}) do not alter the mark in Transient Mark mode
205 when the mark is active.
195 206
196 @item 207 @item
197 Some commands operate on the region if a region is active. For 208 Some commands operate on the region if a region is active. For
198 instance, @kbd{C-x u} in Transient Mark mode operates on the region, 209 instance, @kbd{C-x u} in Transient Mark mode operates on the region,
199 when there is a region. (Outside Transient Mark mode, you must type 210 when there is a region. (Outside Transient Mark mode, you must type
245 not really a separate command; you are using the @kbd{C-@key{SPC}} 256 not really a separate command; you are using the @kbd{C-@key{SPC}}
246 command twice.) 257 command twice.)
247 258
248 @item C-u C-x C-x 259 @item C-u C-x C-x
249 @kindex C-u C-x C-x 260 @kindex C-u C-x C-x
250 Activate the mark without changing it, enable Transient Mark mode just 261 Activate the mark without changing it; enable Transient Mark mode just
251 once until the mark is deactivated. (This is the @kbd{C-x C-x} command, 262 once, until the mark is deactivated. (This is the @kbd{C-x C-x}
252 @code{exchange-point-and-mark}, with a prefix argument.) 263 command, @code{exchange-point-and-mark}, with a prefix argument.)
253 @end table 264 @end table
254 265
255 One of the secondary features of Transient Mark mode is that certain 266 One of the secondary features of Transient Mark mode is that certain
256 commands operate on the region when there is an active region. If you 267 commands operate only on the region, when there is an active region.
257 don't use Transient Mark mode, the region once set never becomes 268 If you don't use Transient Mark mode, the region once set never
258 inactive, so there is no way these commands to make such a 269 becomes inactive, so there is no way for these commands to make such a
259 distinction. Enabling Transient Mark mode momentarily gives you a way 270 distinction. Enabling Transient Mark mode momentarily gives you a way
260 to use these commands on the region. 271 to use these commands on the region.
261 272
262 The other way momentarily use of Transient Mark mode is useful 273 Momentary use of Transient Mark mode is also a way to highlight the
263 is that it highlights the region for the time being. 274 region for the time being.
264 275
265 @node Using Region 276 @node Using Region
266 @section Operating on the Region 277 @section Operating on the Region
267 278
268 @cindex operations on a marked region 279 @cindex operations on a marked region
281 @item 292 @item
282 Indent it with @kbd{C-x @key{TAB}} or @kbd{C-M-\} (@pxref{Indentation}). 293 Indent it with @kbd{C-x @key{TAB}} or @kbd{C-M-\} (@pxref{Indentation}).
283 @item 294 @item
284 Fill it as text with @kbd{M-x fill-region} (@pxref{Filling}). 295 Fill it as text with @kbd{M-x fill-region} (@pxref{Filling}).
285 @item 296 @item
286 Print hardcopy with @kbd{M-x print-region} (@pxref{Hardcopy}). 297 Print hardcopy with @kbd{M-x print-region} (@pxref{Printing}).
287 @item 298 @item
288 Evaluate it as Lisp code with @kbd{M-x eval-region} (@pxref{Lisp Eval}). 299 Evaluate it as Lisp code with @kbd{M-x eval-region} (@pxref{Lisp Eval}).
289 @end itemize 300 @end itemize
290 301
291 Most commands that operate on the text in the region have the word 302 Most commands that operate on the text in the region have the word
316 327
317 @kbd{M-@@} (@code{mark-word}) puts the mark at the end of the next 328 @kbd{M-@@} (@code{mark-word}) puts the mark at the end of the next
318 word, while @kbd{C-M-@@} (@code{mark-sexp}) puts it at the end of the 329 word, while @kbd{C-M-@@} (@code{mark-sexp}) puts it at the end of the
319 next balanced expression (@pxref{Expressions}). These commands handle 330 next balanced expression (@pxref{Expressions}). These commands handle
320 arguments just like @kbd{M-f} and @kbd{C-M-f}. If you repeat these 331 arguments just like @kbd{M-f} and @kbd{C-M-f}. If you repeat these
321 commands, the region is extended. For example, you can type either 332 commands, that extends the region. For example, you can type either
322 @kbd{C-u 2 M-@@} or @kbd{M-@@ M-@@} to mark the next two words. 333 @kbd{C-u 2 M-@@} or @kbd{M-@@ M-@@} to mark the next two words. This
334 command also extends the region when the mark is active in Transient
335 Mark mode, regardless of the last command.
323 336
324 @kindex C-x h 337 @kindex C-x h
325 @findex mark-whole-buffer 338 @findex mark-whole-buffer
326 Other commands set both point and mark, to delimit an object in the 339 Other commands set both point and mark, to delimit an object in the
327 buffer. For example, @kbd{M-h} (@code{mark-paragraph}) moves point to 340 buffer. For example, @kbd{M-h} (@code{mark-paragraph}) moves point to
331 paragraph. With prefix argument, if the argument's value is positive, 344 paragraph. With prefix argument, if the argument's value is positive,
332 @kbd{M-h} marks that many paragraphs starting with the one surrounding 345 @kbd{M-h} marks that many paragraphs starting with the one surrounding
333 point. If the prefix argument is @minus{}@var{n}, @kbd{M-h} also 346 point. If the prefix argument is @minus{}@var{n}, @kbd{M-h} also
334 marks @var{n} paragraphs, running back form the one surrounding point. 347 marks @var{n} paragraphs, running back form the one surrounding point.
335 In that last case, point moves forward to the end of that paragraph, 348 In that last case, point moves forward to the end of that paragraph,
336 and the mark goes at the start of the region. The @kbd{M-h} command 349 and the mark goes at the start of the region. Repeating the @kbd{M-h}
337 also supports the extension of the region, similar to @kbd{M-@@} and 350 command extends the region, just as with @kbd{M-@@} and @kbd{C-M-@@}.
338 @kbd{C-M-@@}.
339 351
340 @kbd{C-M-h} (@code{mark-defun}) similarly puts point before, and the 352 @kbd{C-M-h} (@code{mark-defun}) similarly puts point before, and the
341 mark after, the current (or following) major top-level definition, or 353 mark after, the current (or following) major top-level definition, or
342 defun (@pxref{Moving by Defuns}). (Currently it only marks one defun, 354 defun (@pxref{Moving by Defuns}). Repeating @kbd{C-M-h} also extends
343 but repeating it marks more defuns, like for @kbd{M-@@}.) @kbd{C-x 355 the region.
344 C-p} (@code{mark-page}) puts point before the current page, and mark 356
345 at the end (@pxref{Pages}). The mark goes after the terminating page 357 @kbd{C-x C-p} (@code{mark-page}) puts point before the current page,
346 delimiter (to include it in the region), while point goes after the 358 and mark at the end (@pxref{Pages}). The mark goes after the
347 preceding page delimiter (to exclude it). A numeric argument 359 terminating page delimiter (to include it in the region), while point
348 specifies a later page (if positive) or an earlier page (if negative) 360 goes after the preceding page delimiter (to exclude it). A numeric
349 instead of the current page. 361 argument specifies a later page (if positive) or an earlier page (if
362 negative) instead of the current page.
350 363
351 Finally, @kbd{C-x h} (@code{mark-whole-buffer}) sets up the entire 364 Finally, @kbd{C-x h} (@code{mark-whole-buffer}) sets up the entire
352 buffer as the region, by putting point at the beginning and the mark at 365 buffer as the region, by putting point at the beginning and the mark at
353 the end. 366 the end.
354 367
368 C-@key{SPC}} (or @kbd{C-u C-@@}); this is the command 381 C-@key{SPC}} (or @kbd{C-u C-@@}); this is the command
369 @code{set-mark-command} given a numeric argument. It moves point to 382 @code{set-mark-command} given a numeric argument. It moves point to
370 where the mark was, and restores the mark from the ring of former 383 where the mark was, and restores the mark from the ring of former
371 marks. 384 marks.
372 385
373 If you repeat the character @kbd{C-@key{SPC}}, after typing @kbd{C-u 386 @vindex set-mark-command-repeat-pop
374 C-@key{SPC}}, each repetition moves point to a previous mark position 387 If you set @code{set-mark-command-repeat-pop} to non-@code{nil},
375 from the ring. The mark positions you move through in this way are 388 then when you repeat the character @kbd{C-@key{SPC}} after typing
376 not lost; they go to the end of the ring. 389 @kbd{C-u C-@key{SPC}}, each repetition moves point to a previous mark
390 position from the ring. The mark positions you move through in this
391 way are not lost; they go to the end of the ring.
377 392
378 Each buffer has its own mark ring. All editing commands use the current 393 Each buffer has its own mark ring. All editing commands use the current
379 buffer's mark ring. In particular, @kbd{C-u C-@key{SPC}} always stays in 394 buffer's mark ring. In particular, @kbd{C-u C-@key{SPC}} always stays in
380 the same buffer. 395 the same buffer.
381 396
382 Many commands that can move long distances, such as @kbd{M-<} 397 Many commands that can move long distances, such as @kbd{M-<}
383 (@code{beginning-of-buffer}), start by setting the mark and saving the 398 (@code{beginning-of-buffer}), start by setting the mark and saving the
384 old mark on the mark ring. This is to make it easier for you to move 399 old mark on the mark ring. This is to make it easier for you to move
385 back later. Searches set the mark if they move point. You can tell 400 back later. Searches set the mark if they move point. However, in
386 when a command sets the mark because it displays @samp{Mark set} in the 401 Transient Mark mode, these commands do not set the mark when the mark
387 echo area. 402 is already active. You can tell when a command sets the mark because
403 it displays @samp{Mark set} in the echo area.
388 404
389 If you want to move back to the same place over and over, the mark 405 If you want to move back to the same place over and over, the mark
390 ring may not be convenient enough. If so, you can record the position 406 ring may not be convenient enough. If so, you can record the position
391 in a register for later retrieval (@pxref{RegPos,, Saving Positions in 407 in a register for later retrieval (@pxref{RegPos,, Saving Positions in
392 Registers}). 408 Registers}).
423 The command @kbd{C-x C-@key{SPC}} (@code{pop-global-mark}) jumps to 439 The command @kbd{C-x C-@key{SPC}} (@code{pop-global-mark}) jumps to
424 the buffer and position of the latest entry in the global ring. It also 440 the buffer and position of the latest entry in the global ring. It also
425 rotates the ring, so that successive uses of @kbd{C-x C-@key{SPC}} take 441 rotates the ring, so that successive uses of @kbd{C-x C-@key{SPC}} take
426 you to earlier and earlier buffers. 442 you to earlier and earlier buffers.
427 443
444 @ignore
445 arch-tag: f35e4d82-911b-4cfc-a3d7-3c87b2abba20
446 @end ignore