comparison src/cmds.c @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents 57709be46d1b
children 74fd4e045ea6
comparison
equal deleted inserted replaced
379:76b7d63099ad 380:8626e4521993
41 41
42 /* This is the command that set up Vself_insert_face. */ 42 /* This is the command that set up Vself_insert_face. */
43 Lisp_Object Vself_insert_face_command; 43 Lisp_Object Vself_insert_face_command;
44 44
45 DEFUN ("forward-char", Fforward_char, 0, 2, "_p", /* 45 DEFUN ("forward-char", Fforward_char, 0, 2, "_p", /*
46 Move point right ARG characters (left if ARG negative). 46 Move point right N characters (left if N negative).
47 On attempt to pass end of buffer, stop and signal `end-of-buffer'. 47 On attempt to pass end of buffer, stop and signal `end-of-buffer'.
48 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'. 48 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'.
49 On reaching end of buffer, stop and signal error. 49 On reaching end of buffer, stop and signal error.
50 */ 50 */
51 (arg, buffer)) 51 (n, buffer))
52 { 52 {
53 struct buffer *buf = decode_buffer (buffer, 1); 53 struct buffer *buf = decode_buffer (buffer, 1);
54 54 EMACS_INT count;
55 if (NILP (arg)) 55
56 arg = make_int (1); 56 if (NILP (n))
57 else 57 count = 1;
58 CHECK_INT (arg); 58 else
59 59 {
60 /* This used to just set point to point + XINT (arg), and then check 60 CHECK_INT (n);
61 count = XINT (n);
62 }
63
64 /* This used to just set point to point + XINT (n), and then check
61 to see if it was within boundaries. But now that SET_PT can 65 to see if it was within boundaries. But now that SET_PT can
62 potentially do a lot of stuff (calling entering and exiting 66 potentially do a lot of stuff (calling entering and exiting
63 hooks, etcetera), that's not a good approach. So we validate the 67 hooks, etcetera), that's not a good approach. So we validate the
64 proposed position, then set point. */ 68 proposed position, then set point. */
65 { 69 {
66 Bufpos new_point = BUF_PT (buf) + XINT (arg); 70 Bufpos new_point = BUF_PT (buf) + count;
67 71
68 if (new_point < BUF_BEGV (buf)) 72 if (new_point < BUF_BEGV (buf))
69 { 73 {
70 BUF_SET_PT (buf, BUF_BEGV (buf)); 74 BUF_SET_PT (buf, BUF_BEGV (buf));
71 Fsignal (Qbeginning_of_buffer, Qnil); 75 Fsignal (Qbeginning_of_buffer, Qnil);
83 87
84 return Qnil; 88 return Qnil;
85 } 89 }
86 90
87 DEFUN ("backward-char", Fbackward_char, 0, 2, "_p", /* 91 DEFUN ("backward-char", Fbackward_char, 0, 2, "_p", /*
88 Move point left ARG characters (right if ARG negative). 92 Move point left N characters (right if N negative).
89 On attempt to pass end of buffer, stop and signal `end-of-buffer'. 93 On attempt to pass end of buffer, stop and signal `end-of-buffer'.
90 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'. 94 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'.
91 */ 95 */
92 (arg, buffer)) 96 (n, buffer))
93 { 97 {
94 if (NILP (arg)) 98 if (NILP (n))
95 arg = make_int (1); 99 n = make_int (-1);
96 else 100 else
97 CHECK_INT (arg); 101 {
98 102 CHECK_INT (n);
99 XSETINT (arg, - XINT (arg)); 103 XSETINT (n, - XINT (n));
100 return Fforward_char (arg, buffer); 104 }
105 return Fforward_char (n, buffer);
101 } 106 }
102 107
103 DEFUN ("forward-line", Fforward_line, 0, 2, "_p", /* 108 DEFUN ("forward-line", Fforward_line, 0, 2, "_p", /*
104 Move ARG lines forward (backward if ARG is negative). 109 Move N lines forward (backward if N is negative).
105 Precisely, if point is on line I, move to the start of line I + ARG. 110 Precisely, if point is on line I, move to the start of line I + N.
106 If there isn't room, go as far as possible (no error). 111 If there isn't room, go as far as possible (no error).
107 Returns the count of lines left to move. If moving forward, 112 Returns the count of lines left to move. If moving forward,
108 that is ARG - number of lines moved; if backward, ARG + number moved. 113 that is N - number of lines moved; if backward, N + number moved.
109 With positive ARG, a non-empty line at the end counts as one line 114 With positive N, a non-empty line at the end counts as one line
110 successfully moved (for the return value). 115 successfully moved (for the return value).
111 If BUFFER is nil, the current buffer is assumed. 116 If BUFFER is nil, the current buffer is assumed.
112 */ 117 */
113 (arg, buffer)) 118 (n, buffer))
114 { 119 {
115 struct buffer *buf = decode_buffer (buffer, 1); 120 struct buffer *buf = decode_buffer (buffer, 1);
116 Bufpos pos2 = BUF_PT (buf); 121 Bufpos pos2 = BUF_PT (buf);
117 Bufpos pos; 122 Bufpos pos;
118 EMACS_INT count, shortage, negp; 123 EMACS_INT count, shortage, negp;
119 124
120 if (NILP (arg)) 125 if (NILP (n))
121 count = 1; 126 count = 1;
122 else 127 else
123 { 128 {
124 CHECK_INT (arg); 129 CHECK_INT (n);
125 count = XINT (arg); 130 count = XINT (n);
126 } 131 }
127 132
128 negp = count <= 0; 133 negp = count <= 0;
129 pos = scan_buffer (buf, '\n', pos2, 0, count - negp, &shortage, 1); 134 pos = scan_buffer (buf, '\n', pos2, 0, count - negp, &shortage, 1);
130 if (shortage > 0 135 if (shortage > 0
141 Return the character position of the first character on the current line. 146 Return the character position of the first character on the current line.
142 With argument N not nil or 1, move forward N - 1 lines first. 147 With argument N not nil or 1, move forward N - 1 lines first.
143 If scan reaches end of buffer, return that position. 148 If scan reaches end of buffer, return that position.
144 This function does not move point. 149 This function does not move point.
145 */ 150 */
146 (arg, buffer)) 151 (n, buffer))
147 { 152 {
148 struct buffer *b = decode_buffer (buffer, 1); 153 struct buffer *b = decode_buffer (buffer, 1);
149 REGISTER int orig, end; 154 REGISTER int orig, end;
150 155
151 XSETBUFFER (buffer, b); 156 XSETBUFFER (buffer, b);
152 if (NILP (arg)) 157 if (NILP (n))
153 arg = make_int (1); 158 n = make_int (0);
154 else 159 else
155 CHECK_INT (arg); 160 {
156 161 CHECK_INT (n);
157 orig = BUF_PT(b); 162 n = make_int (XINT (n) - 1);
158 Fforward_line (make_int (XINT (arg) - 1), buffer); 163 }
159 end = BUF_PT(b); 164
160 BUF_SET_PT(b, orig); 165 orig = BUF_PT (b);
166 Fforward_line (n, buffer);
167 end = BUF_PT (b);
168 BUF_SET_PT (b, orig);
161 169
162 return make_int (end); 170 return make_int (end);
163 } 171 }
164 172
165 DEFUN ("beginning-of-line", Fbeginning_of_line, 0, 2, "_p", /* 173 DEFUN ("beginning-of-line", Fbeginning_of_line, 0, 2, "_p", /*
166 Move point to beginning of current line. 174 Move point to beginning of current line.
167 With argument ARG not nil or 1, move forward ARG - 1 lines first. 175 With argument N not nil or 1, move forward N - 1 lines first.
168 If scan reaches end of buffer, stop there without error. 176 If scan reaches end of buffer, stop there without error.
169 If BUFFER is nil, the current buffer is assumed. 177 If BUFFER is nil, the current buffer is assumed.
170 */ 178 */
171 (arg, buffer)) 179 (n, buffer))
172 { 180 {
173 struct buffer *b = decode_buffer (buffer, 1); 181 struct buffer *b = decode_buffer (buffer, 1);
174 182
175 BUF_SET_PT(b, XINT (Fpoint_at_bol(arg, buffer))); 183 BUF_SET_PT (b, XINT (Fpoint_at_bol (n, buffer)));
176 return Qnil; 184 return Qnil;
177 } 185 }
178 186
179 DEFUN ("point-at-eol", Fpoint_at_eol, 0, 2, 0, /* 187 DEFUN ("point-at-eol", Fpoint_at_eol, 0, 2, 0, /*
180 Return the character position of the last character on the current line. 188 Return the character position of the last character on the current line.
181 With argument N not nil or 1, move forward N - 1 lines first. 189 With argument N not nil or 1, move forward N - 1 lines first.
182 If scan reaches end of buffer, return that position. 190 If scan reaches end of buffer, return that position.
183 This function does not move point. 191 This function does not move point.
184 */ 192 */
185 (arg, buffer)) 193 (n, buffer))
186 { 194 {
187 struct buffer *buf = decode_buffer (buffer, 1); 195 struct buffer *buf = decode_buffer (buffer, 1);
188 196 int count;
189 XSETBUFFER (buffer, buf); 197
190 198 if (NILP (n))
191 if (NILP (arg)) 199 count = 1;
192 arg = make_int (1); 200 else
193 else 201 {
194 CHECK_INT (arg); 202 CHECK_INT (n);
203 count = XINT (n);
204 }
195 205
196 return make_int (find_before_next_newline (buf, BUF_PT (buf), 0, 206 return make_int (find_before_next_newline (buf, BUF_PT (buf), 0,
197 XINT (arg) - (XINT (arg) <= 0))); 207 count - (count <= 0)));
198 } 208 }
199 209
200 DEFUN ("end-of-line", Fend_of_line, 0, 2, "_p", /* 210 DEFUN ("end-of-line", Fend_of_line, 0, 2, "_p", /*
201 Move point to end of current line. 211 Move point to end of current line.
202 With argument ARG not nil or 1, move forward ARG - 1 lines first. 212 With argument N not nil or 1, move forward N - 1 lines first.
203 If scan reaches end of buffer, stop there without error. 213 If scan reaches end of buffer, stop there without error.
204 If BUFFER is nil, the current buffer is assumed. 214 If BUFFER is nil, the current buffer is assumed.
205 */ 215 */
206 (arg, buffer)) 216 (n, buffer))
207 { 217 {
208 struct buffer *b = decode_buffer (buffer, 1); 218 struct buffer *b = decode_buffer (buffer, 1);
209 219
210 BUF_SET_PT(b, XINT (Fpoint_at_eol (arg, buffer))); 220 BUF_SET_PT (b, XINT (Fpoint_at_eol (n, buffer)));
211 return Qnil; 221 return Qnil;
212 } 222 }
213 223
214 DEFUN ("delete-char", Fdelete_char, 1, 2, "*p\nP", /* 224 DEFUN ("delete-char", Fdelete_char, 1, 2, "*p\nP", /*
215 Delete the following ARG characters (previous, with negative arg). 225 Delete the following N characters (previous, with negative N).
216 Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). 226 Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
217 Interactively, ARG is the prefix arg, and KILLFLAG is set if 227 Interactively, N is the prefix arg, and KILLFLAG is set if
218 ARG was explicitly specified. 228 N was explicitly specified.
219 */ 229 */
220 (arg, killflag)) 230 (n, killflag))
221 { 231 {
222 /* This function can GC */ 232 /* This function can GC */
223 Bufpos pos; 233 Bufpos pos;
224 struct buffer *buf = current_buffer; 234 struct buffer *buf = current_buffer;
225 235 int count;
226 CHECK_INT (arg); 236
227 237 CHECK_INT (n);
228 pos = BUF_PT (buf) + XINT (arg); 238 count = XINT (n);
239
240 pos = BUF_PT (buf) + count;
229 if (NILP (killflag)) 241 if (NILP (killflag))
230 { 242 {
231 if (XINT (arg) < 0) 243 if (count < 0)
232 { 244 {
233 if (pos < BUF_BEGV (buf)) 245 if (pos < BUF_BEGV (buf))
234 signal_error (Qbeginning_of_buffer, Qnil); 246 signal_error (Qbeginning_of_buffer, Qnil);
235 else 247 else
236 buffer_delete_range (buf, pos, BUF_PT (buf), 0); 248 buffer_delete_range (buf, pos, BUF_PT (buf), 0);
243 buffer_delete_range (buf, BUF_PT (buf), pos, 0); 255 buffer_delete_range (buf, BUF_PT (buf), pos, 0);
244 } 256 }
245 } 257 }
246 else 258 else
247 { 259 {
248 call1 (Qkill_forward_chars, arg); 260 call1 (Qkill_forward_chars, n);
249 } 261 }
250 return Qnil; 262 return Qnil;
251 } 263 }
252 264
253 DEFUN ("delete-backward-char", Fdelete_backward_char, 1, 2, "*p\nP", /* 265 DEFUN ("delete-backward-char", Fdelete_backward_char, 1, 2, "*p\nP", /*
254 Delete the previous ARG characters (following, with negative ARG). 266 Delete the previous N characters (following, with negative N).
255 Optional second arg KILLFLAG non-nil means kill instead (save in kill ring). 267 Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
256 Interactively, ARG is the prefix arg, and KILLFLAG is set if 268 Interactively, N is the prefix arg, and KILLFLAG is set if
257 ARG was explicitly specified. 269 N was explicitly specified.
258 */ 270 */
259 (arg, killflag)) 271 (n, killflag))
260 { 272 {
261 /* This function can GC */ 273 /* This function can GC */
262 CHECK_INT (arg); 274 CHECK_INT (n);
263 return Fdelete_char (make_int (-XINT (arg)), killflag); 275 return Fdelete_char (make_int (- XINT (n)), killflag);
264 } 276 }
265 277
266 static void internal_self_insert (Emchar ch, int noautofill); 278 static void internal_self_insert (Emchar ch, int noautofill);
267 279
268 DEFUN ("self-insert-command", Fself_insert_command, 1, 1, "*p", /* 280 DEFUN ("self-insert-command", Fself_insert_command, 1, 1, "*p", /*
269 Insert the character you type. 281 Insert the character you type.
270 Whichever character you type to run this command is inserted. 282 Whichever character you type to run this command is inserted.
271 */ 283 */
272 (arg)) 284 (n))
273 { 285 {
274 /* This function can GC */ 286 /* This function can GC */
275 int n;
276 Emchar ch; 287 Emchar ch;
277 Lisp_Object c; 288 Lisp_Object c;
278 CHECK_INT (arg); 289 int count;
290
291 CHECK_NATNUM (n);
292 count = XINT (n);
279 293
280 if (CHAR_OR_CHAR_INTP (Vlast_command_char)) 294 if (CHAR_OR_CHAR_INTP (Vlast_command_char))
281 c = Vlast_command_char; 295 c = Vlast_command_char;
282 else 296 else
283 c = Fevent_to_character (Vlast_command_event, Qnil, Qnil, Qt); 297 c = Fevent_to_character (Vlast_command_event, Qnil, Qnil, Qt);
284 298
285 if (NILP (c)) 299 if (NILP (c))
286 signal_simple_error ("last typed character has no ASCII equivalent", 300 signal_simple_error ("Last typed character has no ASCII equivalent",
287 Fcopy_event (Vlast_command_event, Qnil)); 301 Fcopy_event (Vlast_command_event, Qnil));
288 302
289 CHECK_CHAR_COERCE_INT (c); 303 CHECK_CHAR_COERCE_INT (c);
290 304
291 n = XINT (arg);
292 ch = XCHAR (c); 305 ch = XCHAR (c);
293 #if 0 /* FSFmacs */ 306
294 /* #### This optimization won't work because of differences in 307 while (count--)
295 how the start-open and end-open properties default for text 308 internal_self_insert (ch, (count != 0));
296 properties. See internal_self_insert(). */ 309
297 if (n >= 2 && NILP (current_buffer->overwrite_mode))
298 {
299 n -= 2;
300 /* The first one might want to expand an abbrev. */
301 internal_self_insert (c, 1);
302 /* The bulk of the copies of this char can be inserted simply.
303 We don't have to handle a user-specified face specially
304 because it will get inherited from the first char inserted. */
305 Finsert_char (make_char (c), make_int (n), Qt, Qnil);
306 /* The last one might want to auto-fill. */
307 internal_self_insert (c, 0);
308 }
309 else
310 #endif /* 0 */
311 while (n > 0)
312 {
313 n--;
314 internal_self_insert (ch, (n != 0));
315 }
316 return Qnil; 310 return Qnil;
317 } 311 }
318 312
319 /* Insert character C1. If NOAUTOFILL is nonzero, don't do autofill 313 /* Insert character C1. If NOAUTOFILL is nonzero, don't do autofill
320 even if it is enabled. 314 even if it is enabled.
333 REGISTER enum syntaxcode synt; 327 REGISTER enum syntaxcode synt;
334 REGISTER Emchar c2; 328 REGISTER Emchar c2;
335 Lisp_Object overwrite; 329 Lisp_Object overwrite;
336 struct Lisp_Char_Table *syntax_table; 330 struct Lisp_Char_Table *syntax_table;
337 struct buffer *buf = current_buffer; 331 struct buffer *buf = current_buffer;
332 int tab_width;
338 333
339 overwrite = buf->overwrite_mode; 334 overwrite = buf->overwrite_mode;
340 syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); 335 syntax_table = XCHAR_TABLE (buf->mirror_syntax_table);
341 336
342 #if 0 337 #if 0
352 && BUF_PT (buf) < BUF_ZV (buf) 347 && BUF_PT (buf) < BUF_ZV (buf)
353 && (EQ (overwrite, Qoverwrite_mode_binary) 348 && (EQ (overwrite, Qoverwrite_mode_binary)
354 || (c1 != '\n' && BUF_FETCH_CHAR (buf, BUF_PT (buf)) != '\n')) 349 || (c1 != '\n' && BUF_FETCH_CHAR (buf, BUF_PT (buf)) != '\n'))
355 && (EQ (overwrite, Qoverwrite_mode_binary) 350 && (EQ (overwrite, Qoverwrite_mode_binary)
356 || BUF_FETCH_CHAR (buf, BUF_PT (buf)) != '\t' 351 || BUF_FETCH_CHAR (buf, BUF_PT (buf)) != '\t'
357 || XINT (buf->tab_width) <= 0 352 || ((tab_width = XINT (buf->tab_width), tab_width <= 0)
358 || XINT (buf->tab_width) > 20 353 || tab_width > 20
359 || !((current_column (buf) + 1) % XINT (buf->tab_width)))) 354 || !((current_column (buf) + 1) % tab_width))))
360 { 355 {
361 buffer_delete_range (buf, BUF_PT (buf), BUF_PT (buf) + 1, 0); 356 buffer_delete_range (buf, BUF_PT (buf), BUF_PT (buf) + 1, 0);
362 /* hairy = 2; */ 357 /* hairy = 2; */
363 } 358 }
364 359