comparison src/editfns.c @ 22895:9f800ebc6091

(Fsubst_char_in_region): Use replace_range in the case where we may need to combine bytes. (Ftranslate_region): Likewise.
author Richard M. Stallman <rms@gnu.org>
date Mon, 03 Aug 1998 22:25:08 +0000
parents 6f129ed55108
children 6dda0a4b882f
comparison
equal deleted inserted replaced
22894:186b2098dcd8 22895:9f800ebc6091
1936 } 1936 }
1937 1937
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 }
1947 1982
1948 if (changed) 1983 if (changed)
1993 if (oc < size && len == 1) 2028 if (oc < size && len == 1)
1994 { 2029 {
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 }
2004 pos_byte += len; 2063 pos_byte += len;
2005 pos++; 2064 pos++;