diff options
| author | Stefan Monnier | 2006-08-04 15:22:09 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2006-08-04 15:22:09 +0000 |
| commit | 0f2e2a3bbc74a84038de18603e5d734f38fa9db4 (patch) | |
| tree | 7e3ff691dea8e026c5e3dfacfd90af0679de3bf1 /src | |
| parent | 316a275a1e626f7689affcf96f4e98953a6b5c97 (diff) | |
| download | emacs-0f2e2a3bbc74a84038de18603e5d734f38fa9db4.tar.gz emacs-0f2e2a3bbc74a84038de18603e5d734f38fa9db4.zip | |
(Fsubst_char_in_region): Redo the setup work after running
the before-change-functions since they may have altered the buffer.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/editfns.c | 24 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 52847a7fe1f..49c4649d144 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2006-08-04 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * editfns.c (Fsubst_char_in_region): Redo the setup work after running | ||
| 4 | the before-change-functions since they may have altered the buffer. | ||
| 5 | |||
| 1 | 2006-08-04 Ralf Angeli <angeli@caeruleus.net> | 6 | 2006-08-04 Ralf Angeli <angeli@caeruleus.net> |
| 2 | 7 | ||
| 3 | * w32fns.c (w32_createwindow): Handle -geometry command line option | 8 | * w32fns.c (w32_createwindow): Handle -geometry command line option |
diff --git a/src/editfns.c b/src/editfns.c index e692204c702..8ac61f3d006 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2691,6 +2691,10 @@ Both characters must have the same length of multi-byte form. */) | |||
| 2691 | Lisp_Object start, end, fromchar, tochar, noundo; | 2691 | Lisp_Object start, end, fromchar, tochar, noundo; |
| 2692 | { | 2692 | { |
| 2693 | register int pos, pos_byte, stop, i, len, end_byte; | 2693 | register int pos, pos_byte, stop, i, len, end_byte; |
| 2694 | /* Keep track of the first change in the buffer: | ||
| 2695 | if 0 we haven't found it yet. | ||
| 2696 | if < 0 we've found it and we've run the before-change-function. | ||
| 2697 | if > 0 we've actually performed it and the value is its position. */ | ||
| 2694 | int changed = 0; | 2698 | int changed = 0; |
| 2695 | unsigned char fromstr[MAX_MULTIBYTE_LENGTH], tostr[MAX_MULTIBYTE_LENGTH]; | 2699 | unsigned char fromstr[MAX_MULTIBYTE_LENGTH], tostr[MAX_MULTIBYTE_LENGTH]; |
| 2696 | unsigned char *p; | 2700 | unsigned char *p; |
| @@ -2703,6 +2707,8 @@ Both characters must have the same length of multi-byte form. */) | |||
| 2703 | int last_changed = 0; | 2707 | int last_changed = 0; |
| 2704 | int multibyte_p = !NILP (current_buffer->enable_multibyte_characters); | 2708 | int multibyte_p = !NILP (current_buffer->enable_multibyte_characters); |
| 2705 | 2709 | ||
| 2710 | restart: | ||
| 2711 | |||
| 2706 | validate_region (&start, &end); | 2712 | validate_region (&start, &end); |
| 2707 | CHECK_NUMBER (fromchar); | 2713 | CHECK_NUMBER (fromchar); |
| 2708 | CHECK_NUMBER (tochar); | 2714 | CHECK_NUMBER (tochar); |
| @@ -2740,7 +2746,7 @@ Both characters must have the same length of multi-byte form. */) | |||
| 2740 | That's faster than getting rid of things, | 2746 | That's faster than getting rid of things, |
| 2741 | and it prevents even the entry for a first change. | 2747 | and it prevents even the entry for a first change. |
| 2742 | Also inhibit locking the file. */ | 2748 | Also inhibit locking the file. */ |
| 2743 | if (!NILP (noundo)) | 2749 | if (!changed && !NILP (noundo)) |
| 2744 | { | 2750 | { |
| 2745 | record_unwind_protect (subst_char_in_region_unwind, | 2751 | record_unwind_protect (subst_char_in_region_unwind, |
| 2746 | current_buffer->undo_list); | 2752 | current_buffer->undo_list); |
| @@ -2774,10 +2780,14 @@ Both characters must have the same length of multi-byte form. */) | |||
| 2774 | && (len == 2 || (p[2] == fromstr[2] | 2780 | && (len == 2 || (p[2] == fromstr[2] |
| 2775 | && (len == 3 || p[3] == fromstr[3])))))) | 2781 | && (len == 3 || p[3] == fromstr[3])))))) |
| 2776 | { | 2782 | { |
| 2777 | if (! changed) | 2783 | if (changed < 0) |
| 2784 | /* We've already seen this and run the before-change-function; | ||
| 2785 | this time we only need to record the actual position. */ | ||
| 2786 | changed = pos; | ||
| 2787 | else if (!changed) | ||
| 2778 | { | 2788 | { |
| 2779 | changed = pos; | 2789 | changed = -1; |
| 2780 | modify_region (current_buffer, changed, XINT (end)); | 2790 | modify_region (current_buffer, pos, XINT (end)); |
| 2781 | 2791 | ||
| 2782 | if (! NILP (noundo)) | 2792 | if (! NILP (noundo)) |
| 2783 | { | 2793 | { |
| @@ -2786,6 +2796,10 @@ Both characters must have the same length of multi-byte form. */) | |||
| 2786 | if (MODIFF - 1 == current_buffer->auto_save_modified) | 2796 | if (MODIFF - 1 == current_buffer->auto_save_modified) |
| 2787 | current_buffer->auto_save_modified++; | 2797 | current_buffer->auto_save_modified++; |
| 2788 | } | 2798 | } |
| 2799 | |||
| 2800 | /* The before-change-function may have moved the gap | ||
| 2801 | or even modified the buffer so we should start over. */ | ||
| 2802 | goto restart; | ||
| 2789 | } | 2803 | } |
| 2790 | 2804 | ||
| 2791 | /* Take care of the case where the new character | 2805 | /* Take care of the case where the new character |
| @@ -2838,7 +2852,7 @@ Both characters must have the same length of multi-byte form. */) | |||
| 2838 | pos++; | 2852 | pos++; |
| 2839 | } | 2853 | } |
| 2840 | 2854 | ||
| 2841 | if (changed) | 2855 | if (changed > 0) |
| 2842 | { | 2856 | { |
| 2843 | signal_after_change (changed, | 2857 | signal_after_change (changed, |
| 2844 | last_changed - changed, last_changed - changed); | 2858 | last_changed - changed, last_changed - changed); |