aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa1998-03-12 00:44:06 +0000
committerKenichi Handa1998-03-12 00:44:06 +0000
commit2b4f9037e3130b68f024740f5e00f9a4944e96e4 (patch)
treeb0f7c4406d03a1fdb7a1436593ab0c0cf121be04 /src
parent61415a2589e8e71e1c820198bbc18385f7d3d7cb (diff)
downloademacs-2b4f9037e3130b68f024740f5e00f9a4944e96e4.tar.gz
emacs-2b4f9037e3130b68f024740f5e00f9a4944e96e4.zip
(code_convert_region): Adjusted for the change of
adjust_after_replace.
Diffstat (limited to 'src')
-rw-r--r--src/coding.c128
1 files changed, 24 insertions, 104 deletions
diff --git a/src/coding.c b/src/coding.c
index 5a41abfe38f..a9489004a7e 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -3959,8 +3959,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
3959 int first = 1; 3959 int first = 1;
3960 int fake_multibyte = 0; 3960 int fake_multibyte = 0;
3961 unsigned char *src, *dst; 3961 unsigned char *src, *dst;
3962 int combined_before_bytes = 0; 3962 int combined_before_bytes = 0, combined_after_bytes = 0;
3963 int adjusted_inserted;
3964 3963
3965 if (adjust) 3964 if (adjust)
3966 { 3965 {
@@ -4018,17 +4017,6 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4018 move_gap_both (from, from_byte); 4017 move_gap_both (from, from_byte);
4019 coding->produced_char 4018 coding->produced_char
4020 = multibyte_chars_in_text (BYTE_POS_ADDR (from_byte), len_byte); 4019 = multibyte_chars_in_text (BYTE_POS_ADDR (from_byte), len_byte);
4021 if (coding->produced_char != len)
4022 {
4023 int diff = coding->produced_char - len;
4024
4025 if (adjust)
4026 adjust_before_replace (from, from_byte, to, to_byte);
4027 ZV += diff; Z += diff; GPT += diff;
4028 if (adjust)
4029 adjust_after_replace (from, from_byte, to, to_byte,
4030 diff, 0);
4031 }
4032 } 4020 }
4033 else 4021 else
4034 coding->produced_char = len_byte; 4022 coding->produced_char = len_byte;
@@ -4039,13 +4027,12 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4039 4027
4040 /* For encoding, we must process pre-write-conversion in advance. */ 4028 /* For encoding, we must process pre-write-conversion in advance. */
4041 if (encodep 4029 if (encodep
4042 && adjust
4043 && ! NILP (coding->pre_write_conversion) 4030 && ! NILP (coding->pre_write_conversion)
4044 && SYMBOLP (coding->pre_write_conversion) 4031 && SYMBOLP (coding->pre_write_conversion)
4045 && ! NILP (Ffboundp (coding->pre_write_conversion))) 4032 && ! NILP (Ffboundp (coding->pre_write_conversion)))
4046 { 4033 {
4047 /* The function in pre-write-conversion put a new text in a new 4034 /* The function in pre-write-conversion may put a new text in a
4048 buffer. */ 4035 new buffer. */
4049 struct buffer *prev = current_buffer, *new; 4036 struct buffer *prev = current_buffer, *new;
4050 4037
4051 call2 (coding->pre_write_conversion, from, to); 4038 call2 (coding->pre_write_conversion, from, to);
@@ -4240,108 +4227,41 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4240 } 4227 }
4241 if (src - dst > 0) *dst = 0; /* Put an anchor. */ 4228 if (src - dst > 0) *dst = 0; /* Put an anchor. */
4242 4229
4243 adjusted_inserted = inserted; 4230 if (multibyte
4244 4231 && (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte)))
4245 if (multibyte) 4232 inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte);
4246 {
4247 if (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte))
4248 adjusted_inserted
4249 = inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte);
4250
4251 if (! CHAR_HEAD_P (*GPT_ADDR)
4252 && GPT_BYTE > 1
4253 && from_byte == from_byte_orig)
4254 {
4255 unsigned char *p0 = GPT_ADDR - 1, *pmin = BEG_ADDR, *p1, *pmax;
4256
4257 while (! CHAR_HEAD_P (*p0) && p0 > pmin) p0--;
4258 if (BASE_LEADING_CODE_P (*p0))
4259 {
4260 /* Codes in the range 0240..0377 were inserted just
4261 after a multibyte sequence. We must treat those
4262 codes as tailing constituents of the multibyte
4263 sequence. For that, we increase byte positions of
4264 position keepers whose char positions are GPT. */
4265 Lisp_Object tail;
4266
4267 combined_before_bytes
4268 = count_combining_before (GPT_ADDR, inserted_byte,
4269 GPT, GPT_BYTE);
4270 if (PT == GPT)
4271 BUF_PT_BYTE (current_buffer) += combined_before_bytes;
4272 if (BEGV == GPT)
4273 BUF_BEGV_BYTE (current_buffer) += combined_before_bytes;
4274
4275 tail = BUF_MARKERS (current_buffer);
4276 while (XSYMBOL (tail) != XSYMBOL (Qnil))
4277 {
4278 if (XMARKER (tail)->charpos == GPT)
4279 XMARKER (tail)->bytepos += combined_before_bytes;
4280 tail = XMARKER (tail)->chain;
4281 }
4282
4283 from_byte += combined_before_bytes;
4284 from_byte_orig = from_byte;
4285 adjusted_inserted = inserted - !! combined_before_bytes;
4286 4233
4287 if (! EQ (current_buffer->undo_list, Qt)) 4234 adjust_after_replace (from, from_byte, to, to_byte,
4288 { 4235 inserted, inserted_byte);
4289 /* We record the multibyte sequence preceding the 4236 if (from_byte_orig == from_byte)
4290 gap as deleted, and the new multibyte sequence 4237 from_byte_orig = from_byte = PT_BYTE;
4291 combined with COMBINED_BYTES as inserted. We
4292 directly modify the undo list because we have
4293 already done record_delete and can skip various
4294 checking. */
4295 Lisp_Object str = make_multibyte_string (p0, 1,
4296 GPT_ADDR - p0);
4297 current_buffer->undo_list
4298 = Fcons (Fcons (make_number (GPT - 1), make_number (GPT)),
4299 Fcons (Fcons (str, make_number (GPT - 1)),
4300 current_buffer->undo_list));
4301 }
4302 }
4303 }
4304 }
4305
4306 /* Update various buffer positions for the new text. */
4307 GAP_SIZE -= inserted_byte;
4308 ZV += adjusted_inserted; Z+= adjusted_inserted;
4309 ZV_BYTE += inserted_byte; Z_BYTE += inserted_byte;
4310 GPT += adjusted_inserted; GPT_BYTE += inserted_byte;
4311 4238
4312 if (adjust) 4239 if (! encodep && ! NILP (coding->post_read_conversion))
4313 { 4240 {
4314 adjust_after_replace (from, from_byte, to, to_byte, 4241 Lisp_Object val;
4315 inserted, inserted_byte, 4242 int orig_inserted = inserted, pos = PT;
4316 combined_before_bytes, 0);
4317 4243
4318 if (! encodep && ! NILP (coding->post_read_conversion)) 4244 if (from != pos)
4245 temp_set_point_both (current_buffer, from, from_byte);
4246 val = call1 (coding->post_read_conversion, make_number (inserted));
4247 if (! NILP (val))
4319 { 4248 {
4320 Lisp_Object val; 4249 CHECK_NUMBER (val, 0);
4321 int orig_inserted = adjusted_inserted, pos = PT; 4250 inserted = XFASTINT (val);
4322
4323 temp_set_point_both (current_buffer, from, from_byte);
4324 val = call1 (coding->post_read_conversion,
4325 make_number (adjusted_inserted));
4326 if (! NILP (val))
4327 {
4328 CHECK_NUMBER (val, 0);
4329 adjusted_inserted = XFASTINT (val);
4330 }
4331 if (pos >= from + orig_inserted)
4332 temp_set_point (current_buffer,
4333 pos + (adjusted_inserted - orig_inserted));
4334 } 4251 }
4335 signal_after_change (from, to - from, adjusted_inserted); 4252 if (pos >= from + orig_inserted)
4253 temp_set_point (current_buffer, pos + (inserted - orig_inserted));
4336 } 4254 }
4337 4255
4256 signal_after_change (from, to - from, inserted);
4257
4338 { 4258 {
4339 int skip = (to_byte_orig - to_byte) + (from_byte - from_byte_orig); 4259 int skip = (to_byte_orig - to_byte) + (from_byte - from_byte_orig);
4340 4260
4341 coding->consumed = to_byte_orig - from_byte_orig; 4261 coding->consumed = to_byte_orig - from_byte_orig;
4342 coding->consumed_char = skip + (to - from); 4262 coding->consumed_char = skip + (to - from);
4343 coding->produced = skip + inserted_byte; 4263 coding->produced = skip + inserted_byte;
4344 coding->produced_char = skip + adjusted_inserted; 4264 coding->produced_char = skip + inserted;
4345 } 4265 }
4346 4266
4347 return 0; 4267 return 0;