aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorKenichi Handa2004-03-01 06:36:08 +0000
committerKenichi Handa2004-03-01 06:36:08 +0000
commitc99ffedf9a319290b1feb4643b73e2642d5c41ee (patch)
tree4a57d626c56b1f213082b6652500370610ec276d /src/editfns.c
parent10475277ce0d5f813792940aabbd270ebd717f02 (diff)
downloademacs-c99ffedf9a319290b1feb4643b73e2642d5c41ee.tar.gz
emacs-c99ffedf9a319290b1feb4643b73e2642d5c41ee.zip
(Ftranslate_region): Fix previous change
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 31493e3c774..15ee794d064 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2747,12 +2747,11 @@ It returns the number of characters changed. */)
2747 Lisp_Object end; 2747 Lisp_Object end;
2748 register Lisp_Object table; 2748 register Lisp_Object table;
2749{ 2749{
2750 register int pos_byte, stop; /* Limits of the region. */
2751 register unsigned char *tt; /* Trans table. */ 2750 register unsigned char *tt; /* Trans table. */
2752 register int nc; /* New character. */ 2751 register int nc; /* New character. */
2753 int cnt; /* Number of changes made. */ 2752 int cnt; /* Number of changes made. */
2754 int size; /* Size of translate table. */ 2753 int size; /* Size of translate table. */
2755 int pos; 2754 int pos, pos_byte;
2756 int multibyte = !NILP (current_buffer->enable_multibyte_characters); 2755 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
2757 int string_multibyte; 2756 int string_multibyte;
2758 2757
@@ -2768,25 +2767,22 @@ It returns the number of characters changed. */)
2768 size = SCHARS (table); 2767 size = SCHARS (table);
2769 tt = SDATA (table); 2768 tt = SDATA (table);
2770 2769
2771 pos_byte = CHAR_TO_BYTE (XINT (start));
2772 stop = CHAR_TO_BYTE (XINT (end));
2773 modify_region (current_buffer, XINT (start), XINT (end));
2774 pos = XINT (start); 2770 pos = XINT (start);
2771 pos_byte = CHAR_TO_BYTE (pos);
2772 modify_region (current_buffer, pos, XINT (end));
2775 2773
2776 cnt = 0; 2774 cnt = 0;
2777 for (; pos_byte < stop; ) 2775 for (; pos < end; )
2778 { 2776 {
2779 register unsigned char *p = BYTE_POS_ADDR (pos_byte); 2777 register unsigned char *p = BYTE_POS_ADDR (pos_byte);
2780 unsigned char *str; 2778 unsigned char *str;
2781 int len, str_len; 2779 int len, str_len;
2782 int oc; 2780 int oc;
2783 int pos_byte_next;
2784 2781
2785 if (multibyte) 2782 if (multibyte)
2786 oc = STRING_CHAR_AND_LENGTH (p, stop - pos_byte, len); 2783 oc = STRING_CHAR_AND_LENGTH (p, MAX_MULTIBYTE_LENGTH, len);
2787 else 2784 else
2788 oc = *p, len = 1; 2785 oc = *p, len = 1;
2789 pos_byte_next = pos_byte + len;
2790 if (oc < size) 2786 if (oc < size)
2791 { 2787 {
2792 if (string_multibyte) 2788 if (string_multibyte)
@@ -2801,25 +2797,15 @@ It returns the number of characters changed. */)
2801 } 2797 }
2802 if (nc != oc) 2798 if (nc != oc)
2803 { 2799 {
2804 /* Take care of the case where the new character 2800 if (len != str_len)
2805 combines with neighboring bytes. */
2806 if (len > 1 || str_len > 1)
2807 { 2801 {
2808 Lisp_Object string; 2802 Lisp_Object string;
2809 2803
2810 string = make_multibyte_string (str, 1, str_len);
2811 /* This is less efficient, because it moves the gap, 2804 /* This is less efficient, because it moves the gap,
2812 but it handles combining correctly. */ 2805 but it should multibyte characters correctly. */
2813 replace_range (pos, pos + 1, string, 2806 string = make_multibyte_string (str, 1, str_len);
2814 1, 0, 1); 2807 replace_range (pos, pos + 1, string, 1, 0, 1);
2815 pos_byte_next = CHAR_TO_BYTE (pos); 2808 len = str_len;
2816 if (pos_byte_next > pos_byte)
2817 /* Before combining happened. We should not
2818 increment POS. So, to cancel the later
2819 increment of POS, we decrease it now. */
2820 pos--;
2821 else
2822 INC_POS (pos_byte_next);
2823 } 2809 }
2824 else 2810 else
2825 { 2811 {
@@ -2832,7 +2818,7 @@ It returns the number of characters changed. */)
2832 ++cnt; 2818 ++cnt;
2833 } 2819 }
2834 } 2820 }
2835 pos_byte = pos_byte_next; 2821 pos_byte += len;
2836 pos++; 2822 pos++;
2837 } 2823 }
2838 2824