Mercurial > emacs
comparison lispref/positions.texi @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 23a1cea22d13 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 @c -*-texinfo-*- | 1 @c -*-texinfo-*- |
2 @c This is part of the GNU Emacs Lisp Reference Manual. | 2 @c This is part of the GNU Emacs Lisp Reference Manual. |
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001 | 3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, |
4 @c Free Software Foundation, Inc. | 4 @c 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
5 @c See the file elisp.texi for copying conditions. | 5 @c See the file elisp.texi for copying conditions. |
6 @setfilename ../info/positions | 6 @setfilename ../info/positions |
7 @node Positions, Markers, Frames, Top | 7 @node Positions, Markers, Frames, Top |
8 @chapter Positions | 8 @chapter Positions |
9 @cindex position (in buffer) | 9 @cindex position (in buffer) |
13 (or before the first character, or after the last character), so we can | 13 (or before the first character, or after the last character), so we can |
14 speak of the character before or after a given position. However, we | 14 speak of the character before or after a given position. However, we |
15 often speak of the character ``at'' a position, meaning the character | 15 often speak of the character ``at'' a position, meaning the character |
16 after that position. | 16 after that position. |
17 | 17 |
18 Positions are usually represented as integers starting from 1, but can | 18 Positions are usually represented as integers starting from 1, but |
19 also be represented as @dfn{markers}---special objects that relocate | 19 can also be represented as @dfn{markers}---special objects that |
20 automatically when text is inserted or deleted so they stay with the | 20 relocate automatically when text is inserted or deleted so they stay |
21 surrounding characters. @xref{Markers}. | 21 with the surrounding characters. Functions that expect an argument to |
22 be a position (an integer), but accept a marker as a substitute, | |
23 normally ignore which buffer the marker points into; they convert the | |
24 marker to an integer, and use that integer, exactly as if you had | |
25 passed the integer as the argument, even if the marker points to the | |
26 ``wrong'' buffer. A marker that points nowhere cannot convert to an | |
27 integer; using it instead of an integer causes an error. | |
28 @xref{Markers}. | |
22 | 29 |
23 See also the ``field'' feature (@pxref{Fields}), which provides | 30 See also the ``field'' feature (@pxref{Fields}), which provides |
24 functions that are used by many cursor-motion commands. | 31 functions that are used by many cursor-motion commands. |
25 | 32 |
26 @menu | 33 @menu |
87 in effect, in which case it is the position of the end of the region | 94 in effect, in which case it is the position of the end of the region |
88 that you narrowed to. (@xref{Narrowing}.) | 95 that you narrowed to. (@xref{Narrowing}.) |
89 @end defun | 96 @end defun |
90 | 97 |
91 @defun buffer-end flag | 98 @defun buffer-end flag |
92 This function returns @code{(point-min)} if @var{flag} is less than 1, | 99 This function returns @code{(point-max)} if @var{flag} is greater than |
93 @code{(point-max)} otherwise. The argument @var{flag} must be a number. | 100 0, @code{(point-min)} otherwise. The argument @var{flag} must be a |
101 number. | |
94 @end defun | 102 @end defun |
95 | 103 |
96 @defun buffer-size &optional buffer | 104 @defun buffer-size &optional buffer |
97 This function returns the total number of characters in the current | 105 This function returns the total number of characters in the current |
98 buffer. In the absence of any narrowing (@pxref{Narrowing}), | 106 buffer. In the absence of any narrowing (@pxref{Narrowing}), |
158 @deffn Command forward-char &optional count | 166 @deffn Command forward-char &optional count |
159 @c @kindex beginning-of-buffer | 167 @c @kindex beginning-of-buffer |
160 @c @kindex end-of-buffer | 168 @c @kindex end-of-buffer |
161 This function moves point @var{count} characters forward, towards the | 169 This function moves point @var{count} characters forward, towards the |
162 end of the buffer (or backward, towards the beginning of the buffer, if | 170 end of the buffer (or backward, towards the beginning of the buffer, if |
163 @var{count} is negative). If the function attempts to move point past | 171 @var{count} is negative). If @var{count} is @code{nil}, the default |
164 the beginning or end of the buffer (or the limits of the accessible | 172 is 1. |
165 portion, when narrowing is in effect), an error is signaled with error | 173 |
166 code @code{beginning-of-buffer} or @code{end-of-buffer}. | 174 If this attempts to move past the beginning or end of the buffer (or |
175 the limits of the accessible portion, when narrowing is in effect), it | |
176 signals an error with error symbol @code{beginning-of-buffer} or | |
177 @code{end-of-buffer}. | |
167 | 178 |
168 In an interactive call, @var{count} is the numeric prefix argument. | 179 In an interactive call, @var{count} is the numeric prefix argument. |
169 @end deffn | 180 @end deffn |
170 | 181 |
171 @deffn Command backward-char &optional count | 182 @deffn Command backward-char &optional count |
172 This function moves point @var{count} characters backward, towards the | 183 This is just like @code{forward-char} except that it moves |
173 beginning of the buffer (or forward, towards the end of the buffer, if | 184 in the opposite direction. |
174 @var{count} is negative). If the function attempts to move point past | |
175 the beginning or end of the buffer (or the limits of the accessible | |
176 portion, when narrowing is in effect), an error is signaled with error | |
177 code @code{beginning-of-buffer} or @code{end-of-buffer}. | |
178 | |
179 In an interactive call, @var{count} is the numeric prefix argument. | |
180 @end deffn | 185 @end deffn |
181 | 186 |
182 @node Word Motion | 187 @node Word Motion |
183 @subsection Motion by Words | 188 @subsection Motion by Words |
184 | 189 |
185 These functions for parsing words use the syntax table to decide | 190 These functions for parsing words use the syntax table to decide |
186 whether a given character is part of a word. @xref{Syntax Tables}. | 191 whether a given character is part of a word. @xref{Syntax Tables}. |
187 | 192 |
188 @deffn Command forward-word count | 193 @deffn Command forward-word &optional count |
189 This function moves point forward @var{count} words (or backward if | 194 This function moves point forward @var{count} words (or backward if |
190 @var{count} is negative). ``Moving one word'' means moving until point | 195 @var{count} is negative). If @var{count} is @code{nil}, it moves |
191 crosses a word-constituent character and then encounters a | 196 forward one word. |
192 word-separator character. However, this function cannot move point past | 197 |
193 the boundary of the accessible portion of the buffer, or across a field | 198 ``Moving one word'' means moving until point crosses a |
194 boundary (@pxref{Fields}). The most common case of a field boundary is | 199 word-constituent character and then encounters a word-separator |
195 the end of the prompt in the minibuffer. | 200 character. However, this function cannot move point past the boundary |
201 of the accessible portion of the buffer, or across a field boundary | |
202 (@pxref{Fields}). The most common case of a field boundary is the end | |
203 of the prompt in the minibuffer. | |
196 | 204 |
197 If it is possible to move @var{count} words, without being stopped | 205 If it is possible to move @var{count} words, without being stopped |
198 prematurely by the buffer boundary or a field boundary, the value is | 206 prematurely by the buffer boundary or a field boundary, the value is |
199 @code{t}. Otherwise, the return value is @code{nil} and point stops at | 207 @code{t}. Otherwise, the return value is @code{nil} and point stops at |
200 the buffer boundary or field boundary. | 208 the buffer boundary or field boundary. |
201 | 209 |
202 If @code{inhibit-field-text-motion} is non-@code{nil}, | 210 If @code{inhibit-field-text-motion} is non-@code{nil}, |
203 this function ignores field boundaries. | 211 this function ignores field boundaries. |
204 | 212 |
205 In an interactive call, @var{count} is specified by the numeric prefix | 213 In an interactive call, @var{count} is specified by the numeric prefix |
206 argument. | 214 argument. If @var{count} is omitted or @code{nil}, it defaults to 1. |
207 @end deffn | 215 @end deffn |
208 | 216 |
209 @deffn Command backward-word count | 217 @deffn Command backward-word &optional count |
210 This function is just like @code{forward-word}, except that it moves | 218 This function is just like @code{forward-word}, except that it moves |
211 backward until encountering the front of a word, rather than forward. | 219 backward until encountering the front of a word, rather than forward. |
212 | |
213 In an interactive call, @var{count} is set to the numeric prefix | |
214 argument. | |
215 | |
216 @c [Now optimized by compiler.] | |
217 @c This function is rarely used in programs, as it is more efficient to | |
218 @c call @code{forward-word} with a negative argument. | |
219 @end deffn | 220 @end deffn |
220 | 221 |
221 @defvar words-include-escapes | 222 @defvar words-include-escapes |
222 @c Emacs 19 feature | 223 @c Emacs 19 feature |
223 This variable affects the behavior of @code{forward-word} and everything | 224 This variable affects the behavior of @code{forward-word} and everything |
258 they set the mark and display messages in the echo area. | 259 they set the mark and display messages in the echo area. |
259 | 260 |
260 @deffn Command beginning-of-buffer &optional n | 261 @deffn Command beginning-of-buffer &optional n |
261 This function moves point to the beginning of the buffer (or the limits | 262 This function moves point to the beginning of the buffer (or the limits |
262 of the accessible portion, when narrowing is in effect), setting the | 263 of the accessible portion, when narrowing is in effect), setting the |
263 mark at the previous position. If @var{n} is non-@code{nil}, then it | 264 mark at the previous position (except in Transient Mark mode, if |
264 puts point @var{n} tenths of the way from the beginning of the | 265 the mark is already active, it does not set the mark.) |
265 accessible portion of the buffer. | 266 |
266 | 267 If @var{n} is non-@code{nil}, then it puts point @var{n} tenths of the |
267 In an interactive call, @var{n} is the numeric prefix argument, | 268 way from the beginning of the accessible portion of the buffer. In an |
268 if provided; otherwise @var{n} defaults to @code{nil}. | 269 interactive call, @var{n} is the numeric prefix argument, if provided; |
270 otherwise @var{n} defaults to @code{nil}. | |
269 | 271 |
270 @strong{Warning:} Don't use this function in Lisp programs! | 272 @strong{Warning:} Don't use this function in Lisp programs! |
271 @end deffn | 273 @end deffn |
272 | 274 |
273 @deffn Command end-of-buffer &optional n | 275 @deffn Command end-of-buffer &optional n |
274 This function moves point to the end of the buffer (or the limits of the | 276 This function moves point to the end of the buffer (or the limits of |
275 accessible portion, when narrowing is in effect), setting the mark at | 277 the accessible portion, when narrowing is in effect), setting the mark |
276 the previous position. If @var{n} is non-@code{nil}, then it puts point | 278 at the previous position (except in Transient Mark mode when the mark |
277 @var{n} tenths of the way from the end of the accessible portion of the | 279 is already active). If @var{n} is non-@code{nil}, then it puts point |
278 buffer. | 280 @var{n} tenths of the way from the end of the accessible portion of |
281 the buffer. | |
279 | 282 |
280 In an interactive call, @var{n} is the numeric prefix argument, | 283 In an interactive call, @var{n} is the numeric prefix argument, |
281 if provided; otherwise @var{n} defaults to @code{nil}. | 284 if provided; otherwise @var{n} defaults to @code{nil}. |
282 | 285 |
283 @strong{Warning:} Don't use this function in Lisp programs! | 286 @strong{Warning:} Don't use this function in Lisp programs! |
373 @cindex beginning of line | 376 @cindex beginning of line |
374 This function moves point forward @var{count} lines, to the beginning of | 377 This function moves point forward @var{count} lines, to the beginning of |
375 the line. If @var{count} is negative, it moves point | 378 the line. If @var{count} is negative, it moves point |
376 @minus{}@var{count} lines backward, to the beginning of a line. If | 379 @minus{}@var{count} lines backward, to the beginning of a line. If |
377 @var{count} is zero, it moves point to the beginning of the current | 380 @var{count} is zero, it moves point to the beginning of the current |
378 line. | 381 line. If @var{count} is @code{nil}, that means 1. |
379 | 382 |
380 If @code{forward-line} encounters the beginning or end of the buffer (or | 383 If @code{forward-line} encounters the beginning or end of the buffer (or |
381 of the accessible portion) before finding that many lines, it sets point | 384 of the accessible portion) before finding that many lines, it sets point |
382 there. No error is signaled. | 385 there. No error is signaled. |
383 | 386 |
389 In an interactive call, @var{count} is the numeric prefix argument. | 392 In an interactive call, @var{count} is the numeric prefix argument. |
390 @end deffn | 393 @end deffn |
391 | 394 |
392 @defun count-lines start end | 395 @defun count-lines start end |
393 @cindex lines in region | 396 @cindex lines in region |
397 @anchor{Definition of count-lines} | |
394 This function returns the number of lines between the positions | 398 This function returns the number of lines between the positions |
395 @var{start} and @var{end} in the current buffer. If @var{start} and | 399 @var{start} and @var{end} in the current buffer. If @var{start} and |
396 @var{end} are equal, then it returns 0. Otherwise it returns at least | 400 @var{end} are equal, then it returns 0. Otherwise it returns at least |
397 1, even if @var{start} and @var{end} are on the same line. This is | 401 1, even if @var{start} and @var{end} are on the same line. This is |
398 because the text between them, considered in isolation, must contain at | 402 because the text between them, considered in isolation, must contain at |
403 @example | 407 @example |
404 @group | 408 @group |
405 (defun current-line () | 409 (defun current-line () |
406 "Return the vertical position of point@dots{}" | 410 "Return the vertical position of point@dots{}" |
407 (+ (count-lines (window-start) (point)) | 411 (+ (count-lines (window-start) (point)) |
408 (if (= (current-column) 0) 1 0) | 412 (if (= (current-column) 0) 1 0))) |
409 -1)) | 413 @end group |
410 @end group | 414 @end example |
411 @end example | 415 @end defun |
416 | |
417 @defun line-number-at-pos &optional pos | |
418 @cindex line number | |
419 This function returns the line number in the current buffer | |
420 corresponding to the buffer position @var{pos}. If @var{pos} is @code{nil} | |
421 or omitted, the current buffer position is used. | |
412 @end defun | 422 @end defun |
413 | 423 |
414 @ignore | 424 @ignore |
415 @c ================ | 425 @c ================ |
416 The @code{previous-line} and @code{next-line} commands are functions | 426 The @code{previous-line} and @code{next-line} commands are functions |
572 | 582 |
573 The coordinate arguments @var{frompos} and @var{topos} are cons cells of | 583 The coordinate arguments @var{frompos} and @var{topos} are cons cells of |
574 the form @code{(@var{hpos} . @var{vpos})}. | 584 the form @code{(@var{hpos} . @var{vpos})}. |
575 | 585 |
576 The argument @var{width} is the number of columns available to display | 586 The argument @var{width} is the number of columns available to display |
577 text; this affects handling of continuation lines. Use the value | 587 text; this affects handling of continuation lines. @code{nil} means |
578 returned by @code{window-width} for the window of your choice; | 588 the actual number of usable text columns in the window, which is |
579 normally, use @code{(window-width @var{window})}. | 589 equivalent to the value returned by @code{(window-width window)}. |
580 | 590 |
581 The argument @var{offsets} is either @code{nil} or a cons cell of the | 591 The argument @var{offsets} is either @code{nil} or a cons cell of the |
582 form @code{(@var{hscroll} . @var{tab-offset})}. Here @var{hscroll} is | 592 form @code{(@var{hscroll} . @var{tab-offset})}. Here @var{hscroll} is |
583 the number of columns not being displayed at the left margin; most | 593 the number of columns not being displayed at the left margin; most |
584 callers get this by calling @code{window-hscroll}. Meanwhile, | 594 callers get this by calling @code{window-hscroll}. Meanwhile, |
624 (selected-window)))) | 634 (selected-window)))) |
625 @end example | 635 @end example |
626 | 636 |
627 When you use @code{compute-motion} for the minibuffer, you need to use | 637 When you use @code{compute-motion} for the minibuffer, you need to use |
628 @code{minibuffer-prompt-width} to get the horizontal position of the | 638 @code{minibuffer-prompt-width} to get the horizontal position of the |
629 beginning of the first screen line. @xref{Minibuffer Misc}. | 639 beginning of the first screen line. @xref{Minibuffer Contents}. |
630 @end defun | 640 @end defun |
631 | 641 |
632 @node List Motion | 642 @node List Motion |
633 @comment node-name, next, previous, up | 643 @comment node-name, next, previous, up |
634 @subsection Moving over Balanced Expressions | 644 @subsection Moving over Balanced Expressions |
639 Here are several functions concerned with balanced-parenthesis | 649 Here are several functions concerned with balanced-parenthesis |
640 expressions (also called @dfn{sexps} in connection with moving across | 650 expressions (also called @dfn{sexps} in connection with moving across |
641 them in Emacs). The syntax table controls how these functions interpret | 651 them in Emacs). The syntax table controls how these functions interpret |
642 various characters; see @ref{Syntax Tables}. @xref{Parsing | 652 various characters; see @ref{Syntax Tables}. @xref{Parsing |
643 Expressions}, for lower-level primitives for scanning sexps or parts of | 653 Expressions}, for lower-level primitives for scanning sexps or parts of |
644 sexps. For user-level commands, see @ref{Lists Commands,,, emacs, The GNU | 654 sexps. For user-level commands, see @ref{Parentheses,, Commands for |
645 Emacs Manual}. | 655 Editing with Parentheses, emacs, The GNU Emacs Manual}. |
646 | 656 |
647 @deffn Command forward-list &optional arg | 657 @deffn Command forward-list &optional arg |
648 This function moves forward across @var{arg} (default 1) balanced groups of | 658 This function moves forward across @var{arg} (default 1) balanced groups of |
649 parentheses. (Other syntactic entities such as words or paired string | 659 parentheses. (Other syntactic entities such as words or paired string |
650 quotes are ignored.) | 660 quotes are ignored.) |
660 This function moves forward out of @var{arg} (default 1) levels of parentheses. | 670 This function moves forward out of @var{arg} (default 1) levels of parentheses. |
661 A negative argument means move backward but still to a less deep spot. | 671 A negative argument means move backward but still to a less deep spot. |
662 @end deffn | 672 @end deffn |
663 | 673 |
664 @deffn Command down-list &optional arg | 674 @deffn Command down-list &optional arg |
665 This function moves forward into @var{arg} (default 1) levels of parentheses. A | 675 This function moves forward into @var{arg} (default 1) levels of |
666 negative argument means move backward but still go | 676 parentheses. A negative argument means move backward but still go |
667 deeper in parentheses (@minus{}@var{arg} levels). | 677 deeper in parentheses (@minus{}@var{arg} levels). |
668 @end deffn | 678 @end deffn |
669 | 679 |
670 @deffn Command forward-sexp &optional arg | 680 @deffn Command forward-sexp &optional arg |
671 This function moves forward across @var{arg} (default 1) balanced expressions. | 681 This function moves forward across @var{arg} (default 1) balanced expressions. |
693 | 703 |
694 @deffn Command backward-sexp &optional arg | 704 @deffn Command backward-sexp &optional arg |
695 This function moves backward across @var{arg} (default 1) balanced expressions. | 705 This function moves backward across @var{arg} (default 1) balanced expressions. |
696 @end deffn | 706 @end deffn |
697 | 707 |
698 @deffn Command beginning-of-defun arg | 708 @deffn Command beginning-of-defun &optional arg |
699 This function moves back to the @var{arg}th beginning of a defun. If | 709 This function moves back to the @var{arg}th beginning of a defun. If |
700 @var{arg} is negative, this actually moves forward, but it still moves | 710 @var{arg} is negative, this actually moves forward, but it still moves |
701 to the beginning of a defun, not to the end of one. | 711 to the beginning of a defun, not to the end of one. @var{arg} defaults |
702 @end deffn | 712 to 1. |
703 | 713 @end deffn |
704 @deffn Command end-of-defun arg | 714 |
715 @deffn Command end-of-defun &optional arg | |
705 This function moves forward to the @var{arg}th end of a defun. If | 716 This function moves forward to the @var{arg}th end of a defun. If |
706 @var{arg} is negative, this actually moves backward, but it still moves | 717 @var{arg} is negative, this actually moves backward, but it still moves |
707 to the end of a defun, not to the beginning of one. | 718 to the end of a defun, not to the beginning of one. @var{arg} defaults |
719 to 1. | |
708 @end deffn | 720 @end deffn |
709 | 721 |
710 @defopt defun-prompt-regexp | 722 @defopt defun-prompt-regexp |
711 If non-@code{nil}, this variable holds a regular expression that | 723 If non-@code{nil}, this buffer-local variable holds a regular |
712 specifies what text can appear before the open-parenthesis that starts a | 724 expression that specifies what text can appear before the |
713 defun. That is to say, a defun begins on a line that starts with a | 725 open-parenthesis that starts a defun. That is to say, a defun begins |
714 match for this regular expression, followed by a character with | 726 on a line that starts with a match for this regular expression, |
715 open-parenthesis syntax. | 727 followed by a character with open-parenthesis syntax. |
716 @end defopt | 728 @end defopt |
717 | 729 |
718 @defopt open-paren-in-column-0-is-defun-start | 730 @defopt open-paren-in-column-0-is-defun-start |
719 If this variable's value is non-@code{nil}, an open parenthesis in | 731 If this variable's value is non-@code{nil}, an open parenthesis in |
720 column 0 is considered to be the start of a defun. If it is | 732 column 0 is considered to be the start of a defun. If it is |
754 given set of characters. It examines the character following point, | 766 given set of characters. It examines the character following point, |
755 then advances point if the character matches @var{character-set}. This | 767 then advances point if the character matches @var{character-set}. This |
756 continues until it reaches a character that does not match. The | 768 continues until it reaches a character that does not match. The |
757 function returns the number of characters moved over. | 769 function returns the number of characters moved over. |
758 | 770 |
759 The argument @var{character-set} is like the inside of a | 771 The argument @var{character-set} is a string, like the inside of a |
760 @samp{[@dots{}]} in a regular expression except that @samp{]} is never | 772 @samp{[@dots{}]} in a regular expression except that @samp{]} does not |
761 special and @samp{\} quotes @samp{^}, @samp{-} or @samp{\}. Thus, | 773 terminate it, and @samp{\} quotes @samp{^}, @samp{-} or @samp{\}. |
762 @code{"a-zA-Z"} skips over all letters, stopping before the first | 774 Thus, @code{"a-zA-Z"} skips over all letters, stopping before the |
763 nonletter, and @code{"^a-zA-Z"} skips nonletters stopping before the | 775 first nonletter, and @code{"^a-zA-Z"} skips nonletters stopping before |
764 first letter. @xref{Regular Expressions}. | 776 the first letter. See @xref{Regular Expressions}. Character classes |
777 can also be used, e.g. @code{"[:alnum:]"}. See @pxref{Char Classes}. | |
765 | 778 |
766 If @var{limit} is supplied (it must be a number or a marker), it | 779 If @var{limit} is supplied (it must be a number or a marker), it |
767 specifies the maximum position in the buffer that point can be skipped | 780 specifies the maximum position in the buffer that point can be skipped |
768 to. Point will stop at or before @var{limit}. | 781 to. Point will stop at or before @var{limit}. |
769 | 782 |
787 ---------- Buffer: foo ---------- | 800 ---------- Buffer: foo ---------- |
788 I read "The cat in the hat@point{} | 801 I read "The cat in the hat@point{} |
789 comes back" twice. | 802 comes back" twice. |
790 ---------- Buffer: foo ---------- | 803 ---------- Buffer: foo ---------- |
791 @end group | 804 @end group |
792 @end example | |
793 | |
794 Note that char classes are not currently supported in | |
795 @var{character-set}; they will be treated as literals. Thus you | |
796 cannot use @code{"[:alpha:]"} instead of @code{"a-zA-Z"} to include | |
797 non-ASCII letters. A way to skip forward over all letters is: | |
798 | |
799 @example | |
800 (re-search-forward "\\=[[:alpha:]]*" nil t) | |
801 @end example | 805 @end example |
802 @end defun | 806 @end defun |
803 | 807 |
804 @defun skip-chars-backward character-set &optional limit | 808 @defun skip-chars-backward character-set &optional limit |
805 This function moves point backward, skipping characters that match | 809 This function moves point backward, skipping characters that match |
823 | 827 |
824 The forms for saving and restoring the configuration of windows are | 828 The forms for saving and restoring the configuration of windows are |
825 described elsewhere (see @ref{Window Configurations}, and @pxref{Frame | 829 described elsewhere (see @ref{Window Configurations}, and @pxref{Frame |
826 Configurations}). | 830 Configurations}). |
827 | 831 |
828 @defspec save-excursion forms@dots{} | 832 @defspec save-excursion body@dots{} |
829 @cindex mark excursion | 833 @cindex mark excursion |
830 @cindex point excursion | 834 @cindex point excursion |
831 @cindex current buffer excursion | 835 @cindex current buffer excursion |
832 The @code{save-excursion} special form saves the identity of the current | 836 The @code{save-excursion} special form saves the identity of the current |
833 buffer and the values of point and the mark in it, evaluates | 837 buffer and the values of point and the mark in it, evaluates |
834 @var{forms}, and finally restores the buffer and its saved values of | 838 @var{body}, and finally restores the buffer and its saved values of |
835 point and the mark. All three saved values are restored even in case of | 839 point and the mark. All three saved values are restored even in case of |
836 an abnormal exit via @code{throw} or error (@pxref{Nonlocal Exits}). | 840 an abnormal exit via @code{throw} or error (@pxref{Nonlocal Exits}). |
837 | 841 |
838 The @code{save-excursion} special form is the standard way to switch | 842 The @code{save-excursion} special form is the standard way to switch |
839 buffers or move point within one part of a program and avoid affecting | 843 buffers or move point within one part of a program and avoid affecting |
849 correspondences altered by functions such as @code{switch-to-buffer}. | 853 correspondences altered by functions such as @code{switch-to-buffer}. |
850 One way to restore these correspondences, and the selected window, is to | 854 One way to restore these correspondences, and the selected window, is to |
851 use @code{save-window-excursion} inside @code{save-excursion} | 855 use @code{save-window-excursion} inside @code{save-excursion} |
852 (@pxref{Window Configurations}). | 856 (@pxref{Window Configurations}). |
853 | 857 |
854 The value returned by @code{save-excursion} is the result of the last of | 858 The value returned by @code{save-excursion} is the result of the last |
855 @var{forms}, or @code{nil} if no @var{forms} are given. | 859 form in @var{body}, or @code{nil} if no body forms were given. |
856 | 860 |
857 @example | 861 @example |
858 @group | 862 @group |
859 (save-excursion @var{forms}) | 863 (save-excursion @var{forms}) |
860 @equiv{} | 864 @equiv{} |
872 @end example | 876 @end example |
873 @end defspec | 877 @end defspec |
874 | 878 |
875 @strong{Warning:} Ordinary insertion of text adjacent to the saved | 879 @strong{Warning:} Ordinary insertion of text adjacent to the saved |
876 point value relocates the saved value, just as it relocates all markers. | 880 point value relocates the saved value, just as it relocates all markers. |
877 Therefore, when the saved point value is restored, it normally comes | 881 More precisely, the saved value is a marker with insertion type |
878 before the inserted text. | 882 @code{nil}. @xref{Marker Insertion Types}. Therefore, when the saved |
883 point value is restored, it normally comes before the inserted text. | |
879 | 884 |
880 Although @code{save-excursion} saves the location of the mark, it does | 885 Although @code{save-excursion} saves the location of the mark, it does |
881 not prevent functions which modify the buffer from setting | 886 not prevent functions which modify the buffer from setting |
882 @code{deactivate-mark}, and thus causing the deactivation of the mark | 887 @code{deactivate-mark}, and thus causing the deactivation of the mark |
883 after the command finishes. @xref{The Mark}. | 888 after the command finishes. @xref{The Mark}. |
914 | 919 |
915 In an interactive call, @var{start} and @var{end} are set to the bounds | 920 In an interactive call, @var{start} and @var{end} are set to the bounds |
916 of the current region (point and the mark, with the smallest first). | 921 of the current region (point and the mark, with the smallest first). |
917 @end deffn | 922 @end deffn |
918 | 923 |
919 @deffn Command narrow-to-page move-count | 924 @deffn Command narrow-to-page &optional move-count |
920 This function sets the accessible portion of the current buffer to | 925 This function sets the accessible portion of the current buffer to |
921 include just the current page. An optional first argument | 926 include just the current page. An optional first argument |
922 @var{move-count} non-@code{nil} means to move forward or backward by | 927 @var{move-count} non-@code{nil} means to move forward or backward by |
923 @var{move-count} pages and then narrow to one page. The variable | 928 @var{move-count} pages and then narrow to one page. The variable |
924 @code{page-delimiter} specifies where pages start and end | 929 @code{page-delimiter} specifies where pages start and end |
994 This is the contents of foo@point{} | 999 This is the contents of foo@point{} |
995 ---------- Buffer: foo ---------- | 1000 ---------- Buffer: foo ---------- |
996 @end group | 1001 @end group |
997 @end example | 1002 @end example |
998 @end defspec | 1003 @end defspec |
1004 | |
1005 @ignore | |
1006 arch-tag: 56e8ff26-4ffe-4832-a141-7e991a2d0f87 | |
1007 @end ignore |