Mercurial > emacs
comparison src/fileio.c @ 89667:20a59c5d1d55
(kill_workbuf_unwind): Delete this function.
(Finsert_file_contents): Adjust the call of detect_coding_system.
Get conversion_buffer by code_conversion_save. Use the macor
CODING_MAY_REQUIRE_DECODING. After decoding, update
coding_system.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 02 Dec 2003 01:45:13 +0000 |
parents | f15c12edaf6d |
children | 71b7464faec1 |
comparison
equal
deleted
inserted
replaced
89666:7d38a63951c0 | 89667:20a59c5d1d55 |
---|---|
294 Fgoto_char (location); | 294 Fgoto_char (location); |
295 Fset_marker (location, Qnil, Qnil); | 295 Fset_marker (location, Qnil, Qnil); |
296 return Qnil; | 296 return Qnil; |
297 } | 297 } |
298 | 298 |
299 /* Kill the working buffer for code conversion. */ | |
300 | |
301 static Lisp_Object | |
302 kill_workbuf_unwind (workbuf) | |
303 Lisp_Object workbuf; | |
304 { | |
305 if (! NILP (workbuf) && ! NILP (Fbuffer_live_p (workbuf))) | |
306 Fkill_buffer (workbuf); | |
307 return Qnil; | |
308 } | |
309 | 299 |
310 Lisp_Object Qexpand_file_name; | 300 Lisp_Object Qexpand_file_name; |
311 Lisp_Object Qsubstitute_in_file_name; | 301 Lisp_Object Qsubstitute_in_file_name; |
312 Lisp_Object Qdirectory_file_name; | 302 Lisp_Object Qdirectory_file_name; |
313 Lisp_Object Qfile_name_directory; | 303 Lisp_Object Qfile_name_directory; |
3956 else if (nread == 0) | 3946 else if (nread == 0) |
3957 break; | 3947 break; |
3958 | 3948 |
3959 if (CODING_REQUIRE_DETECTION (&coding)) | 3949 if (CODING_REQUIRE_DETECTION (&coding)) |
3960 { | 3950 { |
3961 coding_system = detect_coding_system (buffer, nread, 1, 0, | 3951 coding_system = detect_coding_system (buffer, nread, nread, 1, 0, |
3962 coding_system); | 3952 coding_system); |
3963 setup_coding_system (coding_system, &coding); | 3953 setup_coding_system (coding_system, &coding); |
3964 } | 3954 } |
3965 | 3955 |
3966 if (CODING_REQUIRE_DECODING (&coding)) | 3956 if (CODING_REQUIRE_DECODING (&coding)) |
4115 int bufpos; | 4105 int bufpos; |
4116 unsigned char *decoded; | 4106 unsigned char *decoded; |
4117 int temp; | 4107 int temp; |
4118 int this_count = SPECPDL_INDEX (); | 4108 int this_count = SPECPDL_INDEX (); |
4119 int multibyte = ! NILP (current_buffer->enable_multibyte_characters); | 4109 int multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
4120 Lisp_Object conversion_buffer | 4110 Lisp_Object conversion_buffer; |
4121 = make_conversion_work_buffer (-1, multibyte); | 4111 |
4122 struct gcpro1; | 4112 conversion_buffer = code_conversion_save (1, multibyte); |
4123 | |
4124 record_unwind_protect (kill_workbuf_unwind, conversion_buffer); | |
4125 | 4113 |
4126 /* First read the whole file, performing code conversion into | 4114 /* First read the whole file, performing code conversion into |
4127 CONVERSION_BUFFER. */ | 4115 CONVERSION_BUFFER. */ |
4128 | 4116 |
4129 if (lseek (fd, XINT (beg), 0) < 0) | 4117 if (lseek (fd, XINT (beg), 0) < 0) |
4482 /* When we visit a file by raw-text, we change the buffer to | 4470 /* When we visit a file by raw-text, we change the buffer to |
4483 unibyte. If we have not yet decided how to decode a text, | 4471 unibyte. If we have not yet decided how to decode a text, |
4484 decide it at first by detecting the file's encoding. */ | 4472 decide it at first by detecting the file's encoding. */ |
4485 if (CODING_REQUIRE_DETECTION (&coding)) | 4473 if (CODING_REQUIRE_DETECTION (&coding)) |
4486 { | 4474 { |
4487 coding_system = detect_coding_system (PT_ADDR, inserted, 1, 0, | 4475 coding_system = detect_coding_system (PT_ADDR, inserted, inserted, |
4488 coding_system); | 4476 1, 0, coding_system); |
4489 setup_coding_system (coding_system, &coding); | 4477 setup_coding_system (coding_system, &coding); |
4490 } | 4478 } |
4491 | 4479 |
4492 if (CODING_FOR_UNIBYTE (&coding) | 4480 if (CODING_FOR_UNIBYTE (&coding) |
4493 /* Can't do this if part of the buffer might be preserved. */ | 4481 /* Can't do this if part of the buffer might be preserved. */ |
4496 unibyte. */ | 4484 unibyte. */ |
4497 current_buffer->enable_multibyte_characters = Qnil; | 4485 current_buffer->enable_multibyte_characters = Qnil; |
4498 } | 4486 } |
4499 | 4487 |
4500 coding.dst_multibyte = ! NILP (current_buffer->enable_multibyte_characters); | 4488 coding.dst_multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
4501 if ((CODING_REQUIRE_DETECTION (&coding) | 4489 if (CODING_MAY_REQUIRE_DECODING (&coding) |
4502 || CODING_REQUIRE_DECODING (&coding)) | |
4503 && (inserted > 0 || CODING_REQUIRE_FLUSHING (&coding))) | 4490 && (inserted > 0 || CODING_REQUIRE_FLUSHING (&coding))) |
4504 { | 4491 { |
4505 move_gap_both (PT, PT_BYTE); | 4492 move_gap_both (PT, PT_BYTE); |
4506 GAP_SIZE += inserted; | 4493 GAP_SIZE += inserted; |
4507 ZV_BYTE -= inserted; | 4494 ZV_BYTE -= inserted; |
4508 Z_BYTE -= inserted; | 4495 Z_BYTE -= inserted; |
4509 ZV -= inserted; | 4496 ZV -= inserted; |
4510 Z -= inserted; | 4497 Z -= inserted; |
4511 decode_coding_gap (&coding, inserted, inserted); | 4498 decode_coding_gap (&coding, inserted, inserted); |
4512 inserted = coding.produced_char; | 4499 inserted = coding.produced_char; |
4500 coding_system = CODING_ID_NAME (coding.id); | |
4513 } | 4501 } |
4514 else if (inserted > 0) | 4502 else if (inserted > 0) |
4515 adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, | 4503 adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted, |
4516 inserted); | 4504 inserted); |
4517 | 4505 |