diff options
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/coding.c b/src/coding.c index 808f1e7d9c2..9d2d04af6cb 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* Coding system handler (conversion, detection, and etc). | 1 | /* Coding system handler (conversion, detection, and etc). |
| 2 | Copyright (C) 1995,97,1998,2002,2003 Electrotechnical Laboratory, JAPAN. | 2 | Copyright (C) 1995,97,1998,2002,2003 Electrotechnical Laboratory, JAPAN. |
| 3 | Licensed to the Free Software Foundation. | 3 | Licensed to the Free Software Foundation. |
| 4 | Copyright (C) 2001,2002,2003 Free Software Foundation, Inc. | 4 | Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | This file is part of GNU Emacs. | 6 | This file is part of GNU Emacs. |
| 7 | 7 | ||
| @@ -365,7 +365,7 @@ Lisp_Object Qsafe_chars; | |||
| 365 | Lisp_Object Qvalid_codes; | 365 | Lisp_Object Qvalid_codes; |
| 366 | 366 | ||
| 367 | extern Lisp_Object Qinsert_file_contents, Qwrite_region; | 367 | extern Lisp_Object Qinsert_file_contents, Qwrite_region; |
| 368 | Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument; | 368 | Lisp_Object Qcall_process, Qcall_process_region; |
| 369 | Lisp_Object Qstart_process, Qopen_network_stream; | 369 | Lisp_Object Qstart_process, Qopen_network_stream; |
| 370 | Lisp_Object Qtarget_idx; | 370 | Lisp_Object Qtarget_idx; |
| 371 | 371 | ||
| @@ -5349,12 +5349,17 @@ static int shrink_conversion_region_threshhold = 1024; | |||
| 5349 | } \ | 5349 | } \ |
| 5350 | } while (0) | 5350 | } while (0) |
| 5351 | 5351 | ||
| 5352 | /* ARG is (CODING . BUFFER) where CODING is what to be set in | ||
| 5353 | Vlast_coding_system_used and BUFFER if non-nil is a buffer to | ||
| 5354 | kill. */ | ||
| 5352 | static Lisp_Object | 5355 | static Lisp_Object |
| 5353 | code_convert_region_unwind (arg) | 5356 | code_convert_region_unwind (arg) |
| 5354 | Lisp_Object arg; | 5357 | Lisp_Object arg; |
| 5355 | { | 5358 | { |
| 5356 | inhibit_pre_post_conversion = 0; | 5359 | inhibit_pre_post_conversion = 0; |
| 5357 | Vlast_coding_system_used = arg; | 5360 | Vlast_coding_system_used = XCAR (arg); |
| 5361 | if (! NILP (XCDR (arg))) | ||
| 5362 | Fkill_buffer (XCDR (arg)); | ||
| 5358 | return Qnil; | 5363 | return Qnil; |
| 5359 | } | 5364 | } |
| 5360 | 5365 | ||
| @@ -5607,7 +5612,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace) | |||
| 5607 | Lisp_Object new; | 5612 | Lisp_Object new; |
| 5608 | 5613 | ||
| 5609 | record_unwind_protect (code_convert_region_unwind, | 5614 | record_unwind_protect (code_convert_region_unwind, |
| 5610 | Vlast_coding_system_used); | 5615 | Fcons (Vlast_coding_system_used, Qnil)); |
| 5611 | /* We should not call any more pre-write/post-read-conversion | 5616 | /* We should not call any more pre-write/post-read-conversion |
| 5612 | functions while this pre-write-conversion is running. */ | 5617 | functions while this pre-write-conversion is running. */ |
| 5613 | inhibit_pre_post_conversion = 1; | 5618 | inhibit_pre_post_conversion = 1; |
| @@ -5975,7 +5980,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace) | |||
| 5975 | TEMP_SET_PT_BOTH (from, from_byte); | 5980 | TEMP_SET_PT_BOTH (from, from_byte); |
| 5976 | prev_Z = Z; | 5981 | prev_Z = Z; |
| 5977 | record_unwind_protect (code_convert_region_unwind, | 5982 | record_unwind_protect (code_convert_region_unwind, |
| 5978 | Vlast_coding_system_used); | 5983 | Fcons (Vlast_coding_system_used, Qnil)); |
| 5979 | saved_coding_system = Vlast_coding_system_used; | 5984 | saved_coding_system = Vlast_coding_system_used; |
| 5980 | Vlast_coding_system_used = coding->symbol; | 5985 | Vlast_coding_system_used = coding->symbol; |
| 5981 | /* We should not call any more pre-write/post-read-conversion | 5986 | /* We should not call any more pre-write/post-read-conversion |
| @@ -6021,17 +6026,31 @@ static Lisp_Object Vcode_conversion_workbuf_name; | |||
| 6021 | 6026 | ||
| 6022 | /* Set the current buffer to the working buffer prepared for | 6027 | /* Set the current buffer to the working buffer prepared for |
| 6023 | code-conversion. MULTIBYTE specifies the multibyteness of the | 6028 | code-conversion. MULTIBYTE specifies the multibyteness of the |
| 6024 | buffer. */ | 6029 | buffer. Return the buffer we set if it must be killed after use. |
| 6030 | Otherwise return Qnil. */ | ||
| 6025 | 6031 | ||
| 6026 | static struct buffer * | 6032 | static Lisp_Object |
| 6027 | set_conversion_work_buffer (multibyte) | 6033 | set_conversion_work_buffer (multibyte) |
| 6028 | int multibyte; | 6034 | int multibyte; |
| 6029 | { | 6035 | { |
| 6030 | Lisp_Object buffer; | 6036 | Lisp_Object buffer, buffer_to_kill; |
| 6031 | struct buffer *buf; | 6037 | struct buffer *buf; |
| 6032 | 6038 | ||
| 6033 | buffer = Fget_buffer_create (Vcode_conversion_workbuf_name); | 6039 | buffer = Fget_buffer_create (Vcode_conversion_workbuf_name); |
| 6034 | buf = XBUFFER (buffer); | 6040 | buf = XBUFFER (buffer); |
| 6041 | if (buf == current_buffer) | ||
| 6042 | { | ||
| 6043 | /* As we are already in the work buffer, we must generate a new | ||
| 6044 | buffer for the work. */ | ||
| 6045 | Lisp_Object name; | ||
| 6046 | |||
| 6047 | name = Fgenerate_new_buffer_name (Vcode_conversion_workbuf_name, Qnil); | ||
| 6048 | buffer = buffer_to_kill = Fget_buffer_create (name); | ||
| 6049 | buf = XBUFFER (buffer); | ||
| 6050 | } | ||
| 6051 | else | ||
| 6052 | buffer_to_kill = Qnil; | ||
| 6053 | |||
| 6035 | delete_all_overlays (buf); | 6054 | delete_all_overlays (buf); |
| 6036 | buf->directory = current_buffer->directory; | 6055 | buf->directory = current_buffer->directory; |
| 6037 | buf->read_only = Qnil; | 6056 | buf->read_only = Qnil; |
| @@ -6044,7 +6063,7 @@ set_conversion_work_buffer (multibyte) | |||
| 6044 | Fwiden (); | 6063 | Fwiden (); |
| 6045 | del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0); | 6064 | del_range_2 (BEG, BEG_BYTE, Z, Z_BYTE, 0); |
| 6046 | buf->enable_multibyte_characters = multibyte ? Qt : Qnil; | 6065 | buf->enable_multibyte_characters = multibyte ? Qt : Qnil; |
| 6047 | return buf; | 6066 | return buffer_to_kill; |
| 6048 | } | 6067 | } |
| 6049 | 6068 | ||
| 6050 | Lisp_Object | 6069 | Lisp_Object |
| @@ -6057,10 +6076,9 @@ run_pre_post_conversion_on_str (str, coding, encodep) | |||
| 6057 | struct gcpro gcpro1, gcpro2; | 6076 | struct gcpro gcpro1, gcpro2; |
| 6058 | int multibyte = STRING_MULTIBYTE (str); | 6077 | int multibyte = STRING_MULTIBYTE (str); |
| 6059 | Lisp_Object old_deactivate_mark; | 6078 | Lisp_Object old_deactivate_mark; |
| 6079 | Lisp_Object buffer_to_kill; | ||
| 6060 | 6080 | ||
| 6061 | record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | 6081 | record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); |
| 6062 | record_unwind_protect (code_convert_region_unwind, | ||
| 6063 | Vlast_coding_system_used); | ||
| 6064 | /* It is not crucial to specbind this. */ | 6082 | /* It is not crucial to specbind this. */ |
| 6065 | old_deactivate_mark = Vdeactivate_mark; | 6083 | old_deactivate_mark = Vdeactivate_mark; |
| 6066 | GCPRO2 (str, old_deactivate_mark); | 6084 | GCPRO2 (str, old_deactivate_mark); |
| @@ -6068,7 +6086,9 @@ run_pre_post_conversion_on_str (str, coding, encodep) | |||
| 6068 | /* We must insert the contents of STR as is without | 6086 | /* We must insert the contents of STR as is without |
| 6069 | unibyte<->multibyte conversion. For that, we adjust the | 6087 | unibyte<->multibyte conversion. For that, we adjust the |
| 6070 | multibyteness of the working buffer to that of STR. */ | 6088 | multibyteness of the working buffer to that of STR. */ |
| 6071 | set_conversion_work_buffer (multibyte); | 6089 | buffer_to_kill = set_conversion_work_buffer (multibyte); |
| 6090 | record_unwind_protect (code_convert_region_unwind, | ||
| 6091 | Fcons (Vlast_coding_system_used, buffer_to_kill)); | ||
| 6072 | 6092 | ||
| 6073 | insert_from_string (str, 0, 0, | 6093 | insert_from_string (str, 0, 0, |
| 6074 | SCHARS (str), SBYTES (str), 0); | 6094 | SCHARS (str), SBYTES (str), 0); |
| @@ -6111,6 +6131,7 @@ run_pre_write_conversin_on_c_str (str, size, nchars, nbytes, coding) | |||
| 6111 | struct buffer *cur = current_buffer; | 6131 | struct buffer *cur = current_buffer; |
| 6112 | Lisp_Object old_deactivate_mark, old_last_coding_system_used; | 6132 | Lisp_Object old_deactivate_mark, old_last_coding_system_used; |
| 6113 | Lisp_Object args[3]; | 6133 | Lisp_Object args[3]; |
| 6134 | Lisp_Object buffer_to_kill; | ||
| 6114 | 6135 | ||
| 6115 | /* It is not crucial to specbind this. */ | 6136 | /* It is not crucial to specbind this. */ |
| 6116 | old_deactivate_mark = Vdeactivate_mark; | 6137 | old_deactivate_mark = Vdeactivate_mark; |
| @@ -6120,7 +6141,7 @@ run_pre_write_conversin_on_c_str (str, size, nchars, nbytes, coding) | |||
| 6120 | /* We must insert the contents of STR as is without | 6141 | /* We must insert the contents of STR as is without |
| 6121 | unibyte<->multibyte conversion. For that, we adjust the | 6142 | unibyte<->multibyte conversion. For that, we adjust the |
| 6122 | multibyteness of the working buffer to that of STR. */ | 6143 | multibyteness of the working buffer to that of STR. */ |
| 6123 | set_conversion_work_buffer (coding->src_multibyte); | 6144 | buffer_to_kill = set_conversion_work_buffer (coding->src_multibyte); |
| 6124 | insert_1_both (*str, nchars, nbytes, 0, 0, 0); | 6145 | insert_1_both (*str, nchars, nbytes, 0, 0, 0); |
| 6125 | UNGCPRO; | 6146 | UNGCPRO; |
| 6126 | inhibit_pre_post_conversion = 1; | 6147 | inhibit_pre_post_conversion = 1; |
| @@ -6144,6 +6165,8 @@ run_pre_write_conversin_on_c_str (str, size, nchars, nbytes, coding) | |||
| 6144 | coding->src_multibyte | 6165 | coding->src_multibyte |
| 6145 | = ! NILP (current_buffer->enable_multibyte_characters); | 6166 | = ! NILP (current_buffer->enable_multibyte_characters); |
| 6146 | set_buffer_internal (cur); | 6167 | set_buffer_internal (cur); |
| 6168 | if (! NILP (buffer_to_kill)) | ||
| 6169 | Fkill_buffer (buffer_to_kill); | ||
| 6147 | } | 6170 | } |
| 6148 | 6171 | ||
| 6149 | 6172 | ||