XEmacs 21.2-b1
[chise/xemacs-chise.git.1] / man / xemacs / mark.texi
1
2 @node Mark, Mouse Selection, Help, Top
3 @chapter Selecting Text
4 @cindex mark
5 @cindex region
6
7   Many Emacs commands operate on an arbitrary contiguous
8 part of the current buffer. You can select text in two ways:
9
10 @itemize @bullet
11 @item
12 You use special keys to select text by defining a region between point
13 and the mark. 
14 @item
15 If you are running XEmacs under X, you can also select text
16 with the mouse. 
17 @end itemize
18
19 @section The Mark and the Region
20  To specify the text for a command to operate on, set @dfn{the
21 mark} at one end of it, and move point to the other end.  The text
22 between point and the mark is called @dfn{the region}.  You can move
23 point or the mark to adjust the boundaries of the region.  It doesn't
24 matter which one is set first chronologically, or which one comes
25 earlier in the text.
26   
27   Once the mark has been set, it remains until it is set again at
28 another place.  The mark remains fixed with respect to the preceding
29 character if text is inserted or deleted in a buffer.  Each Emacs
30 buffer has its own mark; when you return to a buffer that had been
31 selected previously, it has the same mark it had before.
32
33   Many commands that insert text, such as @kbd{C-y} (@code{yank}) and
34 @kbd{M-x insert-buffer}, position the mark at one end of the inserted
35 text---the opposite end from where point is positioned, so that the region
36 contains the text just inserted.
37
38   Aside from delimiting the region, the mark is useful for marking
39 a spot that you may want to go back to.  To make this feature more useful,
40 Emacs remembers 16 previous locations of the mark in the @code{mark ring}.
41
42 @menu
43 * Setting Mark::        Commands to set the mark.
44 * Using Region::        Summary of ways to operate on contents of the region.
45 * Marking Objects::     Commands to put region around textual units.
46 * Mark Ring::           Previous mark positions saved so you can go back there.
47 @end menu
48
49 @node Setting Mark, Using Region, Mark, Mark
50 @subsection Setting the Mark
51
52   Here are some commands for setting the mark:
53
54 @c WideCommands
55 @table @kbd
56 @item C-@key{SPC}
57 Set the mark where point is (@code{set-mark-command}).
58 @item C-@@
59 The same.
60 @item C-x C-x
61 Interchange mark and point (@code{exchange-point-and-mark}).
62 @item C-<
63 Pushes a mark at the beginning of the buffer.
64 @item C->
65 Pushes a mark at the end of the buffer.
66 @end table
67
68   For example, to convert part of the buffer to all
69 upper-case, you can use the @kbd{C-x C-u} (@code{upcase-region})
70 command, which operates on the text in the region.  First go to the
71 beginning of the text you want to capitalize and type @kbd{C-@key{SPC}} to
72 put the mark there, then move to the end, and then type @kbd{C-x C-u} to
73 capitalize the selected region.  You can also set the mark at the end of the
74 text, move to the beginning, and then type @kbd{C-x C-u}.  Most commands
75 that operate on the text in the region have the word @code{region} in
76 their names.
77
78 @kindex C-SPC
79 @findex set-mark-command
80   The most common way to set the mark is with the @kbd{C-@key{SPC}}
81 command (@code{set-mark-command}).  This command sets the mark where
82 point is. You can then move point away, leaving the mark behind.  It is
83 actually incorrect to speak of the character @kbd{C-@key{SPC}}; there is
84 no such character.  When you type @key{SPC} while holding down
85 @key{CTRL}, you get the character @kbd{C-@@} on most terminals. This
86 character is actually bound to @code{set-mark-command}.  But unless you are
87 unlucky enough to have a terminal where typing @kbd{C-@key{SPC}} does
88 not produce @kbd{C-@@}, you should think of this character as
89 @kbd{C-@key{SPC}}.
90
91 @kindex C-x C-x
92 @findex exchange-point-and-mark
93   Since terminals have only one cursor, Emacs cannot show you where the
94 mark is located. Most people use the mark soon after they set it, before
95 they forget where it is. But you can see where the mark is with the
96 command @kbd{C-x C-x} (@code{exchange-point-and-mark}) which puts the
97 mark where point was and point where the mark was.  The extent of the
98 region is unchanged, but the cursor and point are now at the previous
99 location of the mark. 
100
101 @kindex C-<
102 @kindex C->
103 @findex mark-beginning-of-buffer
104 @findex mark-end-of-buffer
105  Another way to set the mark is to push the mark to the beginning of a
106 buffer while leaving point at its original location. If you supply an
107 argument to @kbd{C-<} (@code{mark-beginning-of-buffer}), the mark is pushed
108 @var{n}/10 of the way from the true beginning of the buffer. You can
109 also set the mark at the end of a buffer with @kbd{C->}
110 (@code{mark-end-of-buffer}). It pushes the mark to the end of the buffer, 
111 leaving point alone. Supplying an argument to the command pushes the mark
112 @var{n}/10 of the way from the true end of the buffer.
113
114 If you are using XEmacs under the X window system, you can set
115 the variable @code{zmacs-regions} to @code{t}. This makes the current
116 region (defined by point and mark) highlight and makes it available as
117 the X clipboard selection, which means you can use the menu bar items on
118 it.  @xref{Active Regions} for more information.
119  
120   @kbd{C-x C-x} is also useful when you are satisfied with the location of
121 point but want to move the mark; do @kbd{C-x C-x} to put point there and
122 then you can move it.  A second use of @kbd{C-x C-x}, if necessary, puts
123 the mark at the new location with point back at its original location.
124
125 @node Using Region, Marking Objects, Setting Mark, Mark
126 @subsection Operating on the Region
127
128   Once you have created an active region, you can do many things to
129 the text in it:
130 @itemize @bullet
131 @item
132 Kill it with @kbd{C-w} (@pxref{Killing}).
133 @item
134 Save it in a register with @kbd{C-x r s} (@pxref{Registers}).
135 @item
136 Save it in a buffer or a file (@pxref{Accumulating Text}).
137 @item
138 Convert case with @kbd{C-x C-l} or @kbd{C-x C-u} @*(@pxref{Case}).
139 @item
140 Evaluate it as Lisp code with @kbd{M-x eval-region} (@pxref{Lisp Eval}).
141 @item
142 Fill it as text with @kbd{M-q} (@pxref{Filling}).
143 @item
144 Print hardcopy with @kbd{M-x print-region} (@pxref{Hardcopy}).
145 @item
146 Indent it with @kbd{C-x @key{TAB}} or @kbd{C-M-\} (@pxref{Indentation}).
147 @end itemize
148
149 @node Marking Objects, Mark Ring, Using Region, Mark
150 @subsection Commands to Mark Textual Objects
151
152   There are commands for placing point and the mark around a textual
153 object such as a word, list, paragraph or page.
154  
155 @table @kbd
156 @item M-@@
157 Set mark after end of next word (@code{mark-word}).  This command and
158 the following one do not move point.
159 @item C-M-@@
160 Set mark after end of next Lisp expression (@code{mark-sexp}).
161 @item M-h
162 Put region around current paragraph (@code{mark-paragraph}).
163 @item C-M-h
164 Put region around current Lisp defun (@code{mark-defun}).
165 @item C-x h
166 Put region around entire buffer (@code{mark-whole-buffer}).
167 @item C-x C-p
168 Put region around current page (@code{mark-page}).
169 @end table
170
171 @kindex M-@@
172 @kindex C-M-@@
173 @findex mark-word
174 @findex mark-sexp
175 @kbd{M-@@} (@code{mark-word}) puts the mark at the end of the next word,
176 while @kbd{C-M-@@} (@code{mark-sexp}) puts it at the end of the next Lisp
177 expression. These characters sometimes save you some typing.
178
179 @kindex M-h
180 @kindex C-M-h
181 @kindex C-x C-p
182 @kindex C-x h
183 @findex mark-paragraph
184 @findex mark-defun
185 @findex mark-page
186 @findex mark-whole-buffer
187    A number of commands are available that set both point and mark and
188 thus delimit an object in the buffer.  @kbd{M-h} (@code{mark-paragraph})
189 moves point to the beginning of the paragraph that surrounds or follows
190 point, and puts the mark at the end of that paragraph
191 (@pxref{Paragraphs}).  You can then indent, case-convert, or kill the
192 whole paragraph.  In the same fashion, @kbd{C-M-h} (@code{mark-defun})
193 puts point before and the mark after the current or following defun
194 (@pxref{Defuns}).  @kbd{C-x C-p} (@code{mark-page}) puts point before
195 the current page (or the next or previous, depending on the argument),
196 and mark at the end (@pxref{Pages}).  The mark goes after the
197 terminating page delimiter (to include it), while point goes after the
198 preceding page delimiter (to exclude it).  Finally, @kbd{C-x h}
199 (@code{mark-whole-buffer}) sets up the entire buffer as the region by
200 putting point at the beginning and the mark at the end.
201
202 @node Mark Ring,, Marking Objects, Mark
203 @subsection The Mark Ring
204
205 @kindex C-u C-SPC
206 @cindex mark ring
207 @kindex C-u C-@@
208   Aside from delimiting the region, the mark is also useful for marking
209 a spot that you may want to go back to.  To make this feature more
210 useful, Emacs remembers 16 previous locations of the mark in the
211 @dfn{mark ring}.  Most commands that set the mark push the old mark onto
212 this ring.  To return to a marked location, use @kbd{C-u C-@key{SPC}}
213 (or @kbd{C-u C-@@}); this is the command @code{set-mark-command} given a
214 numeric argument.  The command moves point to where the mark was, and
215 restores the mark from the ring of former marks. Repeated use of this
216 command moves point to all the old marks on the ring, one by one.
217 The marks you have seen go to the end of the ring, so no marks are lost.
218
219   Each buffer has its own mark ring.  All editing commands use the current
220 buffer's mark ring.  In particular, @kbd{C-u C-@key{SPC}} always stays in
221 the same buffer.
222
223   Many commands that can move long distances, such as @kbd{M-<}
224 (@code{beginning-of-buffer}), start by setting the mark and saving the
225 old mark on the mark ring.  This makes it easier for you to move back
226 later.  Searches set the mark, unless they do not actually move point.
227 When a command sets the mark, @samp{Mark Set} is printed in the
228 echo area.
229
230 @vindex mark-ring-max
231   The variable @code{mark-ring-max} is the maximum number of entries to
232 keep in the mark ring.  If that many entries exist and another entry is
233 added, the last entry in the list is discarded.  Repeating @kbd{C-u
234 C-@key{SPC}} circulates through the entries that are currently in the
235 ring.
236
237 @vindex mark-ring
238   The variable @code{mark-ring} holds the mark ring itself, as a list of
239 marker objects in the order most recent first.  This variable is local
240 in every buffer.