comparison src/coding.c @ 21140:179c73d91f70

(code_convert_region): Adjusted for the change of adjust_after_replace.
author Kenichi Handa <handa@m17n.org>
date Thu, 12 Mar 1998 00:44:06 +0000
parents 75c6408013e5
children d704dd953837
comparison
equal deleted inserted replaced
21139:48b83e612b06 21140:179c73d91f70
3957 Lisp_Object saved_coding_symbol = Qnil; 3957 Lisp_Object saved_coding_symbol = Qnil;
3958 int multibyte = !NILP (current_buffer->enable_multibyte_characters); 3958 int multibyte = !NILP (current_buffer->enable_multibyte_characters);
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 {
3967 int saved_from = from; 3966 int saved_from = from;
3968 3967
4016 { 4015 {
4017 if (GPT < from || GPT > to) 4016 if (GPT < from || GPT > to)
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;
4035 return 0; 4023 return 0;
4036 } 4024 }
4037 4025
4038 /* Now we convert the text. */ 4026 /* Now we convert the text. */
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);
4052 if (current_buffer != prev) 4039 if (current_buffer != prev)
4053 { 4040 {
4238 dst = GPT_ADDR + inserted_byte; 4225 dst = GPT_ADDR + inserted_byte;
4239 } 4226 }
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 { 4233
4247 if (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte)) 4234 adjust_after_replace (from, from_byte, to, to_byte,
4248 adjusted_inserted 4235 inserted, inserted_byte);
4249 = inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte); 4236 if (from_byte_orig == from_byte)
4250 4237 from_byte_orig = from_byte = PT_BYTE;
4251 if (! CHAR_HEAD_P (*GPT_ADDR) 4238
4252 && GPT_BYTE > 1 4239 if (! encodep && ! NILP (coding->post_read_conversion))
4253 && from_byte == from_byte_orig) 4240 {
4254 { 4241 Lisp_Object val;
4255 unsigned char *p0 = GPT_ADDR - 1, *pmin = BEG_ADDR, *p1, *pmax; 4242 int orig_inserted = inserted, pos = PT;
4256 4243
4257 while (! CHAR_HEAD_P (*p0) && p0 > pmin) p0--; 4244 if (from != pos)
4258 if (BASE_LEADING_CODE_P (*p0)) 4245 temp_set_point_both (current_buffer, from, from_byte);
4259 { 4246 val = call1 (coding->post_read_conversion, make_number (inserted));
4260 /* Codes in the range 0240..0377 were inserted just 4247 if (! NILP (val))
4261 after a multibyte sequence. We must treat those 4248 {
4262 codes as tailing constituents of the multibyte 4249 CHECK_NUMBER (val, 0);
4263 sequence. For that, we increase byte positions of 4250 inserted = XFASTINT (val);
4264 position keepers whose char positions are GPT. */ 4251 }
4265 Lisp_Object tail; 4252 if (pos >= from + orig_inserted)
4266 4253 temp_set_point (current_buffer, pos + (inserted - orig_inserted));
4267 combined_before_bytes 4254 }
4268 = count_combining_before (GPT_ADDR, inserted_byte, 4255
4269 GPT, GPT_BYTE); 4256 signal_after_change (from, to - from, inserted);
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
4287 if (! EQ (current_buffer->undo_list, Qt))
4288 {
4289 /* We record the multibyte sequence preceding the
4290 gap as deleted, and the new multibyte sequence
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
4312 if (adjust)
4313 {
4314 adjust_after_replace (from, from_byte, to, to_byte,
4315 inserted, inserted_byte,
4316 combined_before_bytes, 0);
4317
4318 if (! encodep && ! NILP (coding->post_read_conversion))
4319 {
4320 Lisp_Object val;
4321 int orig_inserted = adjusted_inserted, pos = PT;
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 }
4335 signal_after_change (from, to - from, adjusted_inserted);
4336 }
4337 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;
4348 } 4268 }
4349 4269