41 |
* Setting Mark:: Commands to set the mark. |
* Setting Mark:: Commands to set the mark. |
42 |
* Transient Mark:: How to make Emacs highlight the region-- |
* Transient Mark:: How to make Emacs highlight the region-- |
43 |
when there is one. |
when there is one. |
44 |
|
* Momentary Mark:: Enabling Transient Mark mode momentarily. |
45 |
* Using Region:: Summary of ways to operate on contents of the region. |
* Using Region:: Summary of ways to operate on contents of the region. |
46 |
* Marking Objects:: Commands to put region around textual units. |
* Marking Objects:: Commands to put region around textual units. |
47 |
* Mark Ring:: Previous mark positions saved so you can go back there. |
* Mark Ring:: Previous mark positions saved so you can go back there. |
101 |
puts the mark where point was and point where the mark was. The extent |
puts the mark where point was and point where the mark was. The extent |
102 |
of the region is unchanged, but the cursor and point are now at the |
of the region is unchanged, but the cursor and point are now at the |
103 |
previous position of the mark. In Transient Mark mode, this command |
previous position of the mark. In Transient Mark mode, this command |
104 |
reactivates the mark. |
also reactivates the mark. |
105 |
|
|
106 |
@kbd{C-x C-x} is also useful when you are satisfied with the position |
@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 |
of point but want to move the other end of the region (where the mark |
129 |
@cindex highlighting region |
@cindex highlighting region |
130 |
@cindex region highlighting |
@cindex region highlighting |
131 |
|
|
132 |
On a terminal that supports colors, Emacs can highlight the current |
On a terminal that supports colors, Emacs has the ability to |
133 |
region. But normally it does not. Why not? |
highlight the current region. But normally it does not. Why not? |
134 |
|
|
135 |
Highlighting the region whenever it exists would not be desirable in |
Once you have set the mark in a buffer, there is @emph{always} a |
136 |
Emacs, because once you have set a mark, there is @emph{always} a |
region in that buffer. This is because every command that sets the |
137 |
region (in that buffer). And highlighting the region all the time |
mark also activates it, and nothing ever deactivates it. Highlighting |
138 |
would be a nuisance. So normally Emacs highlights the region only |
the region all the time would be a nuisance. So normally Emacs |
139 |
immediately after you have selected one with the mouse. |
highlights the region only immediately after you have selected one |
140 |
|
with the mouse. |
141 |
You can turn on region highlighting by enabling Transient Mark mode. |
|
142 |
This is a more rigid mode of operation in which the region ``lasts'' |
If you want region highlighting, you can use Transient Mark mode. |
143 |
only temporarily, so you must set up a region for each command that uses |
This is a more rigid mode of operation in which the region always |
144 |
one. In Transient Mark mode, most of the time there is no region; |
``lasts'' only until you use it; you explicitly must set up a region |
145 |
therefore, highlighting the region when it exists is useful and |
for each command that uses one. In Transient Mark mode, most of the |
146 |
not annoying. |
time there is no region; therefore, highlighting the region when it |
147 |
|
exists is useful and not annoying. When Transient Mark mode is |
148 |
|
enabled, Emacs always highlights the region whenever there is a |
149 |
|
region. |
150 |
|
|
151 |
@findex transient-mark-mode |
@findex transient-mark-mode |
152 |
To enable Transient Mark mode, type @kbd{M-x transient-mark-mode}. |
To enable Transient Mark mode, type @kbd{M-x transient-mark-mode}. |
153 |
This command toggles the mode, so you can repeat the command to turn off |
This command toggles the mode; you can use the same command to turn |
154 |
the mode. |
the mode off again. |
155 |
|
|
156 |
Here are the details of Transient Mark mode: |
Here are the details of Transient Mark mode: |
157 |
|
|
162 |
As you move point, you will see the highlighted region grow and |
As you move point, you will see the highlighted region grow and |
163 |
shrink. |
shrink. |
164 |
|
|
165 |
@item |
@item |
166 |
The mouse commands for specifying the mark also make it active. So do |
The mouse commands for specifying the mark also make it active. So do |
167 |
keyboard commands whose purpose is to specify a region, including |
keyboard commands whose purpose is to specify a region, including |
168 |
@kbd{M-@@}, @kbd{C-M-@@}, @kbd{M-h}, @kbd{C-M-h}, @kbd{C-x C-p}, and |
@kbd{M-@@}, @kbd{C-M-@@}, @kbd{M-h}, @kbd{C-M-h}, @kbd{C-x C-p}, and |
169 |
@kbd{C-x h}. |
@kbd{C-x h}. |
170 |
|
|
171 |
@item |
@item |
172 |
|
You can tell that the mark is active because the region is highlighted. |
173 |
|
|
174 |
|
@item |
175 |
When the mark is active, you can execute commands that operate on the |
When the mark is active, you can execute commands that operate on the |
176 |
region, such as killing, indenting, or writing to a file. |
region, such as killing, indenting, or writing to a file. |
177 |
|
|
182 |
region active again by typing @kbd{C-x C-x}. |
region active again by typing @kbd{C-x C-x}. |
183 |
|
|
184 |
@item |
@item |
185 |
|
Quitting with @kbd{C-g} deactivates the mark. |
186 |
|
|
187 |
|
@item |
188 |
Commands like @kbd{M->} and @kbd{C-s}, that ``leave the mark behind'' in |
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. |
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} |
You can activate the new region by executing @kbd{C-x C-x} |
194 |
@kbd{C-s} when the mark is active does not alter the mark. |
@kbd{C-s} when the mark is active does not alter the mark. |
195 |
|
|
196 |
@item |
@item |
197 |
Quitting with @kbd{C-g} deactivates the mark. |
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, |
199 |
@item |
when there is a region. (Outside Transient Mark mode, you must type |
200 |
Some commands operate on the region whenever it is active. For |
@kbd{C-u C-x u} if you want it to operate on the region.) |
201 |
instance, @kbd{C-x u} in Transient Mark mode operates on the region |
@xref{Undo}. Other commands that act this way are identified in their |
202 |
when there is a region. Outside Transient Mark mode, you must type |
own documentation. |
|
@kbd{C-u C-x u} if you want it to operate on the region. |
|
|
@xref{Undo}. Other commands that act this way are identified |
|
|
in their own documentation. |
|
203 |
@end itemize |
@end itemize |
204 |
|
|
205 |
The highlighting of the region uses the @code{region} face; you can |
The highlighting of the region uses the @code{region} face; you can |
215 |
each window highlights its own region (provided that Transient Mark mode |
each window highlights its own region (provided that Transient Mark mode |
216 |
is enabled and the mark in the window's buffer is active). |
is enabled and the mark in the window's buffer is active). |
217 |
|
|
|
When Transient Mark mode is not enabled, every command that sets the |
|
|
mark also activates it, and nothing ever deactivates it. |
|
|
|
|
218 |
@vindex mark-even-if-inactive |
@vindex mark-even-if-inactive |
219 |
If the variable @code{mark-even-if-inactive} is non-@code{nil} in |
If the variable @code{mark-even-if-inactive} is non-@code{nil} in |
220 |
Transient Mark mode, then commands can use the mark and the region |
Transient Mark mode, then commands can use the mark and the region |
221 |
even when it is inactive. Region highlighting appears and disappears |
even when it is inactive. Region highlighting appears and disappears |
222 |
just as it normally does in Transient Mark mode, but the mark doesn't |
just as it normally does in Transient Mark mode, but the mark doesn't |
223 |
really go away when the highlighting disappears. |
really go away when the highlighting disappears, so you can still use |
224 |
|
region commands. |
225 |
|
|
226 |
@cindex Zmacs mode |
@cindex Zmacs mode |
227 |
Transient Mark mode is also sometimes known as ``Zmacs mode'' |
Transient Mark mode is also sometimes known as ``Zmacs mode'' |
228 |
because the Zmacs editor on the MIT Lisp Machine handled the mark in a |
because the Zmacs editor on the MIT Lisp Machine handled the mark in a |
229 |
similar way. |
similar way. |
230 |
|
|
231 |
|
@node Momentary Mark |
232 |
|
@section Using Transient Mark Mode Momentarily |
233 |
|
|
234 |
|
If you don't like Transient Mark mode in general, you might still |
235 |
|
want to use it once in a while. To do this, type @kbd{C-@key{SPC} |
236 |
|
C-@key{SPC}} or @kbd{C-u C-x C-x}. These commands set or activate the |
237 |
|
mark, and enable Transient Mark mode only until the mark is |
238 |
|
deactivated. |
239 |
|
|
240 |
|
@table @kbd |
241 |
|
@item C-@key{SPC} C-@key{SPC} |
242 |
|
@kindex C-@key{SPC} C-@key{SPC} |
243 |
|
Set the mark at point (like plain @kbd{C-@key{SPC}}), and enable |
244 |
|
Transient Mark mode just once until the mark is deactivated. (This is |
245 |
|
not really a separate command; you are using the @kbd{C-@key{SPC}} |
246 |
|
command twice.) |
247 |
|
|
248 |
|
@item C-u C-x C-x |
249 |
|
@kindex C-u C-x C-x |
250 |
|
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, |
252 |
|
@code{exchange-point-and-mark}, with a prefix argument.) |
253 |
|
@end table |
254 |
|
|
255 |
|
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 |
257 |
|
don't use Transient Mark mode, the region once set never becomes |
258 |
|
inactive, so there is no way these commands to make such a |
259 |
|
distinction. Enabling Transient Mark mode momentarily gives you a way |
260 |
|
to use these commands on the region. |
261 |
|
|
262 |
|
The other way momentarily use of Transient Mark mode is useful |
263 |
|
is that it highlights the region for the time being. |
264 |
|
|
265 |
@node Using Region |
@node Using Region |
266 |
@section Operating on the Region |
@section Operating on the Region |
267 |
|
|
368 |
C-@key{SPC}} (or @kbd{C-u C-@@}); this is the command |
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 |
@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 |
where the mark was, and restores the mark from the ring of former |
371 |
marks. Thus, repeated use of this command moves point to all of the old |
marks. |
372 |
marks on the ring, one by one. The mark positions you move through in |
|
373 |
this way are not lost; they go to the end of the ring. |
If you repeat the character @kbd{C-@key{SPC}}, after typing @kbd{C-u |
374 |
|
C-@key{SPC}}, each repetition moves point to a previous mark position |
375 |
|
from the ring. The mark positions you move through in this way are |
376 |
|
not lost; they go to the end of the ring. |
377 |
|
|
378 |
Each buffer has its own mark ring. All editing commands use the current |
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 |
buffer's mark ring. In particular, @kbd{C-u C-@key{SPC}} always stays in |