aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorKenichi Handa1998-03-30 06:00:54 +0000
committerKenichi Handa1998-03-30 06:00:54 +0000
commit12410ef1000f29eb91dfb1d8013caec3da316bf6 (patch)
treea2c92dc074774e4f23971a45b4e77a343c6df98a /src/coding.c
parenta137bb009d91c60aff8a1bed6904f611df4ab847 (diff)
downloademacs-12410ef1000f29eb91dfb1d8013caec3da316bf6.tar.gz
emacs-12410ef1000f29eb91dfb1d8013caec3da316bf6.zip
(code_convert_region): Handle skipped ASCII characters
at the head and tail of conversion region correctly when adjusting position keepers. Call adjust_after_insert to record undo info and adjust markers when we don't have to change byte sequence of a buffer.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c116
1 files changed, 64 insertions, 52 deletions
diff --git a/src/coding.c b/src/coding.c
index aa68631d4e1..fdf48e53427 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -3950,12 +3950,13 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
3950{ 3950{
3951 int len = to - from, len_byte = to_byte - from_byte; 3951 int len = to - from, len_byte = to_byte - from_byte;
3952 int require, inserted, inserted_byte; 3952 int require, inserted, inserted_byte;
3953 int from_byte_orig, to_byte_orig; 3953 int head_skip, tail_skip, total_skip;
3954 Lisp_Object saved_coding_symbol = Qnil; 3954 Lisp_Object saved_coding_symbol = Qnil;
3955 int multibyte = !NILP (current_buffer->enable_multibyte_characters); 3955 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
3956 int first = 1; 3956 int first = 1;
3957 int fake_multibyte = 0; 3957 int fake_multibyte = 0;
3958 unsigned char *src, *dst; 3958 unsigned char *src, *dst;
3959 Lisp_Object deletion = Qnil;
3959 3960
3960 if (replace) 3961 if (replace)
3961 { 3962 {
@@ -3975,10 +3976,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
3975 3976
3976 if (! encodep && CODING_REQUIRE_DETECTION (coding)) 3977 if (! encodep && CODING_REQUIRE_DETECTION (coding))
3977 { 3978 {
3978 /* We must detect encoding of text and eol. Even if detection 3979 /* We must detect encoding of text and eol format. */
3979 routines can't decide the encoding, we should not let them
3980 undecided because the deeper decoding routine (decode_coding)
3981 tries to detect the encodings in vain in that case. */
3982 3980
3983 if (from < GPT && to > GPT) 3981 if (from < GPT && to > GPT)
3984 move_gap_both (from, from_byte); 3982 move_gap_both (from, from_byte);
@@ -3986,6 +3984,10 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
3986 { 3984 {
3987 detect_coding (coding, BYTE_POS_ADDR (from_byte), len_byte); 3985 detect_coding (coding, BYTE_POS_ADDR (from_byte), len_byte);
3988 if (coding->type == coding_type_undecided) 3986 if (coding->type == coding_type_undecided)
3987 /* It seems that the text contains only ASCII, but we
3988 should not left it undecided because the deeper
3989 decoding routine (decode_coding) tries to detect the
3990 encodings again in vain. */
3989 coding->type = coding_type_emacs_mule; 3991 coding->type = coding_type_emacs_mule;
3990 } 3992 }
3991 if (coding->eol_type == CODING_EOL_UNDECIDED) 3993 if (coding->eol_type == CODING_EOL_UNDECIDED)
@@ -4007,25 +4009,18 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
4007 : ! CODING_REQUIRE_DECODING (coding)) 4009 : ! CODING_REQUIRE_DECODING (coding))
4008 { 4010 {
4009 coding->produced = len_byte; 4011 coding->produced = len_byte;
4010 if (multibyte) 4012 if (multibyte
4013 && ! replace
4014 /* See the comment of the member heading_ascii in coding.h. */
4015 && coding->heading_ascii < len_byte)
4011 { 4016 {
4012 adjust_before_replace (from, from_byte, to, to_byte);
4013
4014 /* We still may have to combine byte at the head and the 4017 /* We still may have to combine byte at the head and the
4015 tail of the text in the region. */ 4018 tail of the text in the region. */
4016 if (GPT != to) 4019 if (from < GPT && GPT < to)
4017 move_gap_both (to, to_byte); 4020 move_gap_both (to, to_byte);
4018 coding->produced_char 4021 len = multibyte_chars_in_text (BYTE_POS_ADDR (from_byte), len_byte);
4019 = multibyte_chars_in_text (BYTE_POS_ADDR (from_byte), len_byte); 4022 adjust_after_insert (from, from_byte, to, to_byte, len);
4020 GAP_SIZE += len_byte; 4023 coding->produced_char = len;
4021 GPT_BYTE -= len_byte;
4022 ZV_BYTE -= len_byte;
4023 Z_BYTE -= len_byte;
4024 GPT -= len;
4025 ZV -= len;
4026 Z -= len;
4027 adjust_after_replace (from, from_byte, to, to_byte,
4028 coding->produced_char, len_byte, replace);
4029 } 4024 }
4030 else 4025 else
4031 coding->produced_char = len_byte; 4026 coding->produced_char = len_byte;
@@ -4058,26 +4053,36 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
4058 } 4053 }
4059 } 4054 }
4060 4055
4056 if (replace)
4057 deletion = make_buffer_string_both (from, from_byte, to, to_byte, 1);
4058
4061 /* Try to skip the heading and tailing ASCIIs. */ 4059 /* Try to skip the heading and tailing ASCIIs. */
4062 from_byte_orig = from_byte; to_byte_orig = to_byte; 4060 {
4063 if (from < GPT && GPT < to) 4061 int from_byte_orig = from_byte, to_byte_orig = to_byte;
4064 move_gap (from); 4062
4065 if (encodep) 4063 if (from < GPT && GPT < to)
4066 shrink_encoding_region (&from_byte, &to_byte, coding, NULL); 4064 move_gap_both (from, from_byte);
4067 else 4065 if (encodep)
4068 shrink_decoding_region (&from_byte, &to_byte, coding, NULL); 4066 shrink_encoding_region (&from_byte, &to_byte, coding, NULL);
4069 if (from_byte == to_byte) 4067 else
4070 { 4068 shrink_decoding_region (&from_byte, &to_byte, coding, NULL);
4071 coding->produced = len_byte; 4069 if (from_byte == to_byte)
4072 coding->produced_char = multibyte ? len : len_byte; 4070 {
4073 return 0; 4071 coding->produced = len_byte;
4074 } 4072 coding->produced_char = multibyte ? len : len_byte;
4073 if (!replace)
4074 /* We must record and adjust for this new text now. */
4075 adjust_after_insert (from, from_byte_orig, to, to_byte_orig, len);
4076 return 0;
4077 }
4075 4078
4076 /* Here, the excluded region by shrinking contains only ASCIIs. */ 4079 head_skip = from_byte - from_byte_orig;
4077 from += (from_byte - from_byte_orig); 4080 tail_skip = to_byte_orig - to_byte;
4078 to += (to_byte - to_byte_orig); 4081 total_skip = head_skip + tail_skip;
4079 len = to - from; 4082 from += head_skip;
4080 len_byte = to_byte - from_byte; 4083 to -= tail_skip;
4084 len -= total_skip; len_byte -= total_skip;
4085 }
4081 4086
4082 /* For converion, we must put the gap before the text in addition to 4087 /* For converion, we must put the gap before the text in addition to
4083 making the gap larger for efficient decoding. The required gap 4088 making the gap larger for efficient decoding. The required gap
@@ -4090,9 +4095,6 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
4090 make_gap (require - GAP_SIZE); 4095 make_gap (require - GAP_SIZE);
4091 move_gap_both (from, from_byte); 4096 move_gap_both (from, from_byte);
4092 4097
4093 if (replace)
4094 adjust_before_replace (from, from_byte, to, to_byte);
4095
4096 if (GPT - BEG < beg_unchanged) 4098 if (GPT - BEG < beg_unchanged)
4097 beg_unchanged = GPT - BEG; 4099 beg_unchanged = GPT - BEG;
4098 if (Z - GPT < end_unchanged) 4100 if (Z - GPT < end_unchanged)
@@ -4238,13 +4240,25 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
4238 if (src - dst > 0) *dst = 0; /* Put an anchor. */ 4240 if (src - dst > 0) *dst = 0; /* Put an anchor. */
4239 4241
4240 if (multibyte 4242 if (multibyte
4241 && (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte))) 4243 && (fake_multibyte
4244 || !encodep && (to - from) != (to_byte - from_byte)))
4242 inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte); 4245 inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte);
4243 4246
4244 adjust_after_replace (from, from_byte, to, to_byte, 4247 /* If we have shrinked the conversion area, adjust it now. */
4245 inserted, inserted_byte, replace); 4248 if (total_skip > 0)
4246 if (from_byte_orig == from_byte) 4249 {
4247 from_byte_orig = from_byte = PT_BYTE; 4250 if (tail_skip > 0)
4251 safe_bcopy (GAP_END_ADDR, GPT_ADDR + inserted_byte, tail_skip);
4252 inserted += total_skip; inserted_byte += total_skip;
4253 GAP_SIZE += total_skip;
4254 GPT -= head_skip; GPT_BYTE -= head_skip;
4255 ZV -= total_skip; ZV_BYTE -= total_skip;
4256 Z -= total_skip; Z_BYTE -= total_skip;
4257 from -= head_skip; from_byte -= head_skip;
4258 to += tail_skip; to_byte += tail_skip;
4259 }
4260
4261 adjust_after_replace (from, from_byte, deletion, inserted, inserted_byte);
4248 4262
4249 if (! encodep && ! NILP (coding->post_read_conversion)) 4263 if (! encodep && ! NILP (coding->post_read_conversion))
4250 { 4264 {
@@ -4266,12 +4280,10 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
4266 signal_after_change (from, to - from, inserted); 4280 signal_after_change (from, to - from, inserted);
4267 4281
4268 { 4282 {
4269 int skip = (to_byte_orig - to_byte) + (from_byte - from_byte_orig); 4283 coding->consumed = to_byte - from_byte;
4270 4284 coding->consumed_char = to - from;
4271 coding->consumed = to_byte_orig - from_byte_orig; 4285 coding->produced = inserted_byte;
4272 coding->consumed_char = skip + (to - from); 4286 coding->produced_char = inserted;
4273 coding->produced = skip + inserted_byte;
4274 coding->produced_char = skip + inserted;
4275 } 4287 }
4276 4288
4277 return 0; 4289 return 0;