diff options
| author | Kenichi Handa | 1999-09-03 01:28:42 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1999-09-03 01:28:42 +0000 |
| commit | aa801467ea5017bd71f12dc2f2034d3dce15cb57 (patch) | |
| tree | 99f7f8f3bc17aec8d371f28b77e7ba9205764abb /src | |
| parent | ac4137cca636cd011ce43a595c9cf57126c0a558 (diff) | |
| download | emacs-aa801467ea5017bd71f12dc2f2034d3dce15cb57.tar.gz emacs-aa801467ea5017bd71f12dc2f2034d3dce15cb57.zip | |
(Fsubst_char_in_region): Adjust the way to check byte-combining
possibility for the new handling of multibyte sequence.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/editfns.c b/src/editfns.c index 5c379e0a6c9..a12954a6ed7 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -1953,7 +1953,11 @@ Both characters must have the same length of multi-byte form.") | |||
| 1953 | int changed = 0; | 1953 | int changed = 0; |
| 1954 | unsigned char fromwork[4], *fromstr, towork[4], *tostr, *p; | 1954 | unsigned char fromwork[4], *fromstr, towork[4], *tostr, *p; |
| 1955 | int count = specpdl_ptr - specpdl; | 1955 | int count = specpdl_ptr - specpdl; |
| 1956 | int maybe_byte_combining = 0; | 1956 | #define COMBINING_NO 0 |
| 1957 | #define COMBINING_BEFORE 1 | ||
| 1958 | #define COMBINING_AFTER 2 | ||
| 1959 | #define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER) | ||
| 1960 | int maybe_byte_combining = COMBINING_NO; | ||
| 1957 | 1961 | ||
| 1958 | validate_region (&start, &end); | 1962 | validate_region (&start, &end); |
| 1959 | CHECK_NUMBER (fromchar, 2); | 1963 | CHECK_NUMBER (fromchar, 2); |
| @@ -1964,11 +1968,17 @@ Both characters must have the same length of multi-byte form.") | |||
| 1964 | len = CHAR_STRING (XFASTINT (fromchar), fromwork, fromstr); | 1968 | len = CHAR_STRING (XFASTINT (fromchar), fromwork, fromstr); |
| 1965 | if (CHAR_STRING (XFASTINT (tochar), towork, tostr) != len) | 1969 | if (CHAR_STRING (XFASTINT (tochar), towork, tostr) != len) |
| 1966 | error ("Characters in subst-char-in-region have different byte-lengths"); | 1970 | error ("Characters in subst-char-in-region have different byte-lengths"); |
| 1967 | if (len == 1) | 1971 | if (!ASCII_BYTE_P (*tostr)) |
| 1968 | /* If *TOSTR is in the range 0x80..0x9F, it may be combined | 1972 | { |
| 1969 | with the after bytes. If it is in the range 0xA0..0xFF, it | 1973 | /* If *TOSTR is in the range 0x80..0x9F and TOCHAR is not a |
| 1970 | may be combined with the before bytes. */ | 1974 | complete multibyte character, it may be combined with the |
| 1971 | maybe_byte_combining = !ASCII_BYTE_P (*tostr); | 1975 | after bytes. If it is in the range 0xA0..0xFF, it may be |
| 1976 | combined with the before and after bytes. */ | ||
| 1977 | if (!CHAR_HEAD_P (*tostr)) | ||
| 1978 | maybe_byte_combining = COMBINING_BOTH; | ||
| 1979 | else if (BYTES_BY_CHAR_HEAD (*tostr) > len) | ||
| 1980 | maybe_byte_combining = COMBINING_AFTER; | ||
| 1981 | } | ||
| 1972 | } | 1982 | } |
| 1973 | else | 1983 | else |
| 1974 | { | 1984 | { |
| @@ -2035,10 +2045,13 @@ Both characters must have the same length of multi-byte form.") | |||
| 2035 | /* Take care of the case where the new character | 2045 | /* Take care of the case where the new character |
| 2036 | combines with neighboring bytes. */ | 2046 | combines with neighboring bytes. */ |
| 2037 | if (maybe_byte_combining | 2047 | if (maybe_byte_combining |
| 2038 | && (CHAR_HEAD_P (*tostr) | 2048 | && (maybe_byte_combining == COMBINING_AFTER |
| 2039 | ? ! CHAR_HEAD_P (FETCH_BYTE (pos_byte + 1)) | 2049 | ? (pos_byte_next < Z_BYTE |
| 2040 | : (pos_byte > BEG_BYTE | 2050 | && ! CHAR_HEAD_P (FETCH_BYTE (pos_byte_next))) |
| 2041 | && ! ASCII_BYTE_P (FETCH_BYTE (pos_byte - 1))))) | 2051 | : ((pos_byte_next < Z_BYTE |
| 2052 | && ! CHAR_HEAD_P (FETCH_BYTE (pos_byte_next))) | ||
| 2053 | || (pos_byte > BEG_BYTE | ||
| 2054 | && ! ASCII_BYTE_P (FETCH_BYTE (pos_byte - 1)))))) | ||
| 2042 | { | 2055 | { |
| 2043 | Lisp_Object tem, string; | 2056 | Lisp_Object tem, string; |
| 2044 | 2057 | ||
| @@ -2047,9 +2060,8 @@ Both characters must have the same length of multi-byte form.") | |||
| 2047 | tem = current_buffer->undo_list; | 2060 | tem = current_buffer->undo_list; |
| 2048 | GCPRO1 (tem); | 2061 | GCPRO1 (tem); |
| 2049 | 2062 | ||
| 2050 | /* Make a multibyte string containing this single-byte | 2063 | /* Make a multibyte string containing this single character. */ |
| 2051 | character. */ | 2064 | string = make_multibyte_string (tostr, 1, len); |
| 2052 | string = make_multibyte_string (tostr, 1, 1); | ||
| 2053 | /* replace_range is less efficient, because it moves the gap, | 2065 | /* replace_range is less efficient, because it moves the gap, |
| 2054 | but it handles combining correctly. */ | 2066 | but it handles combining correctly. */ |
| 2055 | replace_range (pos, pos + 1, string, | 2067 | replace_range (pos, pos + 1, string, |