Mercurial > emacs
annotate lispref/markers.texi @ 53059:0aa1869956b7
*** empty log message ***
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Fri, 14 Nov 2003 16:23:12 +0000 |
parents | 8383c6d510e2 |
children | b0b3d8b864b8 |
rev | line source |
---|---|
6444 | 1 @c -*-texinfo-*- |
2 @c This is part of the GNU Emacs Lisp Reference Manual. | |
27189 | 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
46339
diff
changeset
|
4 @c Free Software Foundation, Inc. |
6444 | 5 @c See the file elisp.texi for copying conditions. |
6 @setfilename ../info/markers | |
7 @node Markers, Text, Positions, Top | |
8 @chapter Markers | |
9 @cindex markers | |
10 | |
11 A @dfn{marker} is a Lisp object used to specify a position in a buffer | |
12 relative to the surrounding text. A marker changes its offset from the | |
13 beginning of the buffer automatically whenever text is inserted or | |
14 deleted, so that it stays with the two characters on either side of it. | |
15 | |
16 @menu | |
17 * Overview of Markers:: The components of a marker, and how it relocates. | |
18 * Predicates on Markers:: Testing whether an object is a marker. | |
19 * Creating Markers:: Making empty markers or markers at certain places. | |
20 * Information from Markers:: Finding the marker's buffer or character position. | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
21 * Marker Insertion Types:: Two ways a marker can relocate when you |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
22 insert where it points. |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
23 * Moving Markers:: Moving the marker to a new buffer or position. |
6444 | 24 * The Mark:: How ``the mark'' is implemented with a marker. |
25 * The Region:: How to access ``the region''. | |
26 @end menu | |
27 | |
28 @node Overview of Markers | |
29 @section Overview of Markers | |
30 | |
31 A marker specifies a buffer and a position in that buffer. The marker | |
32 can be used to represent a position in the functions that require one, | |
33 just as an integer could be used. @xref{Positions}, for a complete | |
34 description of positions. | |
35 | |
36 A marker has two attributes: the marker position, and the marker | |
7729
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
37 buffer. The marker position is an integer that is equivalent (at a |
6444 | 38 given time) to the marker as a position in that buffer. But the |
39 marker's position value can change often during the life of the marker. | |
40 Insertion and deletion of text in the buffer relocate the marker. The | |
41 idea is that a marker positioned between two characters remains between | |
42 those two characters despite insertion and deletion elsewhere in the | |
43 buffer. Relocation changes the integer equivalent of the marker. | |
44 | |
45 @cindex marker relocation | |
46 Deleting text around a marker's position leaves the marker between the | |
47 characters immediately before and after the deleted text. Inserting | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
48 text at the position of a marker normally leaves the marker either in |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
49 front of or after the new text, depending on the marker's @dfn{insertion |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
50 type} (@pxref{Marker Insertion Types})---unless the insertion is done |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
51 with @code{insert-before-markers} (@pxref{Insertion}). |
6444 | 52 |
53 @cindex marker garbage collection | |
54 Insertion and deletion in a buffer must check all the markers and | |
55 relocate them if necessary. This slows processing in a buffer with a | |
56 large number of markers. For this reason, it is a good idea to make a | |
57 marker point nowhere if you are sure you don't need it any more. | |
58 Unreferenced markers are garbage collected eventually, but until then | |
59 will continue to use time if they do point somewhere. | |
60 | |
61 @cindex markers as numbers | |
62 Because it is common to perform arithmetic operations on a marker | |
63 position, most of the arithmetic operations (including @code{+} and | |
64 @code{-}) accept markers as arguments. In such cases, the marker | |
65 stands for its current position. | |
66 | |
67 Here are examples of creating markers, setting markers, and moving point | |
68 to markers: | |
69 | |
70 @example | |
71 @group | |
72 ;; @r{Make a new marker that initially does not point anywhere:} | |
73 (setq m1 (make-marker)) | |
74 @result{} #<marker in no buffer> | |
75 @end group | |
76 | |
77 @group | |
78 ;; @r{Set @code{m1} to point between the 99th and 100th characters} | |
79 ;; @r{in the current buffer:} | |
80 (set-marker m1 100) | |
81 @result{} #<marker at 100 in markers.texi> | |
82 @end group | |
83 | |
84 @group | |
85 ;; @r{Now insert one character at the beginning of the buffer:} | |
86 (goto-char (point-min)) | |
87 @result{} 1 | |
88 (insert "Q") | |
89 @result{} nil | |
90 @end group | |
91 | |
92 @group | |
93 ;; @r{@code{m1} is updated appropriately.} | |
94 m1 | |
95 @result{} #<marker at 101 in markers.texi> | |
96 @end group | |
97 | |
98 @group | |
99 ;; @r{Two markers that point to the same position} | |
100 ;; @r{are not @code{eq}, but they are @code{equal}.} | |
101 (setq m2 (copy-marker m1)) | |
102 @result{} #<marker at 101 in markers.texi> | |
103 (eq m1 m2) | |
104 @result{} nil | |
105 (equal m1 m2) | |
106 @result{} t | |
107 @end group | |
108 | |
109 @group | |
110 ;; @r{When you are finished using a marker, make it point nowhere.} | |
111 (set-marker m1 nil) | |
112 @result{} #<marker in no buffer> | |
113 @end group | |
114 @end example | |
115 | |
116 @node Predicates on Markers | |
117 @section Predicates on Markers | |
118 | |
119 You can test an object to see whether it is a marker, or whether it is | |
120 either an integer or a marker. The latter test is useful in connection | |
121 with the arithmetic functions that work with both markers and integers. | |
122 | |
123 @defun markerp object | |
124 This function returns @code{t} if @var{object} is a marker, @code{nil} | |
125 otherwise. Note that integers are not markers, even though many | |
126 functions will accept either a marker or an integer. | |
127 @end defun | |
128 | |
129 @defun integer-or-marker-p object | |
130 This function returns @code{t} if @var{object} is an integer or a marker, | |
131 @code{nil} otherwise. | |
132 @end defun | |
133 | |
134 @defun number-or-marker-p object | |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
135 This function returns @code{t} if @var{object} is a number (either |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
136 integer or floating point) or a marker, @code{nil} otherwise. |
6444 | 137 @end defun |
138 | |
139 @node Creating Markers | |
25751
467b88fab665
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22252
diff
changeset
|
140 @section Functions that Create Markers |
6444 | 141 |
142 When you create a new marker, you can make it point nowhere, or point | |
143 to the present position of point, or to the beginning or end of the | |
144 accessible portion of the buffer, or to the same place as another given | |
145 marker. | |
146 | |
53036
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
147 The next four functions all return markers with insertion type |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
148 @code{nil}. @xref{Marker Insertion Types}. |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
149 |
6444 | 150 @defun make-marker |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
151 This function returns a newly created marker that does not point |
6444 | 152 anywhere. |
153 | |
154 @example | |
155 @group | |
156 (make-marker) | |
157 @result{} #<marker in no buffer> | |
158 @end group | |
159 @end example | |
160 @end defun | |
161 | |
162 @defun point-marker | |
163 This function returns a new marker that points to the present position | |
164 of point in the current buffer. @xref{Point}. For an example, see | |
165 @code{copy-marker}, below. | |
166 @end defun | |
167 | |
168 @defun point-min-marker | |
169 This function returns a new marker that points to the beginning of the | |
170 accessible portion of the buffer. This will be the beginning of the | |
171 buffer unless narrowing is in effect. @xref{Narrowing}. | |
172 @end defun | |
173 | |
174 @defun point-max-marker | |
175 @cindex end of buffer marker | |
176 This function returns a new marker that points to the end of the | |
177 accessible portion of the buffer. This will be the end of the buffer | |
178 unless narrowing is in effect. @xref{Narrowing}. | |
179 | |
180 Here are examples of this function and @code{point-min-marker}, shown in | |
181 a buffer containing a version of the source file for the text of this | |
182 chapter. | |
183 | |
184 @example | |
185 @group | |
186 (point-min-marker) | |
187 @result{} #<marker at 1 in markers.texi> | |
188 (point-max-marker) | |
189 @result{} #<marker at 15573 in markers.texi> | |
190 @end group | |
191 | |
192 @group | |
193 (narrow-to-region 100 200) | |
194 @result{} nil | |
195 @end group | |
196 @group | |
197 (point-min-marker) | |
198 @result{} #<marker at 100 in markers.texi> | |
199 @end group | |
200 @group | |
201 (point-max-marker) | |
202 @result{} #<marker at 200 in markers.texi> | |
203 @end group | |
204 @end example | |
205 @end defun | |
206 | |
53036
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
207 @defun copy-marker marker-or-integer &optional insertion-type |
6444 | 208 If passed a marker as its argument, @code{copy-marker} returns a |
209 new marker that points to the same place and the same buffer as does | |
210 @var{marker-or-integer}. If passed an integer as its argument, | |
211 @code{copy-marker} returns a new marker that points to position | |
212 @var{marker-or-integer} in the current buffer. | |
213 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
214 The new marker's insertion type is specified by the argument |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
215 @var{insertion-type}. @xref{Marker Insertion Types}. |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
216 |
6444 | 217 If passed an integer argument less than 1, @code{copy-marker} returns a |
218 new marker that points to the beginning of the current buffer. If | |
219 passed an integer argument greater than the length of the buffer, | |
220 @code{copy-marker} returns a new marker that points to the end of the | |
221 buffer. | |
222 | |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
223 @example |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
224 @group |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
225 (copy-marker 0) |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
226 @result{} #<marker at 1 in markers.texi> |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
227 @end group |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
228 |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
229 @group |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
230 (copy-marker 20000) |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
231 @result{} #<marker at 7572 in markers.texi> |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
232 @end group |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
233 @end example |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
234 |
6444 | 235 An error is signaled if @var{marker} is neither a marker nor an |
236 integer. | |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
237 @end defun |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
238 |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
239 Two distinct markers are considered @code{equal} (even though not |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
240 @code{eq}) to each other if they have the same position and buffer, or |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
241 if they both point nowhere. |
6444 | 242 |
243 @example | |
244 @group | |
245 (setq p (point-marker)) | |
246 @result{} #<marker at 2139 in markers.texi> | |
247 @end group | |
248 | |
249 @group | |
250 (setq q (copy-marker p)) | |
251 @result{} #<marker at 2139 in markers.texi> | |
252 @end group | |
253 | |
254 @group | |
255 (eq p q) | |
256 @result{} nil | |
257 @end group | |
258 | |
259 @group | |
260 (equal p q) | |
261 @result{} t | |
262 @end group | |
263 @end example | |
264 | |
265 @node Information from Markers | |
266 @section Information from Markers | |
267 | |
268 This section describes the functions for accessing the components of a | |
269 marker object. | |
270 | |
271 @defun marker-position marker | |
272 This function returns the position that @var{marker} points to, or | |
273 @code{nil} if it points nowhere. | |
274 @end defun | |
275 | |
276 @defun marker-buffer marker | |
277 This function returns the buffer that @var{marker} points into, or | |
278 @code{nil} if it points nowhere. | |
279 | |
280 @example | |
281 @group | |
282 (setq m (make-marker)) | |
283 @result{} #<marker in no buffer> | |
284 @end group | |
285 @group | |
286 (marker-position m) | |
287 @result{} nil | |
288 @end group | |
289 @group | |
290 (marker-buffer m) | |
291 @result{} nil | |
292 @end group | |
293 | |
294 @group | |
295 (set-marker m 3770 (current-buffer)) | |
296 @result{} #<marker at 3770 in markers.texi> | |
297 @end group | |
298 @group | |
299 (marker-buffer m) | |
300 @result{} #<buffer markers.texi> | |
301 @end group | |
302 @group | |
303 (marker-position m) | |
304 @result{} 3770 | |
305 @end group | |
306 @end example | |
307 @end defun | |
308 | |
26181 | 309 @defun buffer-has-markers-at position |
310 @tindex buffer-has-markers-at | |
311 This function returns @code{t} if one or more markers | |
312 point at position @var{position} in the current buffer. | |
313 @end defun | |
314 | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
315 @node Marker Insertion Types |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
316 @section Marker Insertion Types |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
317 |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
318 @cindex insertion type of a marker |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
319 When you insert text directly at the place where a marker points, |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
320 there are two possible ways to relocate that marker: it can point before |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
321 the inserted text, or point after it. You can specify which one a given |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
322 marker should do by setting its @dfn{insertion type}. Note that use of |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
323 @code{insert-before-markers} ignores markers' insertion types, always |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
324 relocating a marker to point after the inserted text. |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
325 |
53036
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
326 Most functions that create markers, without explicitly specifying an |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
327 insertion type, create them with insertion type @code{nil}. Also, the |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
328 mark has, by default, insertion type @code{nil}. |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
329 |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
330 @defun set-marker-insertion-type marker type |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
331 This function sets the insertion type of marker @var{marker} to |
22252
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
332 @var{type}. If @var{type} is @code{t}, @var{marker} will advance when |
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
333 text is inserted at its position. If @var{type} is @code{nil}, |
40089afa2b1d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
22138
diff
changeset
|
334 @var{marker} does not advance when text is inserted there. |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
335 @end defun |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
336 |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
337 @defun marker-insertion-type marker |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
338 This function reports the current insertion type of @var{marker}. |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
339 @end defun |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
340 |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
341 @node Moving Markers |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
342 @section Moving Marker Positions |
6444 | 343 |
344 This section describes how to change the position of an existing | |
345 marker. When you do this, be sure you know whether the marker is used | |
346 outside of your program, and, if so, what effects will result from | |
347 moving it---otherwise, confusing things may happen in other parts of | |
348 Emacs. | |
349 | |
350 @defun set-marker marker position &optional buffer | |
351 This function moves @var{marker} to @var{position} | |
352 in @var{buffer}. If @var{buffer} is not provided, it defaults to | |
353 the current buffer. | |
354 | |
355 If @var{position} is less than 1, @code{set-marker} moves @var{marker} | |
7729
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
356 to the beginning of the buffer. If @var{position} is greater than the |
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
357 size of the buffer, @code{set-marker} moves marker to the end of the |
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
358 buffer. If @var{position} is @code{nil} or a marker that points |
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
359 nowhere, then @var{marker} is set to point nowhere. |
6444 | 360 |
361 The value returned is @var{marker}. | |
362 | |
363 @example | |
364 @group | |
365 (setq m (point-marker)) | |
366 @result{} #<marker at 4714 in markers.texi> | |
367 @end group | |
368 @group | |
369 (set-marker m 55) | |
370 @result{} #<marker at 55 in markers.texi> | |
371 @end group | |
372 @group | |
373 (setq b (get-buffer "foo")) | |
374 @result{} #<buffer foo> | |
375 @end group | |
376 @group | |
377 (set-marker m 0 b) | |
378 @result{} #<marker at 1 in foo> | |
379 @end group | |
380 @end example | |
381 @end defun | |
382 | |
383 @defun move-marker marker position &optional buffer | |
384 This is another name for @code{set-marker}. | |
385 @end defun | |
386 | |
387 @node The Mark | |
388 @section The Mark | |
389 @cindex mark, the | |
390 @cindex mark ring | |
391 | |
392 One special marker in each buffer is designated @dfn{the mark}. It | |
393 records a position for the user for the sake of commands such as | |
22138
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
394 @code{kill-region} and @code{indent-rigidly}. Lisp programs should set |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
395 the mark only to values that have a potential use to the user, and never |
d4ac295a98b3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21682
diff
changeset
|
396 for their own internal purposes. For example, the @code{replace-regexp} |
6444 | 397 command sets the mark to the value of point before doing any |
398 replacements, because this enables the user to move back there | |
399 conveniently after the replace is finished. | |
400 | |
401 Many commands are designed so that when called interactively they | |
402 operate on the text between point and the mark. If you are writing such | |
403 a command, don't examine the mark directly; instead, use | |
404 @code{interactive} with the @samp{r} specification. This provides the | |
405 values of point and the mark as arguments to the command in an | |
406 interactive call, but permits other Lisp programs to specify arguments | |
407 explicitly. @xref{Interactive Codes}. | |
408 | |
409 Each buffer has its own value of the mark that is independent of the | |
410 value of the mark in other buffers. When a buffer is created, the mark | |
411 exists but does not point anywhere. We consider this state as ``the | |
7729
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
412 absence of a mark in that buffer.'' |
6444 | 413 |
414 Once the mark ``exists'' in a buffer, it normally never ceases to | |
415 exist. However, it may become @dfn{inactive}, if Transient Mark mode is | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
416 enabled. The variable @code{mark-active}, which is always buffer-local |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
417 in all buffers, indicates whether the mark is active: non-@code{nil} |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
418 means yes. A command can request deactivation of the mark upon return |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
419 to the editor command loop by setting @code{deactivate-mark} to a |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
420 non-@code{nil} value (but this causes deactivation only if Transient |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
421 Mark mode is enabled). |
6444 | 422 |
423 The main motivation for using Transient Mark mode is that this mode | |
424 also enables highlighting of the region when the mark is active. | |
425 @xref{Display}. | |
426 | |
427 In addition to the mark, each buffer has a @dfn{mark ring} which is a | |
428 list of markers containing previous values of the mark. When editing | |
429 commands change the mark, they should normally save the old value of the | |
430 mark on the mark ring. The variable @code{mark-ring-max} specifies the | |
431 maximum number of entries in the mark ring; once the list becomes this | |
432 long, adding a new element deletes the last element. | |
433 | |
26181 | 434 There is also a separate global mark ring, but that is used only in a |
435 few particular user-level commands, and is not relevant to Lisp | |
436 programming. So we do not describe it here. | |
437 | |
6444 | 438 @defun mark &optional force |
439 @cindex current buffer mark | |
440 This function returns the current buffer's mark position as an integer. | |
441 | |
53036
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
442 If Transient Mark mode is enabled, @code{mark-even-if-inactive} is |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
443 @code{nil} and and the mark is inactive, @code{mark} normally signals |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
444 an error. However, if @var{force} is non-@code{nil}, then @code{mark} |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
445 returns the mark position anyway---or @code{nil}, if the mark is not |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
446 yet set for this buffer. |
6444 | 447 @end defun |
448 | |
449 @defun mark-marker | |
450 This function returns the current buffer's mark. This is the very marker | |
7729
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
451 that records the mark location inside Emacs, not a copy. Therefore, |
6444 | 452 changing this marker's position will directly affect the position of the mark. |
453 Don't do it unless that is the effect you want. | |
454 | |
455 @example | |
456 @group | |
457 (setq m (mark-marker)) | |
458 @result{} #<marker at 3420 in markers.texi> | |
459 @end group | |
460 @group | |
461 (set-marker m 100) | |
462 @result{} #<marker at 100 in markers.texi> | |
463 @end group | |
464 @group | |
465 (mark-marker) | |
466 @result{} #<marker at 100 in markers.texi> | |
467 @end group | |
468 @end example | |
469 | |
470 Like any marker, this marker can be set to point at any buffer you like. | |
471 We don't recommend that you make it point at any buffer other than the | |
472 one of which it is the mark. If you do, it will yield perfectly | |
473 consistent, but rather odd, results. | |
474 @end defun | |
475 | |
476 @ignore | |
477 @deffn Command set-mark-command jump | |
478 If @var{jump} is @code{nil}, this command sets the mark to the value | |
479 of point and pushes the previous value of the mark on the mark ring. The | |
480 message @samp{Mark set} is also displayed in the echo area. | |
481 | |
482 If @var{jump} is not @code{nil}, this command sets point to the value | |
483 of the mark, and sets the mark to the previous saved mark value, which | |
484 is popped off the mark ring. | |
485 | |
486 This function is @emph{only} intended for interactive use. | |
487 @end deffn | |
488 @end ignore | |
489 | |
490 @defun set-mark position | |
491 This function sets the mark to @var{position}, and activates the mark. | |
492 The old value of the mark is @emph{not} pushed onto the mark ring. | |
493 | |
7734 | 494 @strong{Please note:} Use this function only if you want the user to |
6444 | 495 see that the mark has moved, and you want the previous mark position to |
496 be lost. Normally, when a new mark is set, the old one should go on the | |
497 @code{mark-ring}. For this reason, most applications should use | |
498 @code{push-mark} and @code{pop-mark}, not @code{set-mark}. | |
499 | |
500 Novice Emacs Lisp programmers often try to use the mark for the wrong | |
501 purposes. The mark saves a location for the user's convenience. An | |
502 editing command should not alter the mark unless altering the mark is | |
503 part of the user-level functionality of the command. (And, in that | |
504 case, this effect should be documented.) To remember a location for | |
505 internal use in the Lisp program, store it in a Lisp variable. For | |
506 example: | |
507 | |
508 @example | |
509 @group | |
510 (let ((beg (point))) | |
511 (forward-line 1) | |
512 (delete-region beg (point))). | |
513 @end group | |
514 @end example | |
515 @end defun | |
516 | |
517 @c for interactive use only | |
518 @ignore | |
519 @deffn Command exchange-point-and-mark | |
520 This function exchanges the positions of point and the mark. | |
521 It is intended for interactive use. | |
522 @end deffn | |
523 @end ignore | |
524 | |
525 @defun push-mark &optional position nomsg activate | |
526 This function sets the current buffer's mark to @var{position}, and | |
527 pushes a copy of the previous mark onto @code{mark-ring}. If | |
528 @var{position} is @code{nil}, then the value of point is used. | |
529 @code{push-mark} returns @code{nil}. | |
530 | |
531 The function @code{push-mark} normally @emph{does not} activate the | |
532 mark. To do that, specify @code{t} for the argument @var{activate}. | |
533 | |
534 A @samp{Mark set} message is displayed unless @var{nomsg} is | |
535 non-@code{nil}. | |
536 @end defun | |
537 | |
538 @defun pop-mark | |
539 This function pops off the top element of @code{mark-ring} and makes | |
540 that mark become the buffer's actual mark. This does not move point in | |
541 the buffer, and it does nothing if @code{mark-ring} is empty. It | |
542 deactivates the mark. | |
543 | |
544 The return value is not meaningful. | |
545 @end defun | |
546 | |
547 @defopt transient-mark-mode | |
548 @cindex Transient Mark mode | |
12098 | 549 This variable if non-@code{nil} enables Transient Mark mode, in which |
550 every buffer-modifying primitive sets @code{deactivate-mark}. The | |
551 consequence of this is that commands that modify the buffer normally | |
552 make the mark inactive. | |
6444 | 553 @end defopt |
554 | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
555 @defopt mark-even-if-inactive |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
556 If this is non-@code{nil}, Lisp programs and the Emacs user can use the |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
557 mark even when it is inactive. This option affects the behavior of |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
558 Transient Mark mode. When the option is non-@code{nil}, deactivation of |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
559 the mark turns off region highlighting, but commands that use the mark |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
560 behave as if the mark were still active. |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
561 @end defopt |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
562 |
6444 | 563 @defvar deactivate-mark |
564 If an editor command sets this variable non-@code{nil}, then the editor | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
565 command loop deactivates the mark after the command returns (if |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
566 Transient Mark mode is enabled). All the primitives that change the |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
567 buffer set @code{deactivate-mark}, to deactivate the mark when the |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
568 command is finished. |
46339
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
569 |
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
570 To write Lisp code that modifies the buffer without causing |
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
571 deactivation of the mark at the end of the command, bind |
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
572 @code{deactivate-mark} to @code{nil} around the code that does the |
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
573 modification. For example: |
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
574 |
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
575 @example |
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
576 (let (deactivate-mark) |
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
577 (insert " ")) |
469cf4d8b62b
Document binding `deactivate-mark' around something that modifies the
Richard M. Stallman <rms@gnu.org>
parents:
27189
diff
changeset
|
578 @end example |
6444 | 579 @end defvar |
580 | |
7729
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
581 @defun deactivate-mark |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
582 This function deactivates the mark, if Transient Mark mode is enabled. |
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
583 Otherwise it does nothing. |
7729
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
584 @end defun |
a1c07008521d
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
6444
diff
changeset
|
585 |
6444 | 586 @defvar mark-active |
587 The mark is active when this variable is non-@code{nil}. This variable | |
21682
90da2489c498
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
21007
diff
changeset
|
588 is always buffer-local in each buffer. |
6444 | 589 @end defvar |
590 | |
591 @defvar activate-mark-hook | |
592 @defvarx deactivate-mark-hook | |
593 These normal hooks are run, respectively, when the mark becomes active | |
21007
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
594 and when it becomes inactive. The hook @code{activate-mark-hook} is |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
595 also run at the end of a command if the mark is active and it is |
66d807bdc5b4
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
12098
diff
changeset
|
596 possible that the region may have changed. |
6444 | 597 @end defvar |
598 | |
599 @defvar mark-ring | |
600 The value of this buffer-local variable is the list of saved former | |
601 marks of the current buffer, most recent first. | |
602 | |
603 @example | |
604 @group | |
605 mark-ring | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
46339
diff
changeset
|
606 @result{} (#<marker at 11050 in markers.texi> |
6444 | 607 #<marker at 10832 in markers.texi> |
608 @dots{}) | |
609 @end group | |
610 @end example | |
611 @end defvar | |
612 | |
613 @defopt mark-ring-max | |
614 The value of this variable is the maximum size of @code{mark-ring}. If | |
615 more marks than this are pushed onto the @code{mark-ring}, | |
616 @code{push-mark} discards an old mark when it adds a new one. | |
617 @end defopt | |
618 | |
619 @node The Region | |
620 @section The Region | |
621 @cindex region, the | |
622 | |
623 The text between point and the mark is known as @dfn{the region}. | |
624 Various functions operate on text delimited by point and the mark, but | |
625 only those functions specifically related to the region itself are | |
626 described here. | |
627 | |
53036
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
628 The next two functions signal an error if the mark does not point |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
629 anywhere. If Transient Mark mode is enabled and |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
630 @code{mark-even-if-inactive} is @code{nil}, they also signal an error |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
631 if the mark is inactive. |
8383c6d510e2
(Creating Markers): Specify insertion type of created markers. Add
Luc Teirlinck <teirllm@auburn.edu>
parents:
52401
diff
changeset
|
632 |
6444 | 633 @defun region-beginning |
634 This function returns the position of the beginning of the region (as | |
635 an integer). This is the position of either point or the mark, | |
636 whichever is smaller. | |
637 @end defun | |
638 | |
639 @defun region-end | |
640 This function returns the position of the end of the region (as an | |
641 integer). This is the position of either point or the mark, whichever is | |
642 larger. | |
643 @end defun | |
644 | |
645 Few programs need to use the @code{region-beginning} and | |
646 @code{region-end} functions. A command designed to operate on a region | |
647 should normally use @code{interactive} with the @samp{r} specification | |
648 to find the beginning and end of the region. This lets other Lisp | |
649 programs specify the bounds explicitly as arguments. (@xref{Interactive | |
650 Codes}.) | |
52401 | 651 |
652 @ignore | |
653 arch-tag: b1ba2e7a-a0f3-4c5e-875c-7d8e22d73299 | |
654 @end ignore |