Mercurial > emacs
comparison src/coding.c @ 65506:f376635f5061
(code_convert_region_unwind): Argument format changed.
(run_pre_post_conversion_on_str): If pre-write-conversion function
changed the current buffer, delete the new buffer.
(run_pre_write_conversin_on_c_str): Likewise.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Wed, 14 Sep 2005 07:05:43 +0000 |
| parents | a0d1312ede66 |
| children | 3e443750ea4c d84f940244dc |
comparison
equal
deleted
inserted
replaced
| 65505:f8283f171a8f | 65506:f376635f5061 |
|---|---|
| 5351 if (encodep) shrink_encoding_region (beg, end, coding, str); \ | 5351 if (encodep) shrink_encoding_region (beg, end, coding, str); \ |
| 5352 else shrink_decoding_region (beg, end, coding, str); \ | 5352 else shrink_decoding_region (beg, end, coding, str); \ |
| 5353 } \ | 5353 } \ |
| 5354 } while (0) | 5354 } while (0) |
| 5355 | 5355 |
| 5356 /* ARG is (CODING . BUFFER) where CODING is what to be set in | 5356 /* ARG is (CODING BUFFER ...) where CODING is what to be set in |
| 5357 Vlast_coding_system_used and BUFFER if non-nil is a buffer to | 5357 Vlast_coding_system_used and the remaining elements are buffers to |
| 5358 kill. */ | 5358 kill. */ |
| 5359 static Lisp_Object | 5359 static Lisp_Object |
| 5360 code_convert_region_unwind (arg) | 5360 code_convert_region_unwind (arg) |
| 5361 Lisp_Object arg; | 5361 Lisp_Object arg; |
| 5362 { | 5362 { |
| 5363 inhibit_pre_post_conversion = 0; | 5363 inhibit_pre_post_conversion = 0; |
| 5364 Vlast_coding_system_used = XCAR (arg); | 5364 Vlast_coding_system_used = XCAR (arg); |
| 5365 if (! NILP (XCDR (arg))) | 5365 for (arg = XCDR (arg); ! NILP (arg); arg = XCDR (arg)) |
| 5366 Fkill_buffer (XCDR (arg)); | 5366 Fkill_buffer (XCAR (arg)); |
| 5367 return Qnil; | 5367 return Qnil; |
| 5368 } | 5368 } |
| 5369 | 5369 |
| 5370 /* Store information about all compositions in the range FROM and TO | 5370 /* Store information about all compositions in the range FROM and TO |
| 5371 of OBJ in memory blocks pointed by CODING->cmp_data. OBJ is a | 5371 of OBJ in memory blocks pointed by CODING->cmp_data. OBJ is a |
| 6079 int count = SPECPDL_INDEX (); | 6079 int count = SPECPDL_INDEX (); |
| 6080 struct gcpro gcpro1, gcpro2; | 6080 struct gcpro gcpro1, gcpro2; |
| 6081 int multibyte = STRING_MULTIBYTE (str); | 6081 int multibyte = STRING_MULTIBYTE (str); |
| 6082 Lisp_Object old_deactivate_mark; | 6082 Lisp_Object old_deactivate_mark; |
| 6083 Lisp_Object buffer_to_kill; | 6083 Lisp_Object buffer_to_kill; |
| 6084 Lisp_Object unwind_arg; | |
| 6084 | 6085 |
| 6085 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | 6086 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); |
| 6086 /* It is not crucial to specbind this. */ | 6087 /* It is not crucial to specbind this. */ |
| 6087 old_deactivate_mark = Vdeactivate_mark; | 6088 old_deactivate_mark = Vdeactivate_mark; |
| 6088 GCPRO2 (str, old_deactivate_mark); | 6089 GCPRO2 (str, old_deactivate_mark); |
| 6089 | 6090 |
| 6090 /* We must insert the contents of STR as is without | 6091 /* We must insert the contents of STR as is without |
| 6091 unibyte<->multibyte conversion. For that, we adjust the | 6092 unibyte<->multibyte conversion. For that, we adjust the |
| 6092 multibyteness of the working buffer to that of STR. */ | 6093 multibyteness of the working buffer to that of STR. */ |
| 6093 buffer_to_kill = set_conversion_work_buffer (multibyte); | 6094 buffer_to_kill = set_conversion_work_buffer (multibyte); |
| 6094 record_unwind_protect (code_convert_region_unwind, | 6095 if (NILP (buffer_to_kill)) |
| 6095 Fcons (Vlast_coding_system_used, buffer_to_kill)); | 6096 unwind_arg = Fcons (Vlast_coding_system_used, Qnil); |
| 6097 else | |
| 6098 unwind_arg = list2 (Vlast_coding_system_used, buffer_to_kill); | |
| 6099 record_unwind_protect (code_convert_region_unwind, unwind_arg); | |
| 6096 | 6100 |
| 6097 insert_from_string (str, 0, 0, | 6101 insert_from_string (str, 0, 0, |
| 6098 SCHARS (str), SBYTES (str), 0); | 6102 SCHARS (str), SBYTES (str), 0); |
| 6099 UNGCPRO; | 6103 UNGCPRO; |
| 6100 inhibit_pre_post_conversion = 1; | 6104 inhibit_pre_post_conversion = 1; |
| 6101 if (encodep) | 6105 if (encodep) |
| 6102 call2 (coding->pre_write_conversion, make_number (BEG), make_number (Z)); | 6106 { |
| 6107 struct buffer *prev = current_buffer; | |
| 6108 | |
| 6109 call2 (coding->pre_write_conversion, make_number (BEG), make_number (Z)); | |
| 6110 if (prev != current_buffer) | |
| 6111 /* We must kill the current buffer too. */ | |
| 6112 Fsetcdr (unwind_arg, Fcons (Fcurrent_buffer (), XCDR (unwind_arg))); | |
| 6113 } | |
| 6103 else | 6114 else |
| 6104 { | 6115 { |
| 6105 Vlast_coding_system_used = coding->symbol; | 6116 Vlast_coding_system_used = coding->symbol; |
| 6106 TEMP_SET_PT_BOTH (BEG, BEG_BYTE); | 6117 TEMP_SET_PT_BOTH (BEG, BEG_BYTE); |
| 6107 call1 (coding->post_read_conversion, make_number (Z - BEG)); | 6118 call1 (coding->post_read_conversion, make_number (Z - BEG)); |
| 6131 int *size, nchars, nbytes; | 6142 int *size, nchars, nbytes; |
| 6132 struct coding_system *coding; | 6143 struct coding_system *coding; |
| 6133 { | 6144 { |
| 6134 struct gcpro gcpro1, gcpro2; | 6145 struct gcpro gcpro1, gcpro2; |
| 6135 struct buffer *cur = current_buffer; | 6146 struct buffer *cur = current_buffer; |
| 6147 struct buffer *prev; | |
| 6136 Lisp_Object old_deactivate_mark, old_last_coding_system_used; | 6148 Lisp_Object old_deactivate_mark, old_last_coding_system_used; |
| 6137 Lisp_Object args[3]; | 6149 Lisp_Object args[3]; |
| 6138 Lisp_Object buffer_to_kill; | 6150 Lisp_Object buffer_to_kill; |
| 6139 | 6151 |
| 6140 /* It is not crucial to specbind this. */ | 6152 /* It is not crucial to specbind this. */ |
| 6147 multibyteness of the working buffer to that of STR. */ | 6159 multibyteness of the working buffer to that of STR. */ |
| 6148 buffer_to_kill = set_conversion_work_buffer (coding->src_multibyte); | 6160 buffer_to_kill = set_conversion_work_buffer (coding->src_multibyte); |
| 6149 insert_1_both (*str, nchars, nbytes, 0, 0, 0); | 6161 insert_1_both (*str, nchars, nbytes, 0, 0, 0); |
| 6150 UNGCPRO; | 6162 UNGCPRO; |
| 6151 inhibit_pre_post_conversion = 1; | 6163 inhibit_pre_post_conversion = 1; |
| 6164 prev = current_buffer; | |
| 6152 args[0] = coding->pre_write_conversion; | 6165 args[0] = coding->pre_write_conversion; |
| 6153 args[1] = make_number (BEG); | 6166 args[1] = make_number (BEG); |
| 6154 args[2] = make_number (Z); | 6167 args[2] = make_number (Z); |
| 6155 safe_call (3, args); | 6168 safe_call (3, args); |
| 6156 inhibit_pre_post_conversion = 0; | 6169 inhibit_pre_post_conversion = 0; |
| 6166 if (BEG < GPT && GPT < Z) | 6179 if (BEG < GPT && GPT < Z) |
| 6167 move_gap (BEG); | 6180 move_gap (BEG); |
| 6168 bcopy (BEG_ADDR, *str, coding->produced); | 6181 bcopy (BEG_ADDR, *str, coding->produced); |
| 6169 coding->src_multibyte | 6182 coding->src_multibyte |
| 6170 = ! NILP (current_buffer->enable_multibyte_characters); | 6183 = ! NILP (current_buffer->enable_multibyte_characters); |
| 6184 if (prev != current_buffer) | |
| 6185 Fkill_buffer (Fcurrent_buffer ()); | |
| 6171 set_buffer_internal (cur); | 6186 set_buffer_internal (cur); |
| 6172 if (! NILP (buffer_to_kill)) | 6187 if (! NILP (buffer_to_kill)) |
| 6173 Fkill_buffer (buffer_to_kill); | 6188 Fkill_buffer (buffer_to_kill); |
| 6174 } | 6189 } |
| 6175 | 6190 |
