Commit aa801467 authored by Kenichi Handa's avatar Kenichi Handa
Browse files

(Fsubst_char_in_region): Adjust the way to check byte-combining

possibility for the new handling of multibyte sequence.
parent ac4137cc
...@@ -1953,7 +1953,11 @@ Both characters must have the same length of multi-byte form.") ...@@ -1953,7 +1953,11 @@ Both characters must have the same length of multi-byte form.")
int changed = 0; int changed = 0;
unsigned char fromwork[4], *fromstr, towork[4], *tostr, *p; unsigned char fromwork[4], *fromstr, towork[4], *tostr, *p;
int count = specpdl_ptr - specpdl; int count = specpdl_ptr - specpdl;
int maybe_byte_combining = 0; #define COMBINING_NO 0
#define COMBINING_BEFORE 1
#define COMBINING_AFTER 2
#define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
int maybe_byte_combining = COMBINING_NO;
validate_region (&start, &end); validate_region (&start, &end);
CHECK_NUMBER (fromchar, 2); CHECK_NUMBER (fromchar, 2);
...@@ -1964,11 +1968,17 @@ Both characters must have the same length of multi-byte form.") ...@@ -1964,11 +1968,17 @@ Both characters must have the same length of multi-byte form.")
len = CHAR_STRING (XFASTINT (fromchar), fromwork, fromstr); len = CHAR_STRING (XFASTINT (fromchar), fromwork, fromstr);
if (CHAR_STRING (XFASTINT (tochar), towork, tostr) != len) if (CHAR_STRING (XFASTINT (tochar), towork, tostr) != len)
error ("Characters in subst-char-in-region have different byte-lengths"); error ("Characters in subst-char-in-region have different byte-lengths");
if (len == 1) if (!ASCII_BYTE_P (*tostr))
/* If *TOSTR is in the range 0x80..0x9F, it may be combined {
with the after bytes. If it is in the range 0xA0..0xFF, it /* If *TOSTR is in the range 0x80..0x9F and TOCHAR is not a
may be combined with the before bytes. */ complete multibyte character, it may be combined with the
maybe_byte_combining = !ASCII_BYTE_P (*tostr); after bytes. If it is in the range 0xA0..0xFF, it may be
combined with the before and after bytes. */
if (!CHAR_HEAD_P (*tostr))
maybe_byte_combining = COMBINING_BOTH;
else if (BYTES_BY_CHAR_HEAD (*tostr) > len)
maybe_byte_combining = COMBINING_AFTER;
}
} }
else else
{ {
...@@ -2035,10 +2045,13 @@ Both characters must have the same length of multi-byte form.") ...@@ -2035,10 +2045,13 @@ Both characters must have the same length of multi-byte form.")
/* Take care of the case where the new character /* Take care of the case where the new character
combines with neighboring bytes. */ combines with neighboring bytes. */
if (maybe_byte_combining if (maybe_byte_combining
&& (CHAR_HEAD_P (*tostr) && (maybe_byte_combining == COMBINING_AFTER
? ! CHAR_HEAD_P (FETCH_BYTE (pos_byte + 1)) ? (pos_byte_next < Z_BYTE
: (pos_byte > BEG_BYTE && ! CHAR_HEAD_P (FETCH_BYTE (pos_byte_next)))
&& ! ASCII_BYTE_P (FETCH_BYTE (pos_byte - 1))))) : ((pos_byte_next < Z_BYTE
&& ! CHAR_HEAD_P (FETCH_BYTE (pos_byte_next)))
|| (pos_byte > BEG_BYTE
&& ! ASCII_BYTE_P (FETCH_BYTE (pos_byte - 1))))))
{ {
Lisp_Object tem, string; Lisp_Object tem, string;
...@@ -2047,9 +2060,8 @@ Both characters must have the same length of multi-byte form.") ...@@ -2047,9 +2060,8 @@ Both characters must have the same length of multi-byte form.")
tem = current_buffer->undo_list; tem = current_buffer->undo_list;
GCPRO1 (tem); GCPRO1 (tem);
/* Make a multibyte string containing this single-byte /* Make a multibyte string containing this single character. */
character. */ string = make_multibyte_string (tostr, 1, len);
string = make_multibyte_string (tostr, 1, 1);
/* replace_range is less efficient, because it moves the gap, /* replace_range is less efficient, because it moves the gap,
but it handles combining correctly. */ but it handles combining correctly. */
replace_range (pos, pos + 1, string, replace_range (pos, pos + 1, string,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment