aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2010-09-01 16:41:17 +0200
committerStefan Monnier2010-09-01 16:41:17 +0200
commit8f4e9110cad4aa7fbbfa4765221f4a6392ca7af3 (patch)
tree3dee31a308543acddc9363cd2e6638f962f8c695 /src
parent4de81ee0d223f3ffda6c22ac630ace93f0fc47f7 (diff)
downloademacs-8f4e9110cad4aa7fbbfa4765221f4a6392ca7af3.tar.gz
emacs-8f4e9110cad4aa7fbbfa4765221f4a6392ca7af3.zip
* lisp/simple.el (blink-paren-function): Move from C to here.
(blink-paren-post-self-insert-function): New function. (post-self-insert-hook): Use it. * src/cmds.c (Vblink_paren_function): Remove. (internal_self_insert): Make it insert N chars at a time. Don't call blink-paren-function. (Fself_insert_command): Adjust accordingly. (syms_of_cmds): Don't declare blink-paren-function.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/cmds.c105
2 files changed, 48 insertions, 65 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index fc98bcc11e3..db8cc1186a5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
12010-09-01 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * cmds.c (Vblink_paren_function): Remove.
4 (internal_self_insert): Make it insert N chars at a time.
5 Don't call blink-paren-function.
6 (Fself_insert_command): Adjust accordingly.
7 (syms_of_cmds): Don't declare blink-paren-function.
8
12010-08-31 Stefan Monnier <monnier@iro.umontreal.ca> 92010-08-31 Stefan Monnier <monnier@iro.umontreal.ca>
2 10
3 * keyboard.c (Fwindow_system): Fix compilation for USE_LISP_UNION_TYPE. 11 * keyboard.c (Fwindow_system): Fix compilation for USE_LISP_UNION_TYPE.
diff --git a/src/cmds.c b/src/cmds.c
index f306ede7ca5..f12e759b7a6 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -32,7 +32,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
32#include "dispextern.h" 32#include "dispextern.h"
33#include "frame.h" 33#include "frame.h"
34 34
35Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function; 35Lisp_Object Qkill_forward_chars, Qkill_backward_chars;
36 36
37/* A possible value for a buffer's overwrite-mode variable. */ 37/* A possible value for a buffer's overwrite-mode variable. */
38Lisp_Object Qoverwrite_mode_binary; 38Lisp_Object Qoverwrite_mode_binary;
@@ -304,36 +304,16 @@ After insertion, the value of `auto-fill-function' is called if the
304 { 304 {
305 int character = translate_char (Vtranslation_table_for_input, 305 int character = translate_char (Vtranslation_table_for_input,
306 XINT (last_command_event)); 306 XINT (last_command_event));
307 if (XINT (n) >= 2 && NILP (current_buffer->overwrite_mode)) 307 int val = internal_self_insert (character, XFASTINT (n));
308 { 308 if (val == 2)
309 XSETFASTINT (n, XFASTINT (n) - 2); 309 nonundocount = 0;
310 /* The first one might want to expand an abbrev. */ 310 frame_make_pointer_invisible ();
311 internal_self_insert (character, 1);
312 /* The bulk of the copies of this char can be inserted simply.
313 We don't have to handle a user-specified face specially
314 because it will get inherited from the first char inserted. */
315 Finsert_char (make_number (character), n, Qt);
316 /* The last one might want to auto-fill. */
317 internal_self_insert (character, 0);
318 }
319 else
320 while (XINT (n) > 0)
321 {
322 int val;
323 /* Ok since old and new vals both nonneg */
324 XSETFASTINT (n, XFASTINT (n) - 1);
325 val = internal_self_insert (character, XFASTINT (n) != 0);
326 if (val == 2)
327 nonundocount = 0;
328 frame_make_pointer_invisible ();
329 }
330 } 311 }
331 312
332 return Qnil; 313 return Qnil;
333} 314}
334 315
335/* Insert character C. If NOAUTOFILL is nonzero, don't do autofill 316/* Insert N times character C
336 even if it is enabled.
337 317
338 If this insertion is suitable for direct output (completely simple), 318 If this insertion is suitable for direct output (completely simple),
339 return 0. A value of 1 indicates this *might* not have been simple. 319 return 0. A value of 1 indicates this *might* not have been simple.
@@ -343,12 +323,12 @@ static Lisp_Object Qexpand_abbrev;
343static Lisp_Object Qpost_self_insert_hook, Vpost_self_insert_hook; 323static Lisp_Object Qpost_self_insert_hook, Vpost_self_insert_hook;
344 324
345static int 325static int
346internal_self_insert (int c, int noautofill) 326internal_self_insert (int c, int n)
347{ 327{
348 int hairy = 0; 328 int hairy = 0;
349 Lisp_Object tem; 329 Lisp_Object tem;
350 register enum syntaxcode synt; 330 register enum syntaxcode synt;
351 Lisp_Object overwrite, string; 331 Lisp_Object overwrite;
352 /* Length of multi-byte form of C. */ 332 /* Length of multi-byte form of C. */
353 int len; 333 int len;
354 /* Working buffer and pointer for multi-byte form of C. */ 334 /* Working buffer and pointer for multi-byte form of C. */
@@ -391,32 +371,22 @@ internal_self_insert (int c, int noautofill)
391 /* This is the character after point. */ 371 /* This is the character after point. */
392 int c2 = FETCH_CHAR (PT_BYTE); 372 int c2 = FETCH_CHAR (PT_BYTE);
393 373
394 /* Column the cursor should be placed at after this insertion.
395 The correct value should be calculated only when necessary. */
396 int target_clm = 0;
397
398 /* Overwriting in binary-mode always replaces C2 by C. 374 /* Overwriting in binary-mode always replaces C2 by C.
399 Overwriting in textual-mode doesn't always do that. 375 Overwriting in textual-mode doesn't always do that.
400 It inserts newlines in the usual way, 376 It inserts newlines in the usual way,
401 and inserts any character at end of line 377 and inserts any character at end of line
402 or before a tab if it doesn't use the whole width of the tab. */ 378 or before a tab if it doesn't use the whole width of the tab. */
403 if (EQ (overwrite, Qoverwrite_mode_binary) 379 if (EQ (overwrite, Qoverwrite_mode_binary))
404 || (c != '\n' 380 chars_to_delete = n;
405 && c2 != '\n' 381 else if (c != '\n' && c2 != '\n')
406 && ! (c2 == '\t'
407 && XINT (current_buffer->tab_width) > 0
408 && XFASTINT (current_buffer->tab_width) < 20
409 && (target_clm = ((int) current_column () /* iftc */
410 + XINT (Fchar_width (make_number (c)))),
411 target_clm % XFASTINT (current_buffer->tab_width)))))
412 { 382 {
413 int pos = PT; 383 int pos = PT;
414 int pos_byte = PT_BYTE; 384 int pos_byte = PT_BYTE;
385 /* Column the cursor should be placed at after this insertion.
386 The correct value should be calculated only when necessary. */
387 int target_clm = ((int) current_column () /* iftc */
388 + n * XINT (Fchar_width (make_number (c))));
415 389
416 if (target_clm == 0)
417 chars_to_delete = 1;
418 else
419 {
420 /* The actual cursor position after the trial of moving 390 /* The actual cursor position after the trial of moving
421 to column TARGET_CLM. It is greater than TARGET_CLM 391 to column TARGET_CLM. It is greater than TARGET_CLM
422 if the TARGET_CLM is middle of multi-column 392 if the TARGET_CLM is middle of multi-column
@@ -428,14 +398,18 @@ internal_self_insert (int c, int noautofill)
428 chars_to_delete = PT - pos; 398 chars_to_delete = PT - pos;
429 399
430 if (actual_clm > target_clm) 400 if (actual_clm > target_clm)
431 { 401 { /* We will delete too many columns. Let's fill columns
432 /* We will delete too many columns. Let's fill columns
433 by spaces so that the remaining text won't move. */ 402 by spaces so that the remaining text won't move. */
403 EMACS_INT actual = PT_BYTE;
404 DEC_POS (actual);
405 if (FETCH_CHAR (actual) == '\t')
406 /* Rather than add spaces, let's just keep the tab. */
407 chars_to_delete--;
408 else
434 spaces_to_insert = actual_clm - target_clm; 409 spaces_to_insert = actual_clm - target_clm;
435 } 410 }
436 } 411
437 SET_PT_BOTH (pos, pos_byte); 412 SET_PT_BOTH (pos, pos_byte);
438 hairy = 2;
439 } 413 }
440 hairy = 2; 414 hairy = 2;
441 } 415 }
@@ -474,16 +448,30 @@ internal_self_insert (int c, int noautofill)
474 448
475 if (chars_to_delete) 449 if (chars_to_delete)
476 { 450 {
477 string = make_string_from_bytes (str, 1, len); 451 int mc = ((NILP (current_buffer->enable_multibyte_characters)
452 && SINGLE_BYTE_CHAR_P (c))
453 ? UNIBYTE_TO_CHAR (c) : c);
454 Lisp_Object string = Fmake_string (make_number (n), make_number (mc));
455
478 if (spaces_to_insert) 456 if (spaces_to_insert)
479 { 457 {
480 tem = Fmake_string (make_number (spaces_to_insert), 458 tem = Fmake_string (make_number (spaces_to_insert),
481 make_number (' ')); 459 make_number (' '));
482 string = concat2 (tem, string); 460 string = concat2 (string, tem);
483 } 461 }
484 462
485 replace_range (PT, PT + chars_to_delete, string, 1, 1, 1); 463 replace_range (PT, PT + chars_to_delete, string, 1, 1, 1);
486 Fforward_char (make_number (1 + spaces_to_insert)); 464 Fforward_char (make_number (n + spaces_to_insert));
465 }
466 else if (n > 1)
467 {
468 USE_SAFE_ALLOCA;
469 unsigned char *strn, *p;
470 SAFE_ALLOCA (strn, unsigned char*, n * len);
471 for (p = strn; n > 0; n--, p += len)
472 memcpy (p, str, len);
473 insert_and_inherit (strn, p - strn);
474 SAFE_FREE ();
487 } 475 }
488 else 476 else
489 insert_and_inherit (str, len); 477 insert_and_inherit (str, len);
@@ -491,7 +479,6 @@ internal_self_insert (int c, int noautofill)
491 if ((CHAR_TABLE_P (Vauto_fill_chars) 479 if ((CHAR_TABLE_P (Vauto_fill_chars)
492 ? !NILP (CHAR_TABLE_REF (Vauto_fill_chars, c)) 480 ? !NILP (CHAR_TABLE_REF (Vauto_fill_chars, c))
493 : (c == ' ' || c == '\n')) 481 : (c == ' ' || c == '\n'))
494 && !noautofill
495 && !NILP (current_buffer->auto_fill_function)) 482 && !NILP (current_buffer->auto_fill_function))
496 { 483 {
497 Lisp_Object tem; 484 Lisp_Object tem;
@@ -509,13 +496,6 @@ internal_self_insert (int c, int noautofill)
509 hairy = 2; 496 hairy = 2;
510 } 497 }
511 498
512 if ((synt == Sclose || synt == Smath)
513 && !NILP (Vblink_paren_function) && INTERACTIVE
514 && !noautofill)
515 {
516 call0 (Vblink_paren_function);
517 hairy = 2;
518 }
519 /* Run hooks for electric keys. */ 499 /* Run hooks for electric keys. */
520 call1 (Vrun_hooks, Qpost_self_insert_hook); 500 call1 (Vrun_hooks, Qpost_self_insert_hook);
521 501
@@ -547,11 +527,6 @@ syms_of_cmds (void)
547This run is run after inserting the charater. */); 527This run is run after inserting the charater. */);
548 Vpost_self_insert_hook = Qnil; 528 Vpost_self_insert_hook = Qnil;
549 529
550 DEFVAR_LISP ("blink-paren-function", &Vblink_paren_function,
551 doc: /* Function called, if non-nil, whenever a close parenthesis is inserted.
552More precisely, a char with closeparen syntax is self-inserted. */);
553 Vblink_paren_function = Qnil;
554
555 defsubr (&Sforward_point); 530 defsubr (&Sforward_point);
556 defsubr (&Sforward_char); 531 defsubr (&Sforward_char);
557 defsubr (&Sbackward_char); 532 defsubr (&Sbackward_char);