diff options
| author | Richard M. Stallman | 1998-08-03 22:25:08 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-08-03 22:25:08 +0000 |
| commit | 0c1e3b856ccc921729fc5498e414f33359b25b3f (patch) | |
| tree | 0095b0cda0ea1370ac52563473c56c461a9cc650 /src | |
| parent | 5fdc799747e1d5da93fc50d5ce45a84fe456155b (diff) | |
| download | emacs-0c1e3b856ccc921729fc5498e414f33359b25b3f.tar.gz emacs-0c1e3b856ccc921729fc5498e414f33359b25b3f.zip | |
(Fsubst_char_in_region): Use replace_range in the case
where we may need to combine bytes.
(Ftranslate_region): Likewise.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 71 |
1 files changed, 65 insertions, 6 deletions
diff --git a/src/editfns.c b/src/editfns.c index aca1a3455e1..c3cdad96aa0 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -1938,9 +1938,44 @@ Both characters must have the same length of multi-byte form.") | |||
| 1938 | changed = 1; | 1938 | changed = 1; |
| 1939 | } | 1939 | } |
| 1940 | 1940 | ||
| 1941 | if (NILP (noundo)) | 1941 | /* Take care of the case where the new character |
| 1942 | record_change (pos, 1); | 1942 | combines with neighboring bytes. */ |
| 1943 | for (i = 0; i < len; i++) *p++ = tostr[i]; | 1943 | if (len == 1 |
| 1944 | && ((! CHAR_HEAD_P (tostr[0]) | ||
| 1945 | && pos_byte > BEGV_BYTE | ||
| 1946 | && ! ASCII_BYTE_P (FETCH_BYTE (pos_byte - 1))) | ||
| 1947 | || | ||
| 1948 | (! ASCII_BYTE_P (tostr[0]) | ||
| 1949 | && pos_byte + 1 < ZV_BYTE | ||
| 1950 | && ! CHAR_HEAD_P (FETCH_BYTE (pos_byte + 1))))) | ||
| 1951 | { | ||
| 1952 | Lisp_Object tem, string; | ||
| 1953 | |||
| 1954 | struct gcpro gcpro1; | ||
| 1955 | |||
| 1956 | tem = current_buffer->undo_list; | ||
| 1957 | GCPRO1 (tem); | ||
| 1958 | |||
| 1959 | /* Make a multibyte string containing this | ||
| 1960 | single-byte character. */ | ||
| 1961 | string = Fmake_string (make_number (1), | ||
| 1962 | make_number (tochar)); | ||
| 1963 | SET_STRING_BYTES (XSTRING (string), 1); | ||
| 1964 | /* replace_range is less efficient, because it moves the gap, | ||
| 1965 | but it handles combining correctly. */ | ||
| 1966 | replace_range (pos, pos + 1, string, | ||
| 1967 | 0, 0, 0); | ||
| 1968 | if (! NILP (noundo)) | ||
| 1969 | current_buffer->undo_list = tem; | ||
| 1970 | |||
| 1971 | UNGCPRO; | ||
| 1972 | } | ||
| 1973 | else | ||
| 1974 | { | ||
| 1975 | if (NILP (noundo)) | ||
| 1976 | record_change (pos, 1); | ||
| 1977 | for (i = 0; i < len; i++) *p++ = tostr[i]; | ||
| 1978 | } | ||
| 1944 | } | 1979 | } |
| 1945 | INC_BOTH (pos, pos_byte); | 1980 | INC_BOTH (pos, pos_byte); |
| 1946 | } | 1981 | } |
| @@ -1995,9 +2030,33 @@ It returns the number of characters changed.") | |||
| 1995 | nc = tt[oc]; | 2030 | nc = tt[oc]; |
| 1996 | if (nc != oc) | 2031 | if (nc != oc) |
| 1997 | { | 2032 | { |
| 1998 | record_change (pos, 1); | 2033 | /* Take care of the case where the new character |
| 1999 | *p = nc; | 2034 | combines with neighboring bytes. */ |
| 2000 | signal_after_change (pos, 1, 1); | 2035 | if ((! CHAR_HEAD_P (nc) |
| 2036 | && pos_byte > BEGV_BYTE | ||
| 2037 | && ! ASCII_BYTE_P (FETCH_BYTE (pos_byte - 1))) | ||
| 2038 | || | ||
| 2039 | (! ASCII_BYTE_P (nc) | ||
| 2040 | && pos_byte + 1 < ZV_BYTE | ||
| 2041 | && ! CHAR_HEAD_P (FETCH_BYTE (pos_byte + 1)))) | ||
| 2042 | { | ||
| 2043 | Lisp_Object string; | ||
| 2044 | |||
| 2045 | string = Fmake_string (make_number (1), | ||
| 2046 | make_number (nc)); | ||
| 2047 | SET_STRING_BYTES (XSTRING (string), 1); | ||
| 2048 | |||
| 2049 | /* This is less efficient, because it moves the gap, | ||
| 2050 | but it handles combining correctly. */ | ||
| 2051 | replace_range (pos, pos + 1, string, | ||
| 2052 | 1, 0, 0); | ||
| 2053 | } | ||
| 2054 | else | ||
| 2055 | { | ||
| 2056 | record_change (pos, 1); | ||
| 2057 | *p = nc; | ||
| 2058 | signal_after_change (pos, 1, 1); | ||
| 2059 | } | ||
| 2001 | ++cnt; | 2060 | ++cnt; |
| 2002 | } | 2061 | } |
| 2003 | } | 2062 | } |