annotate man/lispref/positions.texi @ 5940:c608d4b0b75e cygwin64 tip

rescue lost branch from 64bit.backup
author Henry Thompson <ht@markup.co.uk>
date Thu, 16 Dec 2021 18:48:58 +0000
parents 9fae6227ede5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @setfilename ../../info/positions.info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @node Positions, Markers, Consoles and Devices, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @chapter Positions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 @cindex position (in buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 A @dfn{position} is the index of a character in the text of a buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 More precisely, a position identifies the place between two characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 (or before the first character, or after the last character), so we can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 speak of the character before or after a given position. However, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 often speak of the character ``at'' a position, meaning the character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 after that position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 Positions are usually represented as integers starting from 1, but can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 also be represented as @dfn{markers}---special objects that relocate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 automatically when text is inserted or deleted so they stay with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 surrounding characters. @xref{Markers}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 * Point:: The special position where editing takes place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 * Motion:: Changing point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 * Excursions:: Temporary motion and buffer changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 * Narrowing:: Restricting editing to a portion of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
29 @node Point, Motion, Positions, Positions
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 @section Point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 @cindex point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 @dfn{Point} is a special buffer position used by many editing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 commands, including the self-inserting typed characters and text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 insertion functions. Other commands move point through the text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 to allow editing and insertion at different places.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 Like other positions, point designates a place between two characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 (or before the first character, or after the last character), rather
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 than a particular character. Usually terminals display the cursor over
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 the character that immediately follows point; point is actually before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 the character on which the cursor sits.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 @cindex point with narrowing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 The value of point is a number between 1 and the buffer size plus 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 If narrowing is in effect (@pxref{Narrowing}), then point is constrained
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 to fall within the accessible portion of the buffer (possibly at one end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 of it).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 Each buffer has its own value of point, which is independent of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 value of point in other buffers. Each window also has a value of point,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 which is independent of the value of point in other windows on the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 buffer. This is why point can have different values in various windows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 that display the same buffer. When a buffer appears in only one window,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 the buffer's point and the window's point normally have the same value,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 so the distinction is rarely important. @xref{Window Point}, for more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 @defun point &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 @cindex current buffer position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 This function returns the value of point in @var{buffer}, as an integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 @var{buffer} defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 @need 700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 @result{} 175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 @defun point-min &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 This function returns the minimum accessible value of point in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 @var{buffer}. This is normally 1, but if narrowing is in effect, it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 the position of the start of the region that you narrowed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (@xref{Narrowing}.) @var{buffer} defaults to the current buffer if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 @defun point-max &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 This function returns the maximum accessible value of point in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 @var{buffer}. This is @code{(1+ (buffer-size buffer))}, unless
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 narrowing is in effect, in which case it is the position of the end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 the region that you narrowed to. (@pxref{Narrowing}). @var{buffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 @defun buffer-end flag &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 This function returns @code{(point-min buffer)} if @var{flag} is less
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 than 1, @code{(point-max buffer)} otherwise. The argument @var{flag}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 must be a number. @var{buffer} defaults to the current buffer if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 @defun buffer-size &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 This function returns the total number of characters in @var{buffer}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 In the absence of any narrowing (@pxref{Narrowing}), @code{point-max}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 returns a value one larger than this. @var{buffer} defaults to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (buffer-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 @result{} 35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 (point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 @result{} 36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 @defvar buffer-saved-size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 The value of this buffer-local variable is the former length of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 current buffer, as of the last time it was read in, saved or auto-saved.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
119 @node Motion, Excursions, Point, Positions
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 @section Motion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 Motion functions change the value of point, either relative to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 current value of point, relative to the beginning or end of the buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 or relative to the edges of the selected window. @xref{Point}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 * Character Motion:: Moving in terms of characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 * Word Motion:: Moving in terms of words.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 * Buffer End Motion:: Moving to the beginning or end of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 * Text Lines:: Moving in terms of lines of text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 * Screen Lines:: Moving in terms of lines as displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 * List Motion:: Moving by parsing lists and sexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 * Skipping Characters:: Skipping characters belonging to a certain set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
136 @node Character Motion, Word Motion, Motion, Motion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 @subsection Motion by Characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 These functions move point based on a count of characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 @code{goto-char} is the fundamental primitive; the other functions use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 that.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 @deffn Command goto-char position &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 This function sets point in @code{buffer} to the value @var{position}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 If @var{position} is less than 1, it moves point to the beginning of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 buffer. If @var{position} is greater than the length of the buffer, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 moves point to the end. @var{buffer} defaults to the current buffer if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 If narrowing is in effect, @var{position} still counts from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 beginning of the buffer, but point cannot go outside the accessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 portion. If @var{position} is out of range, @code{goto-char} moves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 point to the beginning or the end of the accessible portion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 When this function is called interactively, @var{position} is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 numeric prefix argument, if provided; otherwise it is read from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 @code{goto-char} returns @var{position}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 @deffn Command forward-char &optional count buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 @c @kindex beginning-of-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 @c @kindex end-of-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 This function moves point @var{count} characters forward, towards the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 end of the buffer (or backward, towards the beginning of the buffer, if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 @var{count} is negative). If the function attempts to move point past
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 the beginning or end of the buffer (or the limits of the accessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 portion, when narrowing is in effect), an error is signaled with error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 code @code{beginning-of-buffer} or @code{end-of-buffer}. @var{buffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 In an interactive call, @var{count} is the numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 @deffn Command backward-char &optional count buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 This function moves point @var{count} characters backward, towards the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 beginning of the buffer (or forward, towards the end of the buffer, if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 @var{count} is negative). If the function attempts to move point past
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 the beginning or end of the buffer (or the limits of the accessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 portion, when narrowing is in effect), an error is signaled with error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 code @code{beginning-of-buffer} or @code{end-of-buffer}. @var{buffer}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 In an interactive call, @var{count} is the numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
190 @node Word Motion, Buffer End Motion, Character Motion, Motion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 @subsection Motion by Words
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 These functions for parsing words use the syntax table to decide
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 whether a given character is part of a word. @xref{Syntax Tables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
196 @deffn Command forward-word &optional count buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 This function moves point forward @var{count} words (or backward if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 @var{count} is negative). Normally it returns @code{t}. If this motion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 encounters the beginning or end of the buffer, or the limits of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 accessible portion when narrowing is in effect, point stops there and
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
201 the value is @code{nil}.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
202
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
203 @var{count} defaults to @code{1} and @var{buffer} defaults to the
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
204 current buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 In an interactive call, @var{count} is set to the numeric prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
210 @deffn Command backward-word &optional count buffer
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 This function is just like @code{forward-word}, except that it moves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 backward until encountering the front of a word, rather than forward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 @var{buffer} defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 In an interactive call, @var{count} is set to the numeric prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 @defvar words-include-escapes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 This variable affects the behavior of @code{forward-word} and everything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 that uses it. If it is non-@code{nil}, then characters in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 ``escape'' and ``character quote'' syntax classes count as part of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 words. Otherwise, they do not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
227 @node Buffer End Motion, Text Lines, Word Motion, Motion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 @subsection Motion to an End of the Buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 To move point to the beginning of the buffer, write:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 Likewise, to move to the end of the buffer, use:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 Here are two commands that users use to do these things. They are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 documented here to warn you not to use them in Lisp programs, because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 they set the mark and display messages in the echo area.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
251 @deffn Command beginning-of-buffer &optional count
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 This function moves point to the beginning of the buffer (or the limits
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 of the accessible portion, when narrowing is in effect), setting the
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
254 mark at the previous position. If @var{count} is non-@code{nil}, then it
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
255 puts point @var{count} tenths of the way from the beginning of the buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
257 In an interactive call, @var{count} is the numeric prefix argument,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
258 if provided; otherwise @var{count} defaults to @code{nil}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 Don't use this function in Lisp programs!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
263 @deffn Command end-of-buffer &optional count
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 This function moves point to the end of the buffer (or the limits of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 the accessible portion, when narrowing is in effect), setting the mark
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
266 at the previous position. If @var{count} is non-@code{nil}, then it puts
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
267 point @var{count} tenths of the way from the end of the buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
269 In an interactive call, @var{count} is the numeric prefix argument,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
270 if provided; otherwise @var{count} defaults to @code{nil}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 Don't use this function in Lisp programs!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
275 @node Text Lines, Screen Lines, Buffer End Motion, Motion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 @subsection Motion by Text Lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 @cindex lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 Text lines are portions of the buffer delimited by newline characters,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 which are regarded as part of the previous line. The first text line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 begins at the beginning of the buffer, and the last text line ends at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 the end of the buffer whether or not the last character is a newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 The division of the buffer into text lines is not affected by the width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 of the window, by line continuation in display, or by how tabs and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 control characters are displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 @deffn Command goto-line line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 This function moves point to the front of the @var{line}th line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 counting from line 1 at beginning of the buffer. If @var{line} is less
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 than 1, it moves point to the beginning of the buffer. If @var{line} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 greater than the number of lines in the buffer, it moves point to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 end of the buffer---that is, the @emph{end of the last line} of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 buffer. This is the only case in which @code{goto-line} does not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 necessarily move to the beginning of a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 If narrowing is in effect, then @var{line} still counts from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 beginning of the buffer, but point cannot go outside the accessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 portion. So @code{goto-line} moves point to the beginning or end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 accessible portion, if the line number specifies an inaccessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 The return value of @code{goto-line} is the difference between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 @var{line} and the line number of the line to which point actually was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 able to move (in the full buffer, before taking account of narrowing).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 Thus, the value is positive if the scan encounters the real end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 buffer. The value is zero if scan encounters the end of the accessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 portion but not the real end of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 In an interactive call, @var{line} is the numeric prefix argument if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 one has been provided. Otherwise @var{line} is read in the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 @deffn Command beginning-of-line &optional count buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 This function moves point to the beginning of the current line. With an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 argument @var{count} not @code{nil} or 1, it moves forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 @var{count}@minus{}1 lines and then to the beginning of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 @var{buffer} defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 If this function reaches the end of the buffer (or of the accessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 portion, if narrowing is in effect), it positions point there. No error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 @deffn Command end-of-line &optional count buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 This function moves point to the end of the current line. With an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 argument @var{count} not @code{nil} or 1, it moves forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 @var{count}@minus{}1 lines and then to the end of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 @var{buffer} defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 If this function reaches the end of the buffer (or of the accessible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 portion, if narrowing is in effect), it positions point there. No error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 @deffn Command forward-line &optional count buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 @cindex beginning of line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 This function moves point forward @var{count} lines, to the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 the line. If @var{count} is negative, it moves point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 @minus{}@var{count} lines backward, to the beginning of a line. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 @var{count} is zero, it moves point to the beginning of the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 line. @var{buffer} defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 If @code{forward-line} encounters the beginning or end of the buffer (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 of the accessible portion) before finding that many lines, it sets point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 there. No error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 @code{forward-line} returns the difference between @var{count} and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 number of lines actually moved. If you attempt to move down five lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 from the beginning of a buffer that has only three lines, point stops at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 the end of the last line, and the value will be 2.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 In an interactive call, @var{count} is the numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
355 @defun count-lines start end &optional ignore-invisible-lines-flag
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 @cindex lines in region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 This function returns the number of lines between the positions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 @var{start} and @var{end} in the current buffer. If @var{start} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 @var{end} are equal, then it returns 0. Otherwise it returns at least
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 1, even if @var{start} and @var{end} are on the same line. This is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 because the text between them, considered in isolation, must contain at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 least one line unless it is empty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
364 With optional @var{ignore-invisible-lines-flag} non-@code{nil}, lines
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
365 collapsed with selective-display are excluded from the line count.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
366
2214
0ac5faff7095 [xemacs-hg @ 2004-08-13 09:28:20 by stephent]
stephent
parents: 446
diff changeset
367 @strong{N.B.} The expression to return the current line number is not
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
368 obvious:
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
369
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
370 @example
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
371 (1+ (count-lines 1 (point-at-bol)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
372 @end example
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
373
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 Here is an example of using @code{count-lines}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (defun current-line ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 "Return the vertical position of point@dots{}"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (+ (count-lines (window-start) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (if (= (current-column) 0) 1 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 @ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 @c ================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 The @code{previous-line} and @code{next-line} commands are functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 that should not be used in programs. They are for users and are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 mentioned here only for completeness.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 @deffn Command previous-line count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 @cindex goal column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 This function moves point up @var{count} lines (down if @var{count}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 is negative). In moving, it attempts to keep point in the ``goal column''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (normally the same column that it was at the beginning of the move).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 If there is no character in the target line exactly under the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 column, point is positioned after the character in that line which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 spans this column, or at the end of the line if it is not long enough.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 If it attempts to move beyond the top or bottom of the buffer (or clipped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 region), then point is positioned in the goal column in the top or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 bottom line. No error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 In an interactive call, @var{count} will be the numeric
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 The command @code{set-goal-column} can be used to create a semipermanent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 goal column to which this command always moves. Then it does not try to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 move vertically.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 If you are thinking of using this in a Lisp program, consider using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 @code{forward-line} with a negative argument instead. It is usually easier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 to use and more reliable (no dependence on goal column, etc.).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 @deffn Command next-line count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 This function moves point down @var{count} lines (up if @var{count}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 is negative). In moving, it attempts to keep point in the ``goal column''
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (normally the same column that it was at the beginning of the move).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 If there is no character in the target line exactly under the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 column, point is positioned after the character in that line which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 spans this column, or at the end of the line if it is not long enough.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 If it attempts to move beyond the top or bottom of the buffer (or clipped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 region), then point is positioned in the goal column in the top or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 bottom line. No error is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 In the case where the @var{count} is 1, and point is on the last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 line of the buffer (or clipped region), a new empty line is inserted at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 end of the buffer (or clipped region) and point moved there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 In an interactive call, @var{count} will be the numeric
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 The command @code{set-goal-column} can be used to create a semipermanent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 goal column to which this command always moves. Then it does not try to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 move vertically.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 If you are thinking of using this in a Lisp program, consider using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 @code{forward-line} instead. It is usually easier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 to use and more reliable (no dependence on goal column, etc.).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 @c ================
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 Also see the functions @code{bolp} and @code{eolp} in @ref{Near Point}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 These functions do not move point, but test whether it is already at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 beginning or end of a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
455 @node Screen Lines, List Motion, Text Lines, Motion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 @subsection Motion by Screen Lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 The line functions in the previous section count text lines, delimited
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 only by newline characters. By contrast, these functions count screen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 lines, which are defined by the way the text appears on the screen. A
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 text line is a single screen line if it is short enough to fit the width
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 of the selected window, but otherwise it may occupy several screen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 In some cases, text lines are truncated on the screen rather than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 continued onto additional screen lines. In these cases,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 @code{vertical-motion} moves point much like @code{forward-line}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 @xref{Truncation}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 Because the width of a given string depends on the flags that control
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 the appearance of certain characters, @code{vertical-motion} behaves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 differently, for a given piece of text, depending on the buffer it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 in, and even on the selected window (because the width, the truncation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 flag, and display table may vary between windows). @xref{Usual
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 Display}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 These functions scan text to determine where screen lines break, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 thus take time proportional to the distance scanned. If you intend to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 use them heavily, Emacs provides caches which may improve the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 performance of your code. @xref{Text Lines, cache-long-line-scans}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 @defun vertical-motion count &optional window pixels
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 This function moves point to the start of the frame line @var{count}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 frame lines down from the frame line containing point. If @var{count}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 is negative, it moves up instead. The optional second argument
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
487 @var{window} may be used to specify a window other than the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 selected window in which to perform the motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 Normally, @code{vertical-motion} returns the number of lines moved. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 value may be less in absolute value than @var{count} if the beginning or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 end of the buffer was reached. If the optional third argument,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 @var{pixels} is non-@code{nil}, the vertical pixel height of the motion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 which took place is returned instead of the actual number of lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 moved. A motion of zero lines returns the height of the current line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 Note that @code{vertical-motion} sets @var{window}'s buffer's point, not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 @var{window}'s point. (This differs from FSF Emacs, which buggily always
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 sets current buffer's point, regardless of @var{window}.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 @defun vertical-motion-pixels count &optional window how
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 This function moves point to the start of the frame line @var{pixels}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 vertical pixels down from the frame line containing point, or up if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 @var{pixels} is negative. The optional second argument @var{window} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 the window to move in, and defaults to the selected window. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 optional third argument @var{how} specifies the stopping condition. A
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 2214
diff changeset
508 negative fixnum indicates that the motion should be no more
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 than @var{pixels}. A positive value indicates that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 motion should be at least @var{pixels}. Any other value indicates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 that the motion should be as close as possible to @var{pixels}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 @deffn Command move-to-window-line count &optional window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 This function moves point with respect to the text currently displayed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 in @var{window}, which defaults to the selected window. It moves point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 to the beginning of the screen line @var{count} screen lines from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 top of the window. If @var{count} is negative, that specifies a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 position @w{@minus{}@var{count}} lines from the bottom (or the last line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 of the buffer, if the buffer ends above the specified screen position).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 If @var{count} is @code{nil}, then point moves to the beginning of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 line in the middle of the window. If the absolute value of @var{count}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 is greater than the size of the window, then point moves to the place
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 that would appear on that screen line if the window were tall enough.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 This will probably cause the next redisplay to scroll to bring that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 location onto the screen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 In an interactive call, @var{count} is the numeric prefix argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 The value returned is the window line number point has moved to, with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 the top line in the window numbered 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 @ignore Not in XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 @defun compute-motion from frompos to topos width offsets window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 This function scans the current buffer, calculating screen positions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 It scans the buffer forward from position @var{from}, assuming that is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 at screen coordinates @var{frompos}, to position @var{to} or coordinates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 @var{topos}, whichever comes first. It returns the ending buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 position and screen coordinates.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 The coordinate arguments @var{frompos} and @var{topos} are cons cells of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 the form @code{(@var{hpos} . @var{vpos})}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 The argument @var{width} is the number of columns available to display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 text; this affects handling of continuation lines. Use the value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 returned by @code{window-width} for the window of your choice;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 normally, use @code{(window-width @var{window})}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 The argument @var{offsets} is either @code{nil} or a cons cell of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 form @code{(@var{hscroll} . @var{tab-offset})}. Here @var{hscroll} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 the number of columns not being displayed at the left margin; most
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 callers get this from @code{window-hscroll}. Meanwhile,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 @var{tab-offset} is the offset between column numbers on the screen and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 column numbers in the buffer. This can be nonzero in a continuation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 line, when the previous screen lines' widths do not add up to a multiple
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 of @code{tab-width}. It is always zero in a non-continuation line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 The window @var{window} serves only to specify which display table to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 use. @code{compute-motion} always operates on the current buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 regardless of what buffer is displayed in @var{window}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 The return value is a list of five elements:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (@var{pos} @var{vpos} @var{hpos} @var{prevhpos} @var{contin})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 Here @var{pos} is the buffer position where the scan stopped, @var{vpos}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 is the vertical screen position, and @var{hpos} is the horizontal screen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 The result @var{prevhpos} is the horizontal position one character back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 from @var{pos}. The result @var{contin} is @code{t} if the last line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 was continued after (or within) the previous character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 For example, to find the buffer position of column @var{col} of line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 @var{line} of a certain window, pass the window's display start location
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 as @var{from} and the window's upper-left coordinates as @var{frompos}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 Pass the buffer's @code{(point-max)} as @var{to}, to limit the scan to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 the end of the accessible portion of the buffer, and pass @var{line} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 @var{col} as @var{topos}. Here's a function that does this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 (defun coordinates-of-position (col line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 (car (compute-motion (window-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 '(0 . 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 (point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 (cons col line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 (window-width)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 (cons (window-hscroll) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 (selected-window))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 When you use @code{compute-motion} for the minibuffer, you need to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 @code{minibuffer-prompt-width} to get the horizontal position of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 beginning of the first screen line. @xref{Minibuffer Misc}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 @end ignore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
603 @node List Motion, Skipping Characters, Screen Lines, Motion
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
604 @subsection Moving over Balanced Expressions
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 @cindex sexp motion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 @cindex Lisp expression motion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 @cindex list motion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 Here are several functions concerned with balanced-parenthesis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 expressions (also called @dfn{sexps} in connection with moving across
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 them in XEmacs). The syntax table controls how these functions interpret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 various characters; see @ref{Syntax Tables}. @xref{Parsing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 Expressions}, for lower-level primitives for scanning sexps or parts of
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
614 sexps. For user-level commands, see @ref{Lists and Sexps,,, xemacs, XEmacs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 Reference Manual}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 @deffn Command forward-list &optional arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 This function moves forward across @var{arg} balanced groups of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 parentheses. (Other syntactic entities such as words or paired string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 quotes are ignored.) @var{arg} defaults to 1 if omitted. If @var{arg}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 is negative, move backward across that many groups of parentheses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
624 @deffn Command backward-list &optional count
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
625 This function moves backward across @var{count} balanced groups of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 parentheses. (Other syntactic entities such as words or paired string
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
627 quotes are ignored.) @var{count} defaults to 1 if omitted. If
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
628 @var{count} is negative, move forward across that many groups of
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
629 parentheses.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
632 @deffn Command up-list &optional count
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
633 This function moves forward out of @var{count} levels of parentheses.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 A negative argument means move backward but still to a less deep spot.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
637 @deffn Command down-list &optional count
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
638 This function moves forward into @var{count} levels of parentheses.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
639 A negative argument means move backward but still go deeper in
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
640 parentheses (@minus{}@var{count} levels).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
643 @deffn Command forward-sexp &optional count
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
644 This function moves forward across @var{count} balanced expressions.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 Balanced expressions include both those delimited by parentheses and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
646 other kinds, such as words and string constants. @var{count} defaults to
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
647 1 if omitted. If @var{count} is negative, move backward across that many
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 balanced expressions. For example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 (concat@point{} "foo " (car x) y z)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (forward-sexp 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 (concat "foo " (car x) y@point{} z)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
668 @deffn Command backward-sexp &optional count
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
669 This function moves backward across @var{count} balanced expressions.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
670 @var{count} defaults to 1 if omitted. If @var{count} is negative, move
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 forward across that many balanced expressions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
674 @deffn Command beginning-of-defun &optional count
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
675 This function moves back to the @var{count}th beginning of a defun.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
676 If @var{count} is negative, this actually moves forward, but it still
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
677 moves to the beginning of a defun, not to the end of one. @var{count}
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
678 defaults to 1 if omitted.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
681 @deffn Command end-of-defun &optional count
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
682 This function moves forward to the @var{count}th end of a defun.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
683 If @var{count} is negative, this actually moves backward, but it still
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
684 moves to the end of a defun, not to the beginning of one. @var{count}
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
685 defaults to 1 if omitted.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 @defopt defun-prompt-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 If non-@code{nil}, this variable holds a regular expression that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 specifies what text can appear before the open-parenthesis that starts a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 defun. That is to say, a defun begins on a line that starts with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 match for this regular expression, followed by a character with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 open-parenthesis syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
696 @node Skipping Characters, , List Motion, Motion
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 @subsection Skipping Characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 @cindex skipping characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 The following two functions move point over a specified set of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 characters. For example, they are often used to skip whitespace. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 related functions, see @ref{Motion and Syntax}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 @defun skip-chars-forward character-set &optional limit buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 This function moves point in @var{buffer} forward, skipping over a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 given set of characters. It examines the character following point,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 then advances point if the character matches @var{character-set}. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 continues until it reaches a character that does not match. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 function returns @code{nil}. @var{buffer} defaults to the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 The argument @var{character-set} is like the inside of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 @samp{[@dots{}]} in a regular expression except that @samp{]} is never
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 special and @samp{\} quotes @samp{^}, @samp{-} or @samp{\}. Thus,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 @code{"a-zA-Z"} skips over all letters, stopping before the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 non-letter, and @code{"^a-zA-Z}" skips non-letters stopping before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 first letter. @xref{Regular Expressions}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 If @var{limit} is supplied (it must be a number or a marker), it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 specifies the maximum position in the buffer that point can be skipped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 to. Point will stop at or before @var{limit}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 In the following example, point is initially located directly before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 @samp{T}. After the form is evaluated, point is located at the end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 that line (between the @samp{t} of @samp{hat} and the newline). The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 function skips all letters and spaces, but not newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 I read "@point{}The cat in the hat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 comes back" twice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 (skip-chars-forward "a-zA-Z ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 @result{} nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 I read "The cat in the hat@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 comes back" twice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 @defun skip-chars-backward character-set &optional limit buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 This function moves point backward, skipping characters that match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 @var{character-set}, until @var{limit}. It just like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 @code{skip-chars-forward} except for the direction of motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
754 @node Excursions, Narrowing, Motion, Positions
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 @section Excursions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 @cindex excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 It is often useful to move point ``temporarily'' within a localized
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 portion of the program, or to switch buffers temporarily. This is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 called an @dfn{excursion}, and it is done with the @code{save-excursion}
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
761 special operator. This construct saves the current buffer and its values of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 point and the mark so they can be restored after the completion of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 excursion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 The forms for saving and restoring the configuration of windows are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 described elsewhere (see @ref{Window Configurations} and @pxref{Frame
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 Configurations}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768
5361
62b9ef1ed4ac Change "special form" to "special operator" in the manuals, too
Aidan Kehoe <kehoea@parhasard.net>
parents: 4905
diff changeset
769 @deffn {Special Operator} save-excursion forms@dots{}
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 @cindex mark excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 @cindex point excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 @cindex current buffer excursion
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
773 The @code{save-excursion} special operator saves the identity of the current
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 buffer and the values of point and the mark in it, evaluates
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 @var{forms}, and finally restores the buffer and its saved values of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 point and the mark. All three saved values are restored even in case of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 an abnormal exit via @code{throw} or error (@pxref{Nonlocal Exits}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
779 The @code{save-excursion} special operator is the standard way to switch
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 buffers or move point within one part of a program and avoid affecting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 the rest of the program. It is used more than 500 times in the Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 sources of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 @code{save-excursion} does not save the values of point and the mark for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 other buffers, so changes in other buffers remain in effect after
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 @code{save-excursion} exits.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 @cindex window excursions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 Likewise, @code{save-excursion} does not restore window-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 correspondences altered by functions such as @code{switch-to-buffer}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 One way to restore these correspondences, and the selected window, is to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 use @code{save-window-excursion} inside @code{save-excursion}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 (@pxref{Window Configurations}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 The value returned by @code{save-excursion} is the result of the last of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 @var{forms}, or @code{nil} if no @var{forms} are given.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 @var{forms})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 @equiv{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 (let ((old-buf (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 (old-pnt (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 (old-mark (copy-marker (mark-marker))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 (progn @var{forms})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 (set-buffer old-buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 (goto-char old-pnt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 (set-marker (mark-marker) old-mark)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 @end example
5361
62b9ef1ed4ac Change "special form" to "special operator" in the manuals, too
Aidan Kehoe <kehoea@parhasard.net>
parents: 4905
diff changeset
813 @end deffn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814
5361
62b9ef1ed4ac Change "special form" to "special operator" in the manuals, too
Aidan Kehoe <kehoea@parhasard.net>
parents: 4905
diff changeset
815 @deffn {Special Operator} save-current-buffer forms@dots{}
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
816 This special operator is similar to @code{save-excursion} but it only
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 saves and restores the current buffer. Beginning with XEmacs 20.3,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 @code{save-current-buffer} is a primitive.
5361
62b9ef1ed4ac Change "special form" to "special operator" in the manuals, too
Aidan Kehoe <kehoea@parhasard.net>
parents: 4905
diff changeset
819 @end deffn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
821 @defmac with-current-buffer buffer forms@dots{}
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
822 This macro evaluates @var{forms} with @var{buffer} as the current
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 buffer. It returns the value of the last form.
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
824 @end defmac
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
826 @defmac with-temp-file filename forms@dots{}
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
827 This macro creates a new buffer, evaluates @var{forms} there, and
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
828 writes the buffer to @var{filename}. It returns the value of the last form
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 evaluated.
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
830 @end defmac
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
832 @defmac save-selected-window forms@dots{}
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
833 This macro is similar to @code{save-excursion} but it saves and
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 restores the selected window and nothing else.
5547
a46c5c8d6564 Avoid calling various macros "special operators" in the manuals.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5361
diff changeset
835 @end defmac
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836
5791
9fae6227ede5 Silence texinfo 5.2 warnings, primarily by adding next, prev, and up
Jerry James <james@xemacs.org>
parents: 5547
diff changeset
837 @node Narrowing, , Excursions, Positions
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 @section Narrowing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 @cindex narrowing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 @cindex restriction (in a buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 @cindex accessible portion (of a buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 @dfn{Narrowing} means limiting the text addressable by XEmacs editing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 commands to a limited range of characters in a buffer. The text that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 remains addressable is called the @dfn{accessible portion} of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 Narrowing is specified with two buffer positions which become the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 beginning and end of the accessible portion. For most editing commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 and most Emacs primitives, these positions replace the values of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 beginning and end of the buffer. While narrowing is in effect, no text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 outside the accessible portion is displayed, and point cannot move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 outside the accessible portion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 Values such as positions or line numbers, which usually count from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 beginning of the buffer, do so despite narrowing, but the functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 which use them refuse to operate on text that is inaccessible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 The commands for saving buffers are unaffected by narrowing; they save
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 the entire buffer regardless of any narrowing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 @deffn Command narrow-to-region start end &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 This function sets the accessible portion of @var{buffer} to start at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 @var{start} and end at @var{end}. Both arguments should be character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 positions. @var{buffer} defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 In an interactive call, @var{start} and @var{end} are set to the bounds
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 of the current region (point and the mark, with the smallest first).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 @deffn Command narrow-to-page &optional move-count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 This function sets the accessible portion of the current buffer to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 include just the current page. An optional first argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 @var{move-count} non-@code{nil} means to move forward or backward by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 @var{move-count} pages and then narrow. The variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 @code{page-delimiter} specifies where pages start and end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 (@pxref{Standard Regexps}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 In an interactive call, @var{move-count} is set to the numeric prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 @deffn Command widen &optional buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 @cindex widening
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 This function cancels any narrowing in @var{buffer}, so that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 entire contents are accessible. This is called @dfn{widening}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 It is equivalent to the following expression:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 (narrow-to-region 1 (1+ (buffer-size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 @var{buffer} defaults to the current buffer if omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895
5361
62b9ef1ed4ac Change "special form" to "special operator" in the manuals, too
Aidan Kehoe <kehoea@parhasard.net>
parents: 4905
diff changeset
896 @deffn {Special Operator} save-restriction body@dots{}
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
897 This special operator saves the current bounds of the accessible portion,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 evaluates the @var{body} forms, and finally restores the saved bounds,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 thus restoring the same state of narrowing (or absence thereof) formerly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 in effect. The state of narrowing is restored even in the event of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 abnormal exit via @code{throw} or error (@pxref{Nonlocal Exits}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 Therefore, this construct is a clean way to narrow a buffer temporarily.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 The value returned by @code{save-restriction} is that returned by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 last form in @var{body}, or @code{nil} if no body forms were given.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 @c Wordy to avoid overfull hbox. --rjc 16mar92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 @strong{Caution:} it is easy to make a mistake when using the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 @code{save-restriction} construct. Read the entire description here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 before you try it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 If @var{body} changes the current buffer, @code{save-restriction} still
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 restores the restrictions on the original buffer (the buffer whose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 restrictions it saved from), but it does not restore the identity of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 @code{save-restriction} does @emph{not} restore point and the mark; use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 @code{save-excursion} for that. If you use both @code{save-restriction}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 and @code{save-excursion} together, @code{save-excursion} should come
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 first (on the outside). Otherwise, the old point value would be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 restored with temporary narrowing still in effect. If the old point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 value were outside the limits of the temporary narrowing, this would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 fail to restore it accurately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
925 The @code{save-restriction} special operator records the values of the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 beginning and end of the accessible portion as distances from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 beginning and end of the buffer. In other words, it records the amount
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 of inaccessible text before and after the accessible portion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 This method yields correct results if @var{body} does further narrowing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 However, @code{save-restriction} can become confused if the body widens
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 and then make changes outside the range of the saved narrowing. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 this is what you want to do, @code{save-restriction} is not the right
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 tool for the job. Here is what you must use instead:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
938 (let ((start (point-min-marker))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 (end (point-max-marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 (progn @var{body})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 (save-excursion
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
943 (set-buffer (marker-buffer start))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
944 (narrow-to-region start end))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 Here is a simple example of correct use of @code{save-restriction}:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 This is the contents of foo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 This is the contents of foo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 This is the contents of foo@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (goto-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 (forward-line 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (narrow-to-region 1 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 (replace-string "foo" "bar")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 This is the contents of bar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 This is the contents of bar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 This is the contents of foo@point{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 ---------- Buffer: foo ----------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 @end example
5361
62b9ef1ed4ac Change "special form" to "special operator" in the manuals, too
Aidan Kehoe <kehoea@parhasard.net>
parents: 4905
diff changeset
975 @end deffn