aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorRichard M. Stallman1998-03-10 21:14:08 +0000
committerRichard M. Stallman1998-03-10 21:14:08 +0000
commit7553d0e19cdea951a6e70e7f99fdf3fe138590fc (patch)
treed1ad4e1499a8240a8e0f53f6956b0bb7a6ed8795 /src/coding.c
parent41b8e71c8886c386264ec9cfab57bb96bf956cb9 (diff)
downloademacs-7553d0e19cdea951a6e70e7f99fdf3fe138590fc.tar.gz
emacs-7553d0e19cdea951a6e70e7f99fdf3fe138590fc.zip
(code_convert_region): Fix previous change. Adjusted
for the change of adjust_after_replace (see insdel.c change above).
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c76
1 files changed, 50 insertions, 26 deletions
diff --git a/src/coding.c b/src/coding.c
index 6376a4f8d6d..5a41abfe38f 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -3959,6 +3959,8 @@ 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;
3963 int adjusted_inserted;
3962 3964
3963 if (adjust) 3965 if (adjust)
3964 { 3966 {
@@ -4238,10 +4240,13 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4238 } 4240 }
4239 if (src - dst > 0) *dst = 0; /* Put an anchor. */ 4241 if (src - dst > 0) *dst = 0; /* Put an anchor. */
4240 4242
4243 adjusted_inserted = inserted;
4244
4241 if (multibyte) 4245 if (multibyte)
4242 { 4246 {
4243 if (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte)) 4247 if (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte))
4244 inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte); 4248 adjusted_inserted
4249 = inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte);
4245 4250
4246 if (! CHAR_HEAD_P (*GPT_ADDR) 4251 if (! CHAR_HEAD_P (*GPT_ADDR)
4247 && GPT_BYTE > 1 4252 && GPT_BYTE > 1
@@ -4252,64 +4257,82 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4252 while (! CHAR_HEAD_P (*p0) && p0 > pmin) p0--; 4257 while (! CHAR_HEAD_P (*p0) && p0 > pmin) p0--;
4253 if (BASE_LEADING_CODE_P (*p0)) 4258 if (BASE_LEADING_CODE_P (*p0))
4254 { 4259 {
4255 /* Codes in the range 0240..0377 were inserted after a 4260 /* Codes in the range 0240..0377 were inserted just
4256 multibyte sequence. We must treat those codes as 4261 after a multibyte sequence. We must treat those
4257 tailing constituents of the multibyte sequence. For 4262 codes as tailing constituents of the multibyte
4258 that, we increase byte positions of position keepers 4263 sequence. For that, we increase byte positions of
4259 whose char positions are GPT. */ 4264 position keepers whose char positions are GPT. */
4260 int byte_increase;
4261 Lisp_Object tail; 4265 Lisp_Object tail;
4262 4266
4263 p1 = GPT_ADDR + 2, pmax = p0 + 1 + inserted_byte; 4267 combined_before_bytes
4264 while (! CHAR_HEAD_P (*p1) && p1 < pmax) p1++; 4268 = count_combining_before (GPT_ADDR, inserted_byte,
4265 /* Now, codes from P0 to P1 constitute a single 4269 GPT, GPT_BYTE);
4266 multibyte character. */
4267
4268 byte_increase = p1 - GPT_ADDR;
4269 if (PT == GPT) 4270 if (PT == GPT)
4270 current_buffer->pt_byte += byte_increase; 4271 BUF_PT_BYTE (current_buffer) += combined_before_bytes;
4272 if (BEGV == GPT)
4273 BUF_BEGV_BYTE (current_buffer) += combined_before_bytes;
4274
4271 tail = BUF_MARKERS (current_buffer); 4275 tail = BUF_MARKERS (current_buffer);
4272 while (XSYMBOL (tail) != XSYMBOL (Qnil)) 4276 while (XSYMBOL (tail) != XSYMBOL (Qnil))
4273 { 4277 {
4274 if (XMARKER (tail)->charpos == GPT) 4278 if (XMARKER (tail)->charpos == GPT)
4275 XMARKER (tail)->bytepos += byte_increase; 4279 XMARKER (tail)->bytepos += combined_before_bytes;
4276 tail = XMARKER (tail)->chain; 4280 tail = XMARKER (tail)->chain;
4277 } 4281 }
4278 4282
4279 from_byte += byte_increase; 4283 from_byte += combined_before_bytes;
4280 from_byte_orig = from_byte; 4284 from_byte_orig = from_byte;
4281 inserted -= byte_increase; 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 }
4282 } 4302 }
4283 } 4303 }
4284 } 4304 }
4285 4305
4286 /* Update various buffer positions for the new text. */ 4306 /* Update various buffer positions for the new text. */
4287 GAP_SIZE -= inserted_byte; 4307 GAP_SIZE -= inserted_byte;
4288 ZV += inserted; Z+= inserted; 4308 ZV += adjusted_inserted; Z+= adjusted_inserted;
4289 ZV_BYTE += inserted_byte; Z_BYTE += inserted_byte; 4309 ZV_BYTE += inserted_byte; Z_BYTE += inserted_byte;
4290 GPT += inserted; GPT_BYTE += inserted_byte; 4310 GPT += adjusted_inserted; GPT_BYTE += inserted_byte;
4291 4311
4292 if (adjust) 4312 if (adjust)
4293 { 4313 {
4294 adjust_after_replace (from, from_byte, to, to_byte, 4314 adjust_after_replace (from, from_byte, to, to_byte,
4295 inserted, inserted_byte); 4315 inserted, inserted_byte,
4316 combined_before_bytes, 0);
4296 4317
4297 if (! encodep && ! NILP (coding->post_read_conversion)) 4318 if (! encodep && ! NILP (coding->post_read_conversion))
4298 { 4319 {
4299 Lisp_Object val; 4320 Lisp_Object val;
4300 int orig_inserted = inserted, pos = PT; 4321 int orig_inserted = adjusted_inserted, pos = PT;
4301 4322
4302 temp_set_point_both (current_buffer, from, from_byte); 4323 temp_set_point_both (current_buffer, from, from_byte);
4303 val = call1 (coding->post_read_conversion, make_number (inserted)); 4324 val = call1 (coding->post_read_conversion,
4325 make_number (adjusted_inserted));
4304 if (! NILP (val)) 4326 if (! NILP (val))
4305 { 4327 {
4306 CHECK_NUMBER (val, 0); 4328 CHECK_NUMBER (val, 0);
4307 inserted = XFASTINT (val); 4329 adjusted_inserted = XFASTINT (val);
4308 } 4330 }
4309 if (pos >= from + orig_inserted) 4331 if (pos >= from + orig_inserted)
4310 temp_set_point (current_buffer, pos + (inserted - orig_inserted)); 4332 temp_set_point (current_buffer,
4333 pos + (adjusted_inserted - orig_inserted));
4311 } 4334 }
4312 signal_after_change (from, to - from, inserted); 4335 signal_after_change (from, to - from, adjusted_inserted);
4313 } 4336 }
4314 4337
4315 { 4338 {
@@ -4318,8 +4341,9 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust)
4318 coding->consumed = to_byte_orig - from_byte_orig; 4341 coding->consumed = to_byte_orig - from_byte_orig;
4319 coding->consumed_char = skip + (to - from); 4342 coding->consumed_char = skip + (to - from);
4320 coding->produced = skip + inserted_byte; 4343 coding->produced = skip + inserted_byte;
4321 coding->produced_char = skip + inserted; 4344 coding->produced_char = skip + adjusted_inserted;
4322 } 4345 }
4346
4323 return 0; 4347 return 0;
4324} 4348}
4325 4349