Mercurial > hg > xemacs-beta
comparison src/cmds.c @ 444:576fb035e263 r21-2-37
Import from CVS: tag r21-2-37
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:36:19 +0200 |
parents | abe6d1db359e |
children | 1ccc32a20af4 |
comparison
equal
deleted
inserted
replaced
443:a8296e22da4e | 444:576fb035e263 |
---|---|
44 | 44 |
45 /* A char-table for characters which may invoke auto-filling. */ | 45 /* A char-table for characters which may invoke auto-filling. */ |
46 Lisp_Object Vauto_fill_chars; | 46 Lisp_Object Vauto_fill_chars; |
47 | 47 |
48 DEFUN ("forward-char", Fforward_char, 0, 2, "_p", /* | 48 DEFUN ("forward-char", Fforward_char, 0, 2, "_p", /* |
49 Move point right N characters (left if N negative). | 49 Move point right COUNT characters (left if COUNT is negative). |
50 On attempt to pass end of buffer, stop and signal `end-of-buffer'. | 50 On attempt to pass end of buffer, stop and signal `end-of-buffer'. |
51 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'. | 51 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'. |
52 On reaching end of buffer, stop and signal error. | 52 On reaching end of buffer, stop and signal error. |
53 */ | 53 */ |
54 (n, buffer)) | 54 (count, buffer)) |
55 { | 55 { |
56 struct buffer *buf = decode_buffer (buffer, 1); | 56 struct buffer *buf = decode_buffer (buffer, 1); |
57 EMACS_INT count; | 57 EMACS_INT n; |
58 | 58 |
59 if (NILP (n)) | 59 if (NILP (count)) |
60 count = 1; | 60 n = 1; |
61 else | 61 else |
62 { | 62 { |
63 CHECK_INT (n); | 63 CHECK_INT (count); |
64 count = XINT (n); | 64 n = XINT (count); |
65 } | 65 } |
66 | 66 |
67 /* This used to just set point to point + XINT (n), and then check | 67 /* This used to just set point to point + XINT (count), and then check |
68 to see if it was within boundaries. But now that SET_PT can | 68 to see if it was within boundaries. But now that SET_PT can |
69 potentially do a lot of stuff (calling entering and exiting | 69 potentially do a lot of stuff (calling entering and exiting |
70 hooks, etcetera), that's not a good approach. So we validate the | 70 hooks, etcetera), that's not a good approach. So we validate the |
71 proposed position, then set point. */ | 71 proposed position, then set point. */ |
72 { | 72 { |
73 Bufpos new_point = BUF_PT (buf) + count; | 73 Bufpos new_point = BUF_PT (buf) + n; |
74 | 74 |
75 if (new_point < BUF_BEGV (buf)) | 75 if (new_point < BUF_BEGV (buf)) |
76 { | 76 { |
77 BUF_SET_PT (buf, BUF_BEGV (buf)); | 77 BUF_SET_PT (buf, BUF_BEGV (buf)); |
78 Fsignal (Qbeginning_of_buffer, Qnil); | 78 Fsignal (Qbeginning_of_buffer, Qnil); |
90 | 90 |
91 return Qnil; | 91 return Qnil; |
92 } | 92 } |
93 | 93 |
94 DEFUN ("backward-char", Fbackward_char, 0, 2, "_p", /* | 94 DEFUN ("backward-char", Fbackward_char, 0, 2, "_p", /* |
95 Move point left N characters (right if N negative). | 95 Move point left COUNT characters (right if COUNT is negative). |
96 On attempt to pass end of buffer, stop and signal `end-of-buffer'. | 96 On attempt to pass end of buffer, stop and signal `end-of-buffer'. |
97 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'. | 97 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'. |
98 */ | 98 */ |
99 (n, buffer)) | 99 (count, buffer)) |
100 { | 100 { |
101 if (NILP (n)) | 101 if (NILP (count)) |
102 n = make_int (-1); | 102 count = make_int (-1); |
103 else | 103 else |
104 { | 104 { |
105 CHECK_INT (n); | 105 CHECK_INT (count); |
106 XSETINT (n, - XINT (n)); | 106 count = make_int (- XINT (count)); |
107 } | 107 } |
108 return Fforward_char (n, buffer); | 108 return Fforward_char (count, buffer); |
109 } | 109 } |
110 | 110 |
111 DEFUN ("forward-line", Fforward_line, 0, 2, "_p", /* | 111 DEFUN ("forward-line", Fforward_line, 0, 2, "_p", /* |
112 Move N lines forward (backward if N is negative). | 112 Move COUNT lines forward (backward if COUNT is negative). |
113 Precisely, if point is on line I, move to the start of line I + N. | 113 Precisely, if point is on line I, move to the start of line I + COUNT. |
114 If there isn't room, go as far as possible (no error). | 114 If there isn't room, go as far as possible (no error). |
115 Returns the count of lines left to move. If moving forward, | 115 Returns the count of lines left to move. If moving forward, |
116 that is N - number of lines moved; if backward, N + number moved. | 116 that is COUNT - number of lines moved; if backward, COUNT + number moved. |
117 With positive N, a non-empty line at the end counts as one line | 117 With positive COUNT, a non-empty line at the end counts as one line |
118 successfully moved (for the return value). | 118 successfully moved (for the return value). |
119 If BUFFER is nil, the current buffer is assumed. | 119 If BUFFER is nil, the current buffer is assumed. |
120 */ | 120 */ |
121 (n, buffer)) | 121 (count, buffer)) |
122 { | 122 { |
123 struct buffer *buf = decode_buffer (buffer, 1); | 123 struct buffer *buf = decode_buffer (buffer, 1); |
124 Bufpos pos2 = BUF_PT (buf); | 124 Bufpos pos2 = BUF_PT (buf); |
125 Bufpos pos; | 125 Bufpos pos; |
126 EMACS_INT count, shortage, negp; | 126 EMACS_INT n, shortage, negp; |
127 | 127 |
128 if (NILP (n)) | 128 if (NILP (count)) |
129 count = 1; | 129 n = 1; |
130 else | 130 else |
131 { | 131 { |
132 CHECK_INT (n); | 132 CHECK_INT (count); |
133 count = XINT (n); | 133 n = XINT (count); |
134 } | 134 } |
135 | 135 |
136 negp = count <= 0; | 136 negp = n <= 0; |
137 pos = scan_buffer (buf, '\n', pos2, 0, count - negp, &shortage, 1); | 137 pos = scan_buffer (buf, '\n', pos2, 0, n - negp, &shortage, 1); |
138 if (shortage > 0 | 138 if (shortage > 0 |
139 && (negp | 139 && (negp |
140 || (BUF_ZV (buf) > BUF_BEGV (buf) | 140 || (BUF_ZV (buf) > BUF_BEGV (buf) |
141 && pos != pos2 | 141 && pos != pos2 |
142 && BUF_FETCH_CHAR (buf, pos - 1) != '\n'))) | 142 && BUF_FETCH_CHAR (buf, pos - 1) != '\n'))) |
145 return make_int (negp ? - shortage : shortage); | 145 return make_int (negp ? - shortage : shortage); |
146 } | 146 } |
147 | 147 |
148 DEFUN ("point-at-bol", Fpoint_at_bol, 0, 2, 0, /* | 148 DEFUN ("point-at-bol", Fpoint_at_bol, 0, 2, 0, /* |
149 Return the character position of the first character on the current line. | 149 Return the character position of the first character on the current line. |
150 With argument N not nil or 1, move forward N - 1 lines first. | 150 With argument COUNT not nil or 1, move forward COUNT - 1 lines first. |
151 If scan reaches end of buffer, return that position. | 151 If scan reaches end of buffer, return that position. |
152 This function does not move point. | 152 This function does not move point. |
153 */ | 153 */ |
154 (n, buffer)) | 154 (count, buffer)) |
155 { | 155 { |
156 struct buffer *b = decode_buffer (buffer, 1); | 156 struct buffer *b = decode_buffer (buffer, 1); |
157 REGISTER int orig, end; | 157 REGISTER int orig, end; |
158 | 158 |
159 XSETBUFFER (buffer, b); | 159 XSETBUFFER (buffer, b); |
160 if (NILP (n)) | 160 if (NILP (count)) |
161 n = make_int (0); | 161 count = make_int (0); |
162 else | 162 else |
163 { | 163 { |
164 CHECK_INT (n); | 164 CHECK_INT (count); |
165 n = make_int (XINT (n) - 1); | 165 count = make_int (XINT (count) - 1); |
166 } | 166 } |
167 | 167 |
168 orig = BUF_PT (b); | 168 orig = BUF_PT (b); |
169 Fforward_line (n, buffer); | 169 Fforward_line (count, buffer); |
170 end = BUF_PT (b); | 170 end = BUF_PT (b); |
171 BUF_SET_PT (b, orig); | 171 BUF_SET_PT (b, orig); |
172 | 172 |
173 return make_int (end); | 173 return make_int (end); |
174 } | 174 } |
175 | 175 |
176 DEFUN ("beginning-of-line", Fbeginning_of_line, 0, 2, "_p", /* | 176 DEFUN ("beginning-of-line", Fbeginning_of_line, 0, 2, "_p", /* |
177 Move point to beginning of current line. | 177 Move point to beginning of current line. |
178 With argument N not nil or 1, move forward N - 1 lines first. | 178 With argument COUNT not nil or 1, move forward COUNT - 1 lines first. |
179 If scan reaches end of buffer, stop there without error. | 179 If scan reaches end of buffer, stop there without error. |
180 If BUFFER is nil, the current buffer is assumed. | 180 If BUFFER is nil, the current buffer is assumed. |
181 */ | 181 */ |
182 (n, buffer)) | 182 (count, buffer)) |
183 { | 183 { |
184 struct buffer *b = decode_buffer (buffer, 1); | 184 struct buffer *b = decode_buffer (buffer, 1); |
185 | 185 |
186 BUF_SET_PT (b, XINT (Fpoint_at_bol (n, buffer))); | 186 BUF_SET_PT (b, XINT (Fpoint_at_bol (count, buffer))); |
187 return Qnil; | 187 return Qnil; |
188 } | 188 } |
189 | 189 |
190 DEFUN ("point-at-eol", Fpoint_at_eol, 0, 2, 0, /* | 190 DEFUN ("point-at-eol", Fpoint_at_eol, 0, 2, 0, /* |
191 Return the character position of the last character on the current line. | 191 Return the character position of the last character on the current line. |
192 With argument N not nil or 1, move forward N - 1 lines first. | 192 With argument COUNT not nil or 1, move forward COUNT - 1 lines first. |
193 If scan reaches end of buffer, return that position. | 193 If scan reaches end of buffer, return that position. |
194 This function does not move point. | 194 This function does not move point. |
195 */ | 195 */ |
196 (n, buffer)) | 196 (count, buffer)) |
197 { | 197 { |
198 struct buffer *buf = decode_buffer (buffer, 1); | 198 struct buffer *buf = decode_buffer (buffer, 1); |
199 int count; | 199 int n; |
200 | 200 |
201 if (NILP (n)) | 201 if (NILP (count)) |
202 count = 1; | 202 n = 1; |
203 else | 203 else |
204 { | 204 { |
205 CHECK_INT (n); | 205 CHECK_INT (count); |
206 count = XINT (n); | 206 n = XINT (count); |
207 } | 207 } |
208 | 208 |
209 return make_int (find_before_next_newline (buf, BUF_PT (buf), 0, | 209 return make_int (find_before_next_newline (buf, BUF_PT (buf), 0, |
210 count - (count <= 0))); | 210 n - (n <= 0))); |
211 } | 211 } |
212 | 212 |
213 DEFUN ("end-of-line", Fend_of_line, 0, 2, "_p", /* | 213 DEFUN ("end-of-line", Fend_of_line, 0, 2, "_p", /* |
214 Move point to end of current line. | 214 Move point to end of current line. |
215 With argument N not nil or 1, move forward N - 1 lines first. | 215 With argument COUNT not nil or 1, move forward COUNT - 1 lines first. |
216 If scan reaches end of buffer, stop there without error. | 216 If scan reaches end of buffer, stop there without error. |
217 If BUFFER is nil, the current buffer is assumed. | 217 If BUFFER is nil, the current buffer is assumed. |
218 */ | 218 */ |
219 (n, buffer)) | 219 (count, buffer)) |
220 { | 220 { |
221 struct buffer *b = decode_buffer (buffer, 1); | 221 struct buffer *b = decode_buffer (buffer, 1); |
222 | 222 |
223 BUF_SET_PT (b, XINT (Fpoint_at_eol (n, buffer))); | 223 BUF_SET_PT (b, XINT (Fpoint_at_eol (count, buffer))); |
224 return Qnil; | 224 return Qnil; |
225 } | 225 } |
226 | 226 |
227 DEFUN ("delete-char", Fdelete_char, 1, 2, "*p\nP", /* | 227 DEFUN ("delete-char", Fdelete_char, 1, 2, "*p\nP", /* |
228 Delete the following N characters (previous, with negative N). | 228 Delete the following COUNT characters (previous, with negative COUNT). |
229 Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). | 229 Optional second arg KILLP non-nil means kill instead (save in kill ring). |
230 Interactively, N is the prefix arg, and KILLFLAG is set if | 230 Interactively, COUNT is the prefix arg, and KILLP is set if |
231 N was explicitly specified. | 231 COUNT was explicitly specified. |
232 */ | 232 */ |
233 (n, killflag)) | 233 (count, killp)) |
234 { | 234 { |
235 /* This function can GC */ | 235 /* This function can GC */ |
236 Bufpos pos; | 236 Bufpos pos; |
237 struct buffer *buf = current_buffer; | 237 struct buffer *buf = current_buffer; |
238 int count; | 238 int n; |
239 | 239 |
240 CHECK_INT (n); | 240 CHECK_INT (count); |
241 count = XINT (n); | 241 n = XINT (count); |
242 | 242 |
243 pos = BUF_PT (buf) + count; | 243 pos = BUF_PT (buf) + n; |
244 if (NILP (killflag)) | 244 if (NILP (killp)) |
245 { | 245 { |
246 if (count < 0) | 246 if (n < 0) |
247 { | 247 { |
248 if (pos < BUF_BEGV (buf)) | 248 if (pos < BUF_BEGV (buf)) |
249 signal_error (Qbeginning_of_buffer, Qnil); | 249 signal_error (Qbeginning_of_buffer, Qnil); |
250 else | 250 else |
251 buffer_delete_range (buf, pos, BUF_PT (buf), 0); | 251 buffer_delete_range (buf, pos, BUF_PT (buf), 0); |
258 buffer_delete_range (buf, BUF_PT (buf), pos, 0); | 258 buffer_delete_range (buf, BUF_PT (buf), pos, 0); |
259 } | 259 } |
260 } | 260 } |
261 else | 261 else |
262 { | 262 { |
263 call1 (Qkill_forward_chars, n); | 263 call1 (Qkill_forward_chars, count); |
264 } | 264 } |
265 return Qnil; | 265 return Qnil; |
266 } | 266 } |
267 | 267 |
268 DEFUN ("delete-backward-char", Fdelete_backward_char, 1, 2, "*p\nP", /* | 268 DEFUN ("delete-backward-char", Fdelete_backward_char, 1, 2, "*p\nP", /* |
269 Delete the previous N characters (following, with negative N). | 269 Delete the previous COUNT characters (following, with negative COUNT). |
270 Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). | 270 Optional second arg KILLP non-nil means kill instead (save in kill ring). |
271 Interactively, N is the prefix arg, and KILLFLAG is set if | 271 Interactively, COUNT is the prefix arg, and KILLP is set if |
272 N was explicitly specified. | 272 COUNT was explicitly specified. |
273 */ | 273 */ |
274 (n, killflag)) | 274 (count, killp)) |
275 { | 275 { |
276 /* This function can GC */ | 276 /* This function can GC */ |
277 CHECK_INT (n); | 277 CHECK_INT (count); |
278 return Fdelete_char (make_int (- XINT (n)), killflag); | 278 return Fdelete_char (make_int (- XINT (count)), killp); |
279 } | 279 } |
280 | 280 |
281 static void internal_self_insert (Emchar ch, int noautofill); | 281 static void internal_self_insert (Emchar ch, int noautofill); |
282 | 282 |
283 DEFUN ("self-insert-command", Fself_insert_command, 1, 1, "*p", /* | 283 DEFUN ("self-insert-command", Fself_insert_command, 1, 1, "*p", /* |
284 Insert the character you type. | 284 Insert the character you type. |
285 Whichever character you type to run this command is inserted. | 285 Whichever character you type to run this command is inserted. |
286 */ | 286 If a prefix arg COUNT is specified, the character is inserted COUNT times. |
287 (n)) | 287 */ |
288 (count)) | |
288 { | 289 { |
289 /* This function can GC */ | 290 /* This function can GC */ |
290 Emchar ch; | 291 Emchar ch; |
291 Lisp_Object c; | 292 Lisp_Object c; |
292 int count; | 293 int n; |
293 | 294 |
294 CHECK_NATNUM (n); | 295 CHECK_NATNUM (count); |
295 count = XINT (n); | 296 n = XINT (count); |
296 | 297 |
297 if (CHAR_OR_CHAR_INTP (Vlast_command_char)) | 298 if (CHAR_OR_CHAR_INTP (Vlast_command_char)) |
298 c = Vlast_command_char; | 299 c = Vlast_command_char; |
299 else | 300 else |
300 c = Fevent_to_character (Vlast_command_event, Qnil, Qnil, Qt); | 301 c = Fevent_to_character (Vlast_command_event, Qnil, Qnil, Qt); |
305 | 306 |
306 CHECK_CHAR_COERCE_INT (c); | 307 CHECK_CHAR_COERCE_INT (c); |
307 | 308 |
308 ch = XCHAR (c); | 309 ch = XCHAR (c); |
309 | 310 |
310 while (count--) | 311 while (n--) |
311 internal_self_insert (ch, (count != 0)); | 312 internal_self_insert (ch, (n != 0)); |
312 | 313 |
313 return Qnil; | 314 return Qnil; |
314 } | 315 } |
315 | 316 |
316 /* Insert character C1. If NOAUTOFILL is nonzero, don't do autofill | 317 /* Insert character C1. If NOAUTOFILL is nonzero, don't do autofill |
445 } | 446 } |
446 | 447 |
447 /* (this comes from Mule but is a generally good idea) */ | 448 /* (this comes from Mule but is a generally good idea) */ |
448 | 449 |
449 DEFUN ("self-insert-internal", Fself_insert_internal, 1, 1, 0, /* | 450 DEFUN ("self-insert-internal", Fself_insert_internal, 1, 1, 0, /* |
450 Invoke `self-insert-command' as if CH is entered from keyboard. | 451 Invoke `self-insert-command' as if CHARACTER is entered from keyboard. |
451 */ | 452 */ |
452 (ch)) | 453 (character)) |
453 { | 454 { |
454 /* This function can GC */ | 455 /* This function can GC */ |
455 CHECK_CHAR_COERCE_INT (ch); | 456 CHECK_CHAR_COERCE_INT (character); |
456 internal_self_insert (XCHAR (ch), 0); | 457 internal_self_insert (XCHAR (character), 0); |
457 return Qnil; | 458 return Qnil; |
458 } | 459 } |
459 | 460 |
460 /* module initialization */ | 461 /* module initialization */ |
461 | 462 |
504 */ ); | 505 */ ); |
505 Vblink_paren_function = Qnil; | 506 Vblink_paren_function = Qnil; |
506 | 507 |
507 DEFVAR_LISP ("auto-fill-chars", &Vauto_fill_chars /* | 508 DEFVAR_LISP ("auto-fill-chars", &Vauto_fill_chars /* |
508 A char-table for characters which invoke auto-filling. | 509 A char-table for characters which invoke auto-filling. |
509 Such characters has value t in this table. | 510 Such characters have value t in this table. |
510 */); | 511 */); |
511 Vauto_fill_chars = Fmake_char_table (Qgeneric); | 512 Vauto_fill_chars = Fmake_char_table (Qgeneric); |
512 XCHAR_TABLE (Vauto_fill_chars)->ascii[' '] = Qt; | 513 XCHAR_TABLE (Vauto_fill_chars)->ascii[' '] = Qt; |
513 XCHAR_TABLE (Vauto_fill_chars)->ascii['\n'] = Qt; | 514 XCHAR_TABLE (Vauto_fill_chars)->ascii['\n'] = Qt; |
514 } | 515 } |