Commit | Line | Data |
---|---|---|
0abf66c5 RS |
1 | @c -*-texinfo-*- |
2 | @c This is part of the GNU Emacs Lisp Reference Manual. | |
fd897522 | 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999 |
177c0ea7 | 4 | @c Free Software Foundation, Inc. |
0abf66c5 RS |
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. | |
f9f59935 RS |
21 | * Marker Insertion Types:: Two ways a marker can relocate when you |
22 | insert where it points. | |
23 | * Moving Markers:: Moving the marker to a new buffer or position. | |
0abf66c5 RS |
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 | |
29679a81 | 37 | buffer. The marker position is an integer that is equivalent (at a |
0abf66c5 RS |
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 | |
969fe9b5 RS |
48 | text at the position of a marker normally leaves the marker either in |
49 | front of or after the new text, depending on the marker's @dfn{insertion | |
50 | type} (@pxref{Marker Insertion Types})---unless the insertion is done | |
51 | with @code{insert-before-markers} (@pxref{Insertion}). | |
0abf66c5 RS |
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 | |
a9f0a989 RS |
135 | This function returns @code{t} if @var{object} is a number (either |
136 | integer or floating point) or a marker, @code{nil} otherwise. | |
0abf66c5 RS |
137 | @end defun |
138 | ||
139 | @node Creating Markers | |
8241495d | 140 | @section Functions that Create Markers |
0abf66c5 RS |
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 | ||
147 | @defun make-marker | |
a9f0a989 | 148 | This function returns a newly created marker that does not point |
0abf66c5 RS |
149 | anywhere. |
150 | ||
151 | @example | |
152 | @group | |
153 | (make-marker) | |
154 | @result{} #<marker in no buffer> | |
155 | @end group | |
156 | @end example | |
157 | @end defun | |
158 | ||
159 | @defun point-marker | |
160 | This function returns a new marker that points to the present position | |
161 | of point in the current buffer. @xref{Point}. For an example, see | |
162 | @code{copy-marker}, below. | |
163 | @end defun | |
164 | ||
165 | @defun point-min-marker | |
166 | This function returns a new marker that points to the beginning of the | |
167 | accessible portion of the buffer. This will be the beginning of the | |
168 | buffer unless narrowing is in effect. @xref{Narrowing}. | |
169 | @end defun | |
170 | ||
171 | @defun point-max-marker | |
172 | @cindex end of buffer marker | |
173 | This function returns a new marker that points to the end of the | |
174 | accessible portion of the buffer. This will be the end of the buffer | |
175 | unless narrowing is in effect. @xref{Narrowing}. | |
176 | ||
177 | Here are examples of this function and @code{point-min-marker}, shown in | |
178 | a buffer containing a version of the source file for the text of this | |
179 | chapter. | |
180 | ||
181 | @example | |
182 | @group | |
183 | (point-min-marker) | |
184 | @result{} #<marker at 1 in markers.texi> | |
185 | (point-max-marker) | |
186 | @result{} #<marker at 15573 in markers.texi> | |
187 | @end group | |
188 | ||
189 | @group | |
190 | (narrow-to-region 100 200) | |
191 | @result{} nil | |
192 | @end group | |
193 | @group | |
194 | (point-min-marker) | |
195 | @result{} #<marker at 100 in markers.texi> | |
196 | @end group | |
197 | @group | |
198 | (point-max-marker) | |
199 | @result{} #<marker at 200 in markers.texi> | |
200 | @end group | |
201 | @end example | |
202 | @end defun | |
203 | ||
f9f59935 | 204 | @defun copy-marker marker-or-integer insertion-type |
0abf66c5 RS |
205 | If passed a marker as its argument, @code{copy-marker} returns a |
206 | new marker that points to the same place and the same buffer as does | |
207 | @var{marker-or-integer}. If passed an integer as its argument, | |
208 | @code{copy-marker} returns a new marker that points to position | |
209 | @var{marker-or-integer} in the current buffer. | |
210 | ||
f9f59935 RS |
211 | The new marker's insertion type is specified by the argument |
212 | @var{insertion-type}. @xref{Marker Insertion Types}. | |
213 | ||
0abf66c5 RS |
214 | If passed an integer argument less than 1, @code{copy-marker} returns a |
215 | new marker that points to the beginning of the current buffer. If | |
216 | passed an integer argument greater than the length of the buffer, | |
217 | @code{copy-marker} returns a new marker that points to the end of the | |
218 | buffer. | |
219 | ||
a9f0a989 RS |
220 | @example |
221 | @group | |
222 | (copy-marker 0) | |
223 | @result{} #<marker at 1 in markers.texi> | |
224 | @end group | |
225 | ||
226 | @group | |
227 | (copy-marker 20000) | |
228 | @result{} #<marker at 7572 in markers.texi> | |
229 | @end group | |
230 | @end example | |
231 | ||
0abf66c5 RS |
232 | An error is signaled if @var{marker} is neither a marker nor an |
233 | integer. | |
a9f0a989 RS |
234 | @end defun |
235 | ||
236 | Two distinct markers are considered @code{equal} (even though not | |
237 | @code{eq}) to each other if they have the same position and buffer, or | |
238 | if they both point nowhere. | |
0abf66c5 RS |
239 | |
240 | @example | |
241 | @group | |
242 | (setq p (point-marker)) | |
243 | @result{} #<marker at 2139 in markers.texi> | |
244 | @end group | |
245 | ||
246 | @group | |
247 | (setq q (copy-marker p)) | |
248 | @result{} #<marker at 2139 in markers.texi> | |
249 | @end group | |
250 | ||
251 | @group | |
252 | (eq p q) | |
253 | @result{} nil | |
254 | @end group | |
255 | ||
256 | @group | |
257 | (equal p q) | |
258 | @result{} t | |
259 | @end group | |
0abf66c5 | 260 | @end example |
0abf66c5 RS |
261 | |
262 | @node Information from Markers | |
263 | @section Information from Markers | |
264 | ||
265 | This section describes the functions for accessing the components of a | |
266 | marker object. | |
267 | ||
268 | @defun marker-position marker | |
269 | This function returns the position that @var{marker} points to, or | |
270 | @code{nil} if it points nowhere. | |
271 | @end defun | |
272 | ||
273 | @defun marker-buffer marker | |
274 | This function returns the buffer that @var{marker} points into, or | |
275 | @code{nil} if it points nowhere. | |
276 | ||
277 | @example | |
278 | @group | |
279 | (setq m (make-marker)) | |
280 | @result{} #<marker in no buffer> | |
281 | @end group | |
282 | @group | |
283 | (marker-position m) | |
284 | @result{} nil | |
285 | @end group | |
286 | @group | |
287 | (marker-buffer m) | |
288 | @result{} nil | |
289 | @end group | |
290 | ||
291 | @group | |
292 | (set-marker m 3770 (current-buffer)) | |
293 | @result{} #<marker at 3770 in markers.texi> | |
294 | @end group | |
295 | @group | |
296 | (marker-buffer m) | |
297 | @result{} #<buffer markers.texi> | |
298 | @end group | |
299 | @group | |
300 | (marker-position m) | |
301 | @result{} 3770 | |
302 | @end group | |
303 | @end example | |
304 | @end defun | |
305 | ||
75f3230b GM |
306 | @defun buffer-has-markers-at position |
307 | @tindex buffer-has-markers-at | |
308 | This function returns @code{t} if one or more markers | |
309 | point at position @var{position} in the current buffer. | |
310 | @end defun | |
311 | ||
f9f59935 RS |
312 | @node Marker Insertion Types |
313 | @section Marker Insertion Types | |
314 | ||
315 | @cindex insertion type of a marker | |
316 | When you insert text directly at the place where a marker points, | |
317 | there are two possible ways to relocate that marker: it can point before | |
318 | the inserted text, or point after it. You can specify which one a given | |
969fe9b5 RS |
319 | marker should do by setting its @dfn{insertion type}. Note that use of |
320 | @code{insert-before-markers} ignores markers' insertion types, always | |
321 | relocating a marker to point after the inserted text. | |
f9f59935 | 322 | |
f9f59935 RS |
323 | @defun set-marker-insertion-type marker type |
324 | This function sets the insertion type of marker @var{marker} to | |
1911e6e5 RS |
325 | @var{type}. If @var{type} is @code{t}, @var{marker} will advance when |
326 | text is inserted at its position. If @var{type} is @code{nil}, | |
327 | @var{marker} does not advance when text is inserted there. | |
f9f59935 RS |
328 | @end defun |
329 | ||
f9f59935 RS |
330 | @defun marker-insertion-type marker |
331 | This function reports the current insertion type of @var{marker}. | |
332 | @end defun | |
333 | ||
334 | @node Moving Markers | |
335 | @section Moving Marker Positions | |
0abf66c5 RS |
336 | |
337 | This section describes how to change the position of an existing | |
338 | marker. When you do this, be sure you know whether the marker is used | |
339 | outside of your program, and, if so, what effects will result from | |
340 | moving it---otherwise, confusing things may happen in other parts of | |
341 | Emacs. | |
342 | ||
343 | @defun set-marker marker position &optional buffer | |
344 | This function moves @var{marker} to @var{position} | |
345 | in @var{buffer}. If @var{buffer} is not provided, it defaults to | |
346 | the current buffer. | |
347 | ||
348 | If @var{position} is less than 1, @code{set-marker} moves @var{marker} | |
29679a81 RS |
349 | to the beginning of the buffer. If @var{position} is greater than the |
350 | size of the buffer, @code{set-marker} moves marker to the end of the | |
351 | buffer. If @var{position} is @code{nil} or a marker that points | |
352 | nowhere, then @var{marker} is set to point nowhere. | |
0abf66c5 RS |
353 | |
354 | The value returned is @var{marker}. | |
355 | ||
356 | @example | |
357 | @group | |
358 | (setq m (point-marker)) | |
359 | @result{} #<marker at 4714 in markers.texi> | |
360 | @end group | |
361 | @group | |
362 | (set-marker m 55) | |
363 | @result{} #<marker at 55 in markers.texi> | |
364 | @end group | |
365 | @group | |
366 | (setq b (get-buffer "foo")) | |
367 | @result{} #<buffer foo> | |
368 | @end group | |
369 | @group | |
370 | (set-marker m 0 b) | |
371 | @result{} #<marker at 1 in foo> | |
372 | @end group | |
373 | @end example | |
374 | @end defun | |
375 | ||
376 | @defun move-marker marker position &optional buffer | |
377 | This is another name for @code{set-marker}. | |
378 | @end defun | |
379 | ||
380 | @node The Mark | |
381 | @section The Mark | |
382 | @cindex mark, the | |
383 | @cindex mark ring | |
384 | ||
385 | One special marker in each buffer is designated @dfn{the mark}. It | |
386 | records a position for the user for the sake of commands such as | |
a9f0a989 RS |
387 | @code{kill-region} and @code{indent-rigidly}. Lisp programs should set |
388 | the mark only to values that have a potential use to the user, and never | |
389 | for their own internal purposes. For example, the @code{replace-regexp} | |
0abf66c5 RS |
390 | command sets the mark to the value of point before doing any |
391 | replacements, because this enables the user to move back there | |
392 | conveniently after the replace is finished. | |
393 | ||
394 | Many commands are designed so that when called interactively they | |
395 | operate on the text between point and the mark. If you are writing such | |
396 | a command, don't examine the mark directly; instead, use | |
397 | @code{interactive} with the @samp{r} specification. This provides the | |
398 | values of point and the mark as arguments to the command in an | |
399 | interactive call, but permits other Lisp programs to specify arguments | |
400 | explicitly. @xref{Interactive Codes}. | |
401 | ||
402 | Each buffer has its own value of the mark that is independent of the | |
403 | value of the mark in other buffers. When a buffer is created, the mark | |
404 | exists but does not point anywhere. We consider this state as ``the | |
29679a81 | 405 | absence of a mark in that buffer.'' |
0abf66c5 RS |
406 | |
407 | Once the mark ``exists'' in a buffer, it normally never ceases to | |
408 | exist. However, it may become @dfn{inactive}, if Transient Mark mode is | |
969fe9b5 RS |
409 | enabled. The variable @code{mark-active}, which is always buffer-local |
410 | in all buffers, indicates whether the mark is active: non-@code{nil} | |
411 | means yes. A command can request deactivation of the mark upon return | |
412 | to the editor command loop by setting @code{deactivate-mark} to a | |
413 | non-@code{nil} value (but this causes deactivation only if Transient | |
414 | Mark mode is enabled). | |
0abf66c5 RS |
415 | |
416 | The main motivation for using Transient Mark mode is that this mode | |
417 | also enables highlighting of the region when the mark is active. | |
418 | @xref{Display}. | |
419 | ||
420 | In addition to the mark, each buffer has a @dfn{mark ring} which is a | |
421 | list of markers containing previous values of the mark. When editing | |
422 | commands change the mark, they should normally save the old value of the | |
423 | mark on the mark ring. The variable @code{mark-ring-max} specifies the | |
424 | maximum number of entries in the mark ring; once the list becomes this | |
425 | long, adding a new element deletes the last element. | |
426 | ||
75f3230b GM |
427 | There is also a separate global mark ring, but that is used only in a |
428 | few particular user-level commands, and is not relevant to Lisp | |
429 | programming. So we do not describe it here. | |
430 | ||
0abf66c5 RS |
431 | @defun mark &optional force |
432 | @cindex current buffer mark | |
433 | This function returns the current buffer's mark position as an integer. | |
434 | ||
435 | If the mark is inactive, @code{mark} normally signals an error. | |
436 | However, if @var{force} is non-@code{nil}, then @code{mark} returns the | |
437 | mark position anyway---or @code{nil}, if the mark is not yet set for | |
438 | this buffer. | |
439 | @end defun | |
440 | ||
441 | @defun mark-marker | |
442 | This function returns the current buffer's mark. This is the very marker | |
29679a81 | 443 | that records the mark location inside Emacs, not a copy. Therefore, |
0abf66c5 RS |
444 | changing this marker's position will directly affect the position of the mark. |
445 | Don't do it unless that is the effect you want. | |
446 | ||
447 | @example | |
448 | @group | |
449 | (setq m (mark-marker)) | |
450 | @result{} #<marker at 3420 in markers.texi> | |
451 | @end group | |
452 | @group | |
453 | (set-marker m 100) | |
454 | @result{} #<marker at 100 in markers.texi> | |
455 | @end group | |
456 | @group | |
457 | (mark-marker) | |
458 | @result{} #<marker at 100 in markers.texi> | |
459 | @end group | |
460 | @end example | |
461 | ||
462 | Like any marker, this marker can be set to point at any buffer you like. | |
463 | We don't recommend that you make it point at any buffer other than the | |
464 | one of which it is the mark. If you do, it will yield perfectly | |
465 | consistent, but rather odd, results. | |
466 | @end defun | |
467 | ||
468 | @ignore | |
469 | @deffn Command set-mark-command jump | |
470 | If @var{jump} is @code{nil}, this command sets the mark to the value | |
471 | of point and pushes the previous value of the mark on the mark ring. The | |
472 | message @samp{Mark set} is also displayed in the echo area. | |
473 | ||
474 | If @var{jump} is not @code{nil}, this command sets point to the value | |
475 | of the mark, and sets the mark to the previous saved mark value, which | |
476 | is popped off the mark ring. | |
477 | ||
478 | This function is @emph{only} intended for interactive use. | |
479 | @end deffn | |
480 | @end ignore | |
481 | ||
482 | @defun set-mark position | |
483 | This function sets the mark to @var{position}, and activates the mark. | |
484 | The old value of the mark is @emph{not} pushed onto the mark ring. | |
485 | ||
ec221d13 | 486 | @strong{Please note:} Use this function only if you want the user to |
0abf66c5 RS |
487 | see that the mark has moved, and you want the previous mark position to |
488 | be lost. Normally, when a new mark is set, the old one should go on the | |
489 | @code{mark-ring}. For this reason, most applications should use | |
490 | @code{push-mark} and @code{pop-mark}, not @code{set-mark}. | |
491 | ||
492 | Novice Emacs Lisp programmers often try to use the mark for the wrong | |
493 | purposes. The mark saves a location for the user's convenience. An | |
494 | editing command should not alter the mark unless altering the mark is | |
495 | part of the user-level functionality of the command. (And, in that | |
496 | case, this effect should be documented.) To remember a location for | |
497 | internal use in the Lisp program, store it in a Lisp variable. For | |
498 | example: | |
499 | ||
500 | @example | |
501 | @group | |
502 | (let ((beg (point))) | |
503 | (forward-line 1) | |
504 | (delete-region beg (point))). | |
505 | @end group | |
506 | @end example | |
507 | @end defun | |
508 | ||
509 | @c for interactive use only | |
510 | @ignore | |
511 | @deffn Command exchange-point-and-mark | |
512 | This function exchanges the positions of point and the mark. | |
513 | It is intended for interactive use. | |
514 | @end deffn | |
515 | @end ignore | |
516 | ||
517 | @defun push-mark &optional position nomsg activate | |
518 | This function sets the current buffer's mark to @var{position}, and | |
519 | pushes a copy of the previous mark onto @code{mark-ring}. If | |
520 | @var{position} is @code{nil}, then the value of point is used. | |
521 | @code{push-mark} returns @code{nil}. | |
522 | ||
523 | The function @code{push-mark} normally @emph{does not} activate the | |
524 | mark. To do that, specify @code{t} for the argument @var{activate}. | |
525 | ||
526 | A @samp{Mark set} message is displayed unless @var{nomsg} is | |
527 | non-@code{nil}. | |
528 | @end defun | |
529 | ||
530 | @defun pop-mark | |
531 | This function pops off the top element of @code{mark-ring} and makes | |
532 | that mark become the buffer's actual mark. This does not move point in | |
533 | the buffer, and it does nothing if @code{mark-ring} is empty. It | |
534 | deactivates the mark. | |
535 | ||
536 | The return value is not meaningful. | |
537 | @end defun | |
538 | ||
539 | @defopt transient-mark-mode | |
540 | @cindex Transient Mark mode | |
bfe721d1 KH |
541 | This variable if non-@code{nil} enables Transient Mark mode, in which |
542 | every buffer-modifying primitive sets @code{deactivate-mark}. The | |
543 | consequence of this is that commands that modify the buffer normally | |
544 | make the mark inactive. | |
0abf66c5 RS |
545 | @end defopt |
546 | ||
969fe9b5 RS |
547 | @defopt mark-even-if-inactive |
548 | If this is non-@code{nil}, Lisp programs and the Emacs user can use the | |
549 | mark even when it is inactive. This option affects the behavior of | |
550 | Transient Mark mode. When the option is non-@code{nil}, deactivation of | |
551 | the mark turns off region highlighting, but commands that use the mark | |
552 | behave as if the mark were still active. | |
553 | @end defopt | |
554 | ||
0abf66c5 RS |
555 | @defvar deactivate-mark |
556 | If an editor command sets this variable non-@code{nil}, then the editor | |
969fe9b5 RS |
557 | command loop deactivates the mark after the command returns (if |
558 | Transient Mark mode is enabled). All the primitives that change the | |
559 | buffer set @code{deactivate-mark}, to deactivate the mark when the | |
560 | command is finished. | |
ce218967 RS |
561 | |
562 | To write Lisp code that modifies the buffer without causing | |
563 | deactivation of the mark at the end of the command, bind | |
564 | @code{deactivate-mark} to @code{nil} around the code that does the | |
565 | modification. For example: | |
566 | ||
567 | @example | |
568 | (let (deactivate-mark) | |
569 | (insert " ")) | |
570 | @end example | |
0abf66c5 RS |
571 | @end defvar |
572 | ||
29679a81 | 573 | @defun deactivate-mark |
969fe9b5 RS |
574 | This function deactivates the mark, if Transient Mark mode is enabled. |
575 | Otherwise it does nothing. | |
29679a81 RS |
576 | @end defun |
577 | ||
0abf66c5 RS |
578 | @defvar mark-active |
579 | The mark is active when this variable is non-@code{nil}. This variable | |
969fe9b5 | 580 | is always buffer-local in each buffer. |
0abf66c5 RS |
581 | @end defvar |
582 | ||
583 | @defvar activate-mark-hook | |
584 | @defvarx deactivate-mark-hook | |
585 | These normal hooks are run, respectively, when the mark becomes active | |
f9f59935 RS |
586 | and when it becomes inactive. The hook @code{activate-mark-hook} is |
587 | also run at the end of a command if the mark is active and it is | |
588 | possible that the region may have changed. | |
0abf66c5 RS |
589 | @end defvar |
590 | ||
591 | @defvar mark-ring | |
592 | The value of this buffer-local variable is the list of saved former | |
593 | marks of the current buffer, most recent first. | |
594 | ||
595 | @example | |
596 | @group | |
597 | mark-ring | |
177c0ea7 | 598 | @result{} (#<marker at 11050 in markers.texi> |
0abf66c5 RS |
599 | #<marker at 10832 in markers.texi> |
600 | @dots{}) | |
601 | @end group | |
602 | @end example | |
603 | @end defvar | |
604 | ||
605 | @defopt mark-ring-max | |
606 | The value of this variable is the maximum size of @code{mark-ring}. If | |
607 | more marks than this are pushed onto the @code{mark-ring}, | |
608 | @code{push-mark} discards an old mark when it adds a new one. | |
609 | @end defopt | |
610 | ||
611 | @node The Region | |
612 | @section The Region | |
613 | @cindex region, the | |
614 | ||
615 | The text between point and the mark is known as @dfn{the region}. | |
616 | Various functions operate on text delimited by point and the mark, but | |
617 | only those functions specifically related to the region itself are | |
618 | described here. | |
619 | ||
620 | @defun region-beginning | |
621 | This function returns the position of the beginning of the region (as | |
622 | an integer). This is the position of either point or the mark, | |
623 | whichever is smaller. | |
624 | ||
625 | If the mark does not point anywhere, an error is signaled. | |
626 | @end defun | |
627 | ||
628 | @defun region-end | |
629 | This function returns the position of the end of the region (as an | |
630 | integer). This is the position of either point or the mark, whichever is | |
631 | larger. | |
632 | ||
633 | If the mark does not point anywhere, an error is signaled. | |
634 | @end defun | |
635 | ||
636 | Few programs need to use the @code{region-beginning} and | |
637 | @code{region-end} functions. A command designed to operate on a region | |
638 | should normally use @code{interactive} with the @samp{r} specification | |
639 | to find the beginning and end of the region. This lets other Lisp | |
640 | programs specify the bounds explicitly as arguments. (@xref{Interactive | |
641 | Codes}.) | |
ab5796a9 MB |
642 | |
643 | @ignore | |
644 | arch-tag: b1ba2e7a-a0f3-4c5e-875c-7d8e22d73299 | |
645 | @end ignore |