aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa1998-03-16 05:51:07 +0000
committerKenichi Handa1998-03-16 05:51:07 +0000
commit6e44253b80942ba76b4c0cd365723bcdd677d15b (patch)
tree61d2f8198c8e9ddd97bd1a7f3667c3c7e113e6e0 /src
parentf4ac86afc5b2297b76649cc2aad4df678ded8e3d (diff)
downloademacs-6e44253b80942ba76b4c0cd365723bcdd677d15b.tar.gz
emacs-6e44253b80942ba76b4c0cd365723bcdd677d15b.zip
(code_convert_region): The 6th arg name is changed to
REPLACE. Even if there's no need of code conversion, call adjust_after_replace to handle bytes combining.
Diffstat (limited to 'src')
-rw-r--r--src/coding.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/coding.c b/src/coding.c
index a9489004a7e..0f6fc3dd985 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -3939,16 +3939,13 @@ shrink_encoding_region (beg, end, coding, str)
3939 characters (and bytes) are recorded in members of the structure 3939 characters (and bytes) are recorded in members of the structure
3940 CODING. 3940 CODING.
3941 3941
3942 If ADJUST is nonzero, we do various things as if the original text 3942 If REPLACE is nonzero, we do various things as if the original text
3943 is deleted and a new text is inserted. See the comments in 3943 is deleted and a new text is inserted. See the comments in
3944 replace_range (insdel.c) to know what we are doing. 3944 replace_range (insdel.c) to know what we are doing. */
3945
3946 ADJUST nonzero also means that post-read-conversion or
3947 pre-write-conversion functions (if any) should be processed. */
3948 3945
3949int 3946int
3950code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust) 3947code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
3951 int from, from_byte, to, to_byte, encodep, adjust; 3948 int from, from_byte, to, to_byte, encodep, replace;
3952 struct coding_system *coding; 3949 struct coding_system *coding;
3953{ 3950{
3954 int len = to - from, len_byte = to_byte - from_byte; 3951 int len = to - from, len_byte = to_byte - from_byte;
@@ -3959,9 +3956,8 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
3959 int first = 1; 3956 int first = 1;
3960 int fake_multibyte = 0; 3957 int fake_multibyte = 0;
3961 unsigned char *src, *dst; 3958 unsigned char *src, *dst;
3962 int combined_before_bytes = 0, combined_after_bytes = 0;
3963 3959
3964 if (adjust) 3960 if (replace)
3965 { 3961 {
3966 int saved_from = from; 3962 int saved_from = from;
3967 3963
@@ -4013,10 +4009,21 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4013 coding->produced = len_byte; 4009 coding->produced = len_byte;
4014 if (multibyte) 4010 if (multibyte)
4015 { 4011 {
4016 if (GPT < from || GPT > to) 4012 /* We still may have to combine byte at the head and the
4017 move_gap_both (from, from_byte); 4013 tail of the text in the region. */
4014 if (GPT != to)
4015 move_gap_both (to, to_byte);
4018 coding->produced_char 4016 coding->produced_char
4019 = multibyte_chars_in_text (BYTE_POS_ADDR (from_byte), len_byte); 4017 = multibyte_chars_in_text (BYTE_POS_ADDR (from_byte), len_byte);
4018 GAP_SIZE += len_byte;
4019 GPT_BYTE -= len_byte;
4020 ZV_BYTE -= len_byte;
4021 Z_BYTE -= len_byte;
4022 GPT -= len_byte;
4023 ZV -= len_byte;
4024 Z -= len_byte;
4025 adjust_after_replace (from, from_byte, to, to_byte,
4026 coding->produced_char, len_byte, replace);
4020 } 4027 }
4021 else 4028 else
4022 coding->produced_char = len_byte; 4029 coding->produced_char = len_byte;
@@ -4081,7 +4088,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4081 make_gap (require - GAP_SIZE); 4088 make_gap (require - GAP_SIZE);
4082 move_gap_both (from, from_byte); 4089 move_gap_both (from, from_byte);
4083 4090
4084 if (adjust) 4091 if (replace)
4085 adjust_before_replace (from, from_byte, to, to_byte); 4092 adjust_before_replace (from, from_byte, to, to_byte);
4086 4093
4087 if (GPT - BEG < beg_unchanged) 4094 if (GPT - BEG < beg_unchanged)
@@ -4204,8 +4211,9 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4204 REQUIRE + LEN_BYTE = LEN_BYTE * (NEW / ORIG) 4211 REQUIRE + LEN_BYTE = LEN_BYTE * (NEW / ORIG)
4205 REQUIRE = LEN_BYTE * (NEW - ORIG) / ORIG 4212 REQUIRE = LEN_BYTE * (NEW - ORIG) / ORIG
4206 Here, we are sure that NEW >= ORIG. */ 4213 Here, we are sure that NEW >= ORIG. */
4207 require = (len_byte * (coding->produced - coding->consumed) 4214 float ratio = coding->produced - coding->consumed;
4208 / coding->consumed); 4215 ratio /= coding->consumed;
4216 require = len_byte * ratio;
4209 first = 0; 4217 first = 0;
4210 } 4218 }
4211 if ((src - dst) < (require + 2000)) 4219 if ((src - dst) < (require + 2000))
@@ -4232,7 +4240,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4232 inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte); 4240 inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte);
4233 4241
4234 adjust_after_replace (from, from_byte, to, to_byte, 4242 adjust_after_replace (from, from_byte, to, to_byte,
4235 inserted, inserted_byte); 4243 inserted, inserted_byte, replace);
4236 if (from_byte_orig == from_byte) 4244 if (from_byte_orig == from_byte)
4237 from_byte_orig = from_byte = PT_BYTE; 4245 from_byte_orig = from_byte = PT_BYTE;
4238 4246