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