Mercurial > emacs
comparison src/coding.c @ 64308:93129de4b8a4
(code_convert_region_unwind): ARG is changed to a cons.
(code_convert_region): Adjusted for the above change.
(set_conversion_work_buffer): If the work buffer is already in
use, generate a new buffer and return it. Otherwise return Qnil.
(run_pre_post_conversion_on_str): Adjusted for the above change.
(run_pre_write_conversin_on_c_str): Likewise.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 14 Jul 2005 07:57:21 +0000 |
parents | 3de1b955c31a |
children | a0d1312ede66 |
comparison
equal
deleted
inserted
replaced
64307:487eee037b09 | 64308:93129de4b8a4 |
---|---|
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 | |
5357 Vlast_coding_system_used and BUFFER if non-nil is a buffer to | |
5358 kill. */ | |
5356 static Lisp_Object | 5359 static Lisp_Object |
5357 code_convert_region_unwind (arg) | 5360 code_convert_region_unwind (arg) |
5358 Lisp_Object arg; | 5361 Lisp_Object arg; |
5359 { | 5362 { |
5360 inhibit_pre_post_conversion = 0; | 5363 inhibit_pre_post_conversion = 0; |
5361 Vlast_coding_system_used = arg; | 5364 Vlast_coding_system_used = XCAR (arg); |
5365 if (! NILP (XCDR (arg))) | |
5366 Fkill_buffer (XCDR (arg)); | |
5362 return Qnil; | 5367 return Qnil; |
5363 } | 5368 } |
5364 | 5369 |
5365 /* Store information about all compositions in the range FROM and TO | 5370 /* Store information about all compositions in the range FROM and TO |
5366 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 |
5609 new buffer. */ | 5614 new buffer. */ |
5610 struct buffer *prev = current_buffer; | 5615 struct buffer *prev = current_buffer; |
5611 Lisp_Object new; | 5616 Lisp_Object new; |
5612 | 5617 |
5613 record_unwind_protect (code_convert_region_unwind, | 5618 record_unwind_protect (code_convert_region_unwind, |
5614 Vlast_coding_system_used); | 5619 Fcons (Vlast_coding_system_used, Qnil)); |
5615 /* We should not call any more pre-write/post-read-conversion | 5620 /* We should not call any more pre-write/post-read-conversion |
5616 functions while this pre-write-conversion is running. */ | 5621 functions while this pre-write-conversion is running. */ |
5617 inhibit_pre_post_conversion = 1; | 5622 inhibit_pre_post_conversion = 1; |
5618 call2 (coding->pre_write_conversion, | 5623 call2 (coding->pre_write_conversion, |
5619 make_number (from), make_number (to)); | 5624 make_number (from), make_number (to)); |
5977 | 5982 |
5978 if (from != PT) | 5983 if (from != PT) |
5979 TEMP_SET_PT_BOTH (from, from_byte); | 5984 TEMP_SET_PT_BOTH (from, from_byte); |
5980 prev_Z = Z; | 5985 prev_Z = Z; |
5981 record_unwind_protect (code_convert_region_unwind, | 5986 record_unwind_protect (code_convert_region_unwind, |
5982 Vlast_coding_system_used); | 5987 Fcons (Vlast_coding_system_used, Qnil)); |
5983 saved_coding_system = Vlast_coding_system_used; | 5988 saved_coding_system = Vlast_coding_system_used; |
5984 Vlast_coding_system_used = coding->symbol; | 5989 Vlast_coding_system_used = coding->symbol; |
5985 /* We should not call any more pre-write/post-read-conversion | 5990 /* We should not call any more pre-write/post-read-conversion |
5986 functions while this post-read-conversion is running. */ | 5991 functions while this post-read-conversion is running. */ |
5987 inhibit_pre_post_conversion = 1; | 5992 inhibit_pre_post_conversion = 1; |
6023 /* Name (or base name) of work buffer for code conversion. */ | 6028 /* Name (or base name) of work buffer for code conversion. */ |
6024 static Lisp_Object Vcode_conversion_workbuf_name; | 6029 static Lisp_Object Vcode_conversion_workbuf_name; |
6025 | 6030 |
6026 /* Set the current buffer to the working buffer prepared for | 6031 /* Set the current buffer to the working buffer prepared for |
6027 code-conversion. MULTIBYTE specifies the multibyteness of the | 6032 code-conversion. MULTIBYTE specifies the multibyteness of the |
6028 buffer. */ | 6033 buffer. Return the buffer we set if it must be killed after use. |
6029 | 6034 Otherwise return Qnil. */ |
6030 static struct buffer * | 6035 |
6036 static Lisp_Object | |
6031 set_conversion_work_buffer (multibyte) | 6037 set_conversion_work_buffer (multibyte) |
6032 int multibyte; | 6038 int multibyte; |
6033 { | 6039 { |
6034 Lisp_Object buffer; | 6040 Lisp_Object buffer, buffer_to_kill; |
6035 struct buffer *buf; | 6041 struct buffer *buf; |
6036 | 6042 |
6037 buffer = Fget_buffer_create (Vcode_conversion_workbuf_name); | 6043 buffer = Fget_buffer_create (Vcode_conversion_workbuf_name); |
6038 buf = XBUFFER (buffer); | 6044 buf = XBUFFER (buffer); |
6045 if (buf == current_buffer) | |
6046 { | |
6047 /* As we are already in the work buffer, we must generate a new | |
6048 buffer for the work. */ | |
6049 Lisp_Object name; | |
6050 | |
6051 name = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil); | |
6052 buffer = buffer_to_kill = Fget_buffer_create (name); | |
6053 buf = XBUFFER (buffer); | |
6054 } | |
6055 else | |
6056 buffer_to_kill = Qnil; | |
6057 | |
6039 delete_all_overlays (buf); | 6058 delete_all_overlays (buf); |
6040 buf->directory = current_buffer->directory; | 6059 buf->directory = current_buffer->directory; |
6041 buf->read_only = Qnil; | 6060 buf->read_only = Qnil; |
6042 buf->filename = Qnil; | 6061 buf->filename = Qnil; |
6043 buf->undo_list = Qt; | 6062 buf->undo_list = Qt; |
6046 set_buffer_internal (buf); | 6065 set_buffer_internal (buf); |
6047 if (BEG != BEGV || Z != ZV) | 6066 if (BEG != BEGV || Z != ZV) |
6048 Fwiden (); | 6067 Fwiden (); |
6049 del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0); | 6068 del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0); |
6050 buf->enable_multibyte_characters = multibyte ? Qt : Qnil; | 6069 buf->enable_multibyte_characters = multibyte ? Qt : Qnil; |
6051 return buf; | 6070 return buffer_to_kill; |
6052 } | 6071 } |
6053 | 6072 |
6054 Lisp_Object | 6073 Lisp_Object |
6055 run_pre_post_conversion_on_str (str, coding, encodep) | 6074 run_pre_post_conversion_on_str (str, coding, encodep) |
6056 Lisp_Object str; | 6075 Lisp_Object str; |
6059 { | 6078 { |
6060 int count = SPECPDL_INDEX (); | 6079 int count = SPECPDL_INDEX (); |
6061 struct gcpro gcpro1, gcpro2; | 6080 struct gcpro gcpro1, gcpro2; |
6062 int multibyte = STRING_MULTIBYTE (str); | 6081 int multibyte = STRING_MULTIBYTE (str); |
6063 Lisp_Object old_deactivate_mark; | 6082 Lisp_Object old_deactivate_mark; |
6083 Lisp_Object buffer_to_kill; | |
6064 | 6084 |
6065 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | 6085 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); |
6066 record_unwind_protect (code_convert_region_unwind, | |
6067 Vlast_coding_system_used); | |
6068 /* It is not crucial to specbind this. */ | 6086 /* It is not crucial to specbind this. */ |
6069 old_deactivate_mark = Vdeactivate_mark; | 6087 old_deactivate_mark = Vdeactivate_mark; |
6070 GCPRO2 (str, old_deactivate_mark); | 6088 GCPRO2 (str, old_deactivate_mark); |
6071 | 6089 |
6072 /* We must insert the contents of STR as is without | 6090 /* We must insert the contents of STR as is without |
6073 unibyte<->multibyte conversion. For that, we adjust the | 6091 unibyte<->multibyte conversion. For that, we adjust the |
6074 multibyteness of the working buffer to that of STR. */ | 6092 multibyteness of the working buffer to that of STR. */ |
6075 set_conversion_work_buffer (multibyte); | 6093 buffer_to_kill = set_conversion_work_buffer (multibyte); |
6094 record_unwind_protect (code_convert_region_unwind, | |
6095 Fcons (Vlast_coding_system_used, buffer_to_kill)); | |
6076 | 6096 |
6077 insert_from_string (str, 0, 0, | 6097 insert_from_string (str, 0, 0, |
6078 SCHARS (str), SBYTES (str), 0); | 6098 SCHARS (str), SBYTES (str), 0); |
6079 UNGCPRO; | 6099 UNGCPRO; |
6080 inhibit_pre_post_conversion = 1; | 6100 inhibit_pre_post_conversion = 1; |
6113 { | 6133 { |
6114 struct gcpro gcpro1, gcpro2; | 6134 struct gcpro gcpro1, gcpro2; |
6115 struct buffer *cur = current_buffer; | 6135 struct buffer *cur = current_buffer; |
6116 Lisp_Object old_deactivate_mark, old_last_coding_system_used; | 6136 Lisp_Object old_deactivate_mark, old_last_coding_system_used; |
6117 Lisp_Object args[3]; | 6137 Lisp_Object args[3]; |
6138 Lisp_Object buffer_to_kill; | |
6118 | 6139 |
6119 /* It is not crucial to specbind this. */ | 6140 /* It is not crucial to specbind this. */ |
6120 old_deactivate_mark = Vdeactivate_mark; | 6141 old_deactivate_mark = Vdeactivate_mark; |
6121 old_last_coding_system_used = Vlast_coding_system_used; | 6142 old_last_coding_system_used = Vlast_coding_system_used; |
6122 GCPRO2 (old_deactivate_mark, old_last_coding_system_used); | 6143 GCPRO2 (old_deactivate_mark, old_last_coding_system_used); |
6123 | 6144 |
6124 /* We must insert the contents of STR as is without | 6145 /* We must insert the contents of STR as is without |
6125 unibyte<->multibyte conversion. For that, we adjust the | 6146 unibyte<->multibyte conversion. For that, we adjust the |
6126 multibyteness of the working buffer to that of STR. */ | 6147 multibyteness of the working buffer to that of STR. */ |
6127 set_conversion_work_buffer (coding->src_multibyte); | 6148 buffer_to_kill = set_conversion_work_buffer (coding->src_multibyte); |
6128 insert_1_both (*str, nchars, nbytes, 0, 0, 0); | 6149 insert_1_both (*str, nchars, nbytes, 0, 0, 0); |
6129 UNGCPRO; | 6150 UNGCPRO; |
6130 inhibit_pre_post_conversion = 1; | 6151 inhibit_pre_post_conversion = 1; |
6131 args[0] = coding->pre_write_conversion; | 6152 args[0] = coding->pre_write_conversion; |
6132 args[1] = make_number (BEG); | 6153 args[1] = make_number (BEG); |
6146 move_gap (BEG); | 6167 move_gap (BEG); |
6147 bcopy (BEG_ADDR, *str, coding->produced); | 6168 bcopy (BEG_ADDR, *str, coding->produced); |
6148 coding->src_multibyte | 6169 coding->src_multibyte |
6149 = ! NILP (current_buffer->enable_multibyte_characters); | 6170 = ! NILP (current_buffer->enable_multibyte_characters); |
6150 set_buffer_internal (cur); | 6171 set_buffer_internal (cur); |
6172 if (! NILP (buffer_to_kill)) | |
6173 Fkill_buffer (buffer_to_kill); | |
6151 } | 6174 } |
6152 | 6175 |
6153 | 6176 |
6154 Lisp_Object | 6177 Lisp_Object |
6155 decode_coding_string (str, coding, nocopy) | 6178 decode_coding_string (str, coding, nocopy) |