aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c270
1 files changed, 193 insertions, 77 deletions
diff --git a/src/coding.c b/src/coding.c
index 9b295d7d870..e2b5ed6ed6c 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -701,26 +701,6 @@ static enum coding_category coding_priorities[coding_category_max];
701 Nth coding category. */ 701 Nth coding category. */
702static struct coding_system coding_categories[coding_category_max]; 702static struct coding_system coding_categories[coding_category_max];
703 703
704static int detected_mask[coding_category_raw_text] =
705 { CATEGORY_MASK_ISO,
706 CATEGORY_MASK_ISO,
707 CATEGORY_MASK_ISO,
708 CATEGORY_MASK_ISO,
709 CATEGORY_MASK_ISO,
710 CATEGORY_MASK_ISO,
711 CATEGORY_MASK_UTF_8,
712 CATEGORY_MASK_UTF_16,
713 CATEGORY_MASK_UTF_16,
714 CATEGORY_MASK_UTF_16,
715 CATEGORY_MASK_UTF_16,
716 CATEGORY_MASK_UTF_16,
717 CATEGORY_MASK_CHARSET,
718 CATEGORY_MASK_SJIS,
719 CATEGORY_MASK_BIG5,
720 CATEGORY_MASK_CCL,
721 CATEGORY_MASK_EMACS_MULE
722 };
723
724/*** Commonly used macros and functions ***/ 704/*** Commonly used macros and functions ***/
725 705
726#ifndef min 706#ifndef min
@@ -3080,6 +3060,70 @@ decode_coding_iso_2022 (coding)
3080 } 3060 }
3081 continue; 3061 continue;
3082 3062
3063 case '%':
3064 ONE_MORE_BYTE (c1);
3065 if (c1 == '/')
3066 {
3067 /* CTEXT extended segment:
3068 ESC % / [0-4] M L --ENCODING-NAME-- \002 --BYTES--
3069 We keep these bytes as is for the moment.
3070 They may be decoded by post-read-conversion. */
3071 int dim, M, L;
3072 int size;
3073
3074 ONE_MORE_BYTE (dim);
3075 ONE_MORE_BYTE (M);
3076 ONE_MORE_BYTE (L);
3077 size = ((M - 128) * 128) + (L - 128);
3078 if (charbuf + 8 + size > charbuf_end)
3079 goto break_loop;
3080 *charbuf++ = ISO_CODE_ESC;
3081 *charbuf++ = '%';
3082 *charbuf++ = '/';
3083 *charbuf++ = dim;
3084 *charbuf++ = BYTE8_TO_CHAR (M);
3085 *charbuf++ = BYTE8_TO_CHAR (L);
3086 while (size-- > 0)
3087 {
3088 ONE_MORE_BYTE (c1);
3089 *charbuf++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
3090 }
3091 }
3092 else if (c1 == 'G')
3093 {
3094 /* XFree86 extension for embedding UTF-8 in CTEXT:
3095 ESC % G --UTF-8-BYTES-- ESC % @
3096 We keep these bytes as is for the moment.
3097 They may be decoded by post-read-conversion. */
3098 int *p = charbuf;
3099
3100 if (p + 6 > charbuf_end)
3101 goto break_loop;
3102 *p++ = ISO_CODE_ESC;
3103 *p++ = '%';
3104 *p++ = 'G';
3105 while (p < charbuf_end)
3106 {
3107 ONE_MORE_BYTE (c1);
3108 if (c1 == ISO_CODE_ESC
3109 && src + 1 < src_end
3110 && src[0] == '%'
3111 && src[1] == '@')
3112 break;
3113 *p++ = ASCII_BYTE_P (c1) ? c1 : BYTE8_TO_CHAR (c1);
3114 }
3115 if (p + 3 > charbuf_end)
3116 goto break_loop;
3117 *p++ = ISO_CODE_ESC;
3118 *p++ = '%';
3119 *p++ = '@';
3120 charbuf = p;
3121 }
3122 else
3123 goto invalid_code;
3124 continue;
3125 break;
3126
3083 default: 3127 default:
3084 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION)) 3128 if (! (CODING_ISO_FLAGS (coding) & CODING_ISO_FLAG_DESIGNATION))
3085 goto invalid_code; 3129 goto invalid_code;
@@ -3168,6 +3212,10 @@ decode_coding_iso_2022 (coding)
3168 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c); 3212 *charbuf++ = ASCII_BYTE_P (c) ? c : BYTE8_TO_CHAR (c);
3169 char_offset++; 3213 char_offset++;
3170 coding->errors++; 3214 coding->errors++;
3215 continue;
3216
3217 break_loop:
3218 break;
3171 } 3219 }
3172 3220
3173 no_more_source: 3221 no_more_source:
@@ -4287,7 +4335,7 @@ decode_coding_ccl (coding)
4287 struct ccl_program ccl; 4335 struct ccl_program ccl;
4288 int source_charbuf[1024]; 4336 int source_charbuf[1024];
4289 int source_byteidx[1024]; 4337 int source_byteidx[1024];
4290 Lisp_Object attrs, eol_type, charset_list, valids; 4338 Lisp_Object attrs, eol_type, charset_list;
4291 4339
4292 CODING_GET_INFO (coding, attrs, eol_type, charset_list); 4340 CODING_GET_INFO (coding, attrs, eol_type, charset_list);
4293 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding)); 4341 setup_ccl_program (&ccl, CODING_CCL_DECODER (coding));
@@ -4793,7 +4841,6 @@ setup_coding_system (coding_system, coding)
4793 { 4841 {
4794 int i; 4842 int i;
4795 int flags = XINT (AREF (attrs, coding_attr_iso_flags)); 4843 int flags = XINT (AREF (attrs, coding_attr_iso_flags));
4796 enum coding_category category = XINT (CODING_ATTR_CATEGORY (attrs));
4797 4844
4798 /* Invoke graphic register 0 to plane 0. */ 4845 /* Invoke graphic register 0 to plane 0. */
4799 CODING_ISO_INVOCATION (coding, 0) = 0; 4846 CODING_ISO_INVOCATION (coding, 0) = 0;
@@ -5948,13 +5995,13 @@ consume_chars (coding)
5948 int *buf = coding->charbuf; 5995 int *buf = coding->charbuf;
5949 int *buf_end = coding->charbuf + coding->charbuf_size; 5996 int *buf_end = coding->charbuf + coding->charbuf_size;
5950 const unsigned char *src = coding->source + coding->consumed; 5997 const unsigned char *src = coding->source + coding->consumed;
5998 const unsigned char *src_end = coding->source + coding->src_bytes;
5951 EMACS_INT pos = coding->src_pos + coding->consumed_char; 5999 EMACS_INT pos = coding->src_pos + coding->consumed_char;
5952 EMACS_INT end_pos = coding->src_pos + coding->src_chars; 6000 EMACS_INT end_pos = coding->src_pos + coding->src_chars;
5953 int multibytep = coding->src_multibyte; 6001 int multibytep = coding->src_multibyte;
5954 Lisp_Object eol_type; 6002 Lisp_Object eol_type;
5955 int c; 6003 int c;
5956 EMACS_INT stop, stop_composition, stop_charset; 6004 EMACS_INT stop, stop_composition, stop_charset;
5957 int id;
5958 6005
5959 eol_type = CODING_ID_EOL_TYPE (coding->id); 6006 eol_type = CODING_ID_EOL_TYPE (coding->id);
5960 if (VECTORP (eol_type)) 6007 if (VECTORP (eol_type))
@@ -5978,8 +6025,6 @@ consume_chars (coding)
5978 { 6025 {
5979 if (pos == stop) 6026 if (pos == stop)
5980 { 6027 {
5981 int *p;
5982
5983 if (pos == end_pos) 6028 if (pos == end_pos)
5984 break; 6029 break;
5985 if (pos == stop_composition) 6030 if (pos == stop_composition)
@@ -5993,9 +6038,16 @@ consume_chars (coding)
5993 } 6038 }
5994 6039
5995 if (! multibytep) 6040 if (! multibytep)
5996 c = *src++; 6041 {
6042 EMACS_INT bytes = MULTIBYTE_LENGTH (src, src_end);
6043
6044 if (bytes > 0)
6045 c = STRING_CHAR_ADVANCE (src), pos += bytes;
6046 else
6047 c = *src++, pos++;
6048 }
5997 else 6049 else
5998 c = STRING_CHAR_ADVANCE (src); 6050 c = STRING_CHAR_ADVANCE (src), pos++;
5999 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY)) 6051 if ((c == '\r') && (coding->mode & CODING_MODE_SELECTIVE_DISPLAY))
6000 c = '\n'; 6052 c = '\n';
6001 if (! EQ (eol_type, Qunix)) 6053 if (! EQ (eol_type, Qunix))
@@ -6009,7 +6061,6 @@ consume_chars (coding)
6009 } 6061 }
6010 } 6062 }
6011 *buf++ = c; 6063 *buf++ = c;
6012 pos++;
6013 } 6064 }
6014 6065
6015 coding->consumed = src - coding->source; 6066 coding->consumed = src - coding->source;
@@ -6081,9 +6132,10 @@ encode_coding (coding)
6081 return (coding->result); 6132 return (coding->result);
6082} 6133}
6083 6134
6084/* Work buffer */
6085 6135
6086/* List of currently used working buffer. */ 6136/* Stack of working buffers used in code conversion. An nil element
6137 means that the code conversion of that level is not using a working
6138 buffer. */
6087Lisp_Object Vcode_conversion_work_buf_list; 6139Lisp_Object Vcode_conversion_work_buf_list;
6088 6140
6089/* A working buffer used by the top level conversion. */ 6141/* A working buffer used by the top level conversion. */
@@ -6095,32 +6147,35 @@ Lisp_Object Vcode_conversion_reused_work_buf;
6095 buffer. */ 6147 buffer. */
6096 6148
6097Lisp_Object 6149Lisp_Object
6098make_conversion_work_buffer (multibytep) 6150make_conversion_work_buffer (multibytep, depth)
6099 int multibytep; 6151 int multibytep, depth;
6100{ 6152{
6101 struct buffer *current = current_buffer; 6153 struct buffer *current = current_buffer;
6102 Lisp_Object buf; 6154 Lisp_Object buf, name;
6103 6155
6104 if (NILP (Vcode_conversion_work_buf_list)) 6156 if (depth == 0)
6105 { 6157 {
6106 if (NILP (Vcode_conversion_reused_work_buf)) 6158 if (NILP (Vcode_conversion_reused_work_buf))
6107 Vcode_conversion_reused_work_buf 6159 Vcode_conversion_reused_work_buf
6108 = Fget_buffer_create (build_string (" *code-conversion-work*")); 6160 = Fget_buffer_create (build_string (" *code-conversion-work<0>*"));
6109 Vcode_conversion_work_buf_list 6161 buf = Vcode_conversion_reused_work_buf;
6110 = Fcons (Vcode_conversion_reused_work_buf, Qnil);
6111 } 6162 }
6112 else 6163 else
6113 { 6164 {
6114 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); 6165 if (depth < 0)
6115 char str[128]; 6166 {
6167 name = build_string (" *code-conversion-work*");
6168 name = Fgenerate_new_buffer_name (name, Qnil);
6169 }
6170 else
6171 {
6172 char str[128];
6116 6173
6117 sprintf (str, " *code-conversion-work*<%d>", depth); 6174 sprintf (str, " *code-conversion-work*<%d>", depth);
6118 Vcode_conversion_work_buf_list 6175 name = build_string (str);
6119 = Fcons (Fget_buffer_create (build_string (str)), 6176 }
6120 Vcode_conversion_work_buf_list); 6177 buf = Fget_buffer_create (name);
6121 } 6178 }
6122
6123 buf = XCAR (Vcode_conversion_work_buf_list);
6124 set_buffer_internal (XBUFFER (buf)); 6179 set_buffer_internal (XBUFFER (buf));
6125 current_buffer->undo_list = Qt; 6180 current_buffer->undo_list = Qt;
6126 Ferase_buffer (); 6181 Ferase_buffer ();
@@ -6129,42 +6184,55 @@ make_conversion_work_buffer (multibytep)
6129 return buf; 6184 return buf;
6130} 6185}
6131 6186
6132static struct coding_system *saved_coding; 6187static Lisp_Object
6188code_conversion_restore (buffer)
6189 Lisp_Object buffer;
6190{
6191 Lisp_Object workbuf;
6192
6193 workbuf = XCAR (Vcode_conversion_work_buf_list);
6194 if (! NILP (workbuf)
6195 && ! EQ (workbuf, Vcode_conversion_reused_work_buf)
6196 && ! NILP (Fbuffer_live_p (workbuf)))
6197 Fkill_buffer (workbuf);
6198 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list);
6199 set_buffer_internal (XBUFFER (buffer));
6200 return Qnil;
6201}
6133 6202
6134Lisp_Object 6203static Lisp_Object
6135code_conversion_restore (info) 6204code_conversion_save (buffer, with_work_buf, multibyte)
6136 Lisp_Object info; 6205 Lisp_Object buffer;
6206 int with_work_buf, multibyte;
6137{ 6207{
6138 int depth = XINT (Flength (Vcode_conversion_work_buf_list)); 6208 Lisp_Object workbuf;
6139 Lisp_Object buf;
6140 6209
6141 if (depth > 0) 6210 if (with_work_buf)
6142 { 6211 {
6143 buf = XCAR (Vcode_conversion_work_buf_list); 6212 int depth = XINT (Flength (Vcode_conversion_work_buf_list));
6144 Vcode_conversion_work_buf_list = XCDR (Vcode_conversion_work_buf_list);
6145 if (depth > 1 && !NILP (Fbuffer_live_p (buf)))
6146 Fkill_buffer (buf);
6147 }
6148
6149 if (EQ (saved_coding->dst_object, Qt)
6150 && saved_coding->destination)
6151 xfree (saved_coding->destination);
6152 6213
6153 return save_excursion_restore (info); 6214 workbuf = make_conversion_work_buffer (multibyte, depth);
6215 }
6216 else
6217 workbuf = Qnil;
6218 Vcode_conversion_work_buf_list
6219 = Fcons (workbuf, Vcode_conversion_work_buf_list);
6220 record_unwind_protect (code_conversion_restore, buffer);
6221 return workbuf;
6154} 6222}
6155 6223
6156
6157int 6224int
6158decode_coding_gap (coding, chars, bytes) 6225decode_coding_gap (coding, chars, bytes)
6159 struct coding_system *coding; 6226 struct coding_system *coding;
6160 EMACS_INT chars, bytes; 6227 EMACS_INT chars, bytes;
6161{ 6228{
6162 int count = specpdl_ptr - specpdl; 6229 int count = specpdl_ptr - specpdl;
6230 Lisp_Object buffer;
6163 6231
6164 saved_coding = coding; 6232 buffer = Fcurrent_buffer ();
6165 record_unwind_protect (code_conversion_restore, save_excursion_save ()); 6233 code_conversion_save (buffer, 0, 0);
6166 6234
6167 coding->src_object = Fcurrent_buffer (); 6235 coding->src_object = buffer;
6168 coding->src_chars = chars; 6236 coding->src_chars = chars;
6169 coding->src_bytes = bytes; 6237 coding->src_bytes = bytes;
6170 coding->src_pos = -chars; 6238 coding->src_pos = -chars;
@@ -6193,10 +6261,9 @@ encode_coding_gap (coding, chars, bytes)
6193 int count = specpdl_ptr - specpdl; 6261 int count = specpdl_ptr - specpdl;
6194 Lisp_Object buffer; 6262 Lisp_Object buffer;
6195 6263
6196 saved_coding = coding;
6197 record_unwind_protect (code_conversion_restore, save_excursion_save ());
6198
6199 buffer = Fcurrent_buffer (); 6264 buffer = Fcurrent_buffer ();
6265 code_conversion_save (buffer, 0, 0);
6266
6200 coding->src_object = buffer; 6267 coding->src_object = buffer;
6201 coding->src_chars = chars; 6268 coding->src_chars = chars;
6202 coding->src_bytes = bytes; 6269 coding->src_bytes = bytes;
@@ -6257,9 +6324,10 @@ decode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6257 EMACS_INT chars = to - from; 6324 EMACS_INT chars = to - from;
6258 EMACS_INT bytes = to_byte - from_byte; 6325 EMACS_INT bytes = to_byte - from_byte;
6259 Lisp_Object attrs; 6326 Lisp_Object attrs;
6327 Lisp_Object buffer;
6328 int saved_pt = -1, saved_pt_byte;
6260 6329
6261 saved_coding = coding; 6330 buffer = Fcurrent_buffer ();
6262 record_unwind_protect (code_conversion_restore, save_excursion_save ());
6263 6331
6264 if (NILP (dst_object)) 6332 if (NILP (dst_object))
6265 { 6333 {
@@ -6284,6 +6352,7 @@ decode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6284 move_gap_both (from, from_byte); 6352 move_gap_both (from, from_byte);
6285 if (EQ (src_object, dst_object)) 6353 if (EQ (src_object, dst_object))
6286 { 6354 {
6355 saved_pt = PT, saved_pt_byte = PT_BYTE;
6287 TEMP_SET_PT_BOTH (from, from_byte); 6356 TEMP_SET_PT_BOTH (from, from_byte);
6288 del_range_both (from, from_byte, to, to_byte, 1); 6357 del_range_both (from, from_byte, to, to_byte, 1);
6289 coding->src_pos = -chars; 6358 coding->src_pos = -chars;
@@ -6304,13 +6373,14 @@ decode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6304 || (! NILP (CODING_ATTR_POST_READ (attrs)) 6373 || (! NILP (CODING_ATTR_POST_READ (attrs))
6305 && NILP (dst_object))) 6374 && NILP (dst_object)))
6306 { 6375 {
6307 coding->dst_object = make_conversion_work_buffer (1); 6376 coding->dst_object = code_conversion_save (buffer, 1, 1);
6308 coding->dst_pos = BEG; 6377 coding->dst_pos = BEG;
6309 coding->dst_pos_byte = BEG_BYTE; 6378 coding->dst_pos_byte = BEG_BYTE;
6310 coding->dst_multibyte = 1; 6379 coding->dst_multibyte = 1;
6311 } 6380 }
6312 else if (BUFFERP (dst_object)) 6381 else if (BUFFERP (dst_object))
6313 { 6382 {
6383 code_conversion_save (buffer, 0, 0);
6314 coding->dst_object = dst_object; 6384 coding->dst_object = dst_object;
6315 coding->dst_pos = BUF_PT (XBUFFER (dst_object)); 6385 coding->dst_pos = BUF_PT (XBUFFER (dst_object));
6316 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object)); 6386 coding->dst_pos_byte = BUF_PT_BYTE (XBUFFER (dst_object));
@@ -6319,6 +6389,7 @@ decode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6319 } 6389 }
6320 else 6390 else
6321 { 6391 {
6392 code_conversion_save (buffer, 0, 0);
6322 coding->dst_object = Qnil; 6393 coding->dst_object = Qnil;
6323 coding->dst_multibyte = 1; 6394 coding->dst_multibyte = 1;
6324 } 6395 }
@@ -6368,6 +6439,25 @@ decode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6368 } 6439 }
6369 } 6440 }
6370 6441
6442 if (saved_pt >= 0)
6443 {
6444 /* This is the case of:
6445 (BUFFERP (src_object) && EQ (src_object, dst_object))
6446 As we have moved PT while replacing the original buffer
6447 contents, we must recover it now. */
6448 set_buffer_internal (XBUFFER (src_object));
6449 if (saved_pt < from)
6450 TEMP_SET_PT_BOTH (saved_pt, saved_pt_byte);
6451 else if (saved_pt < from + chars)
6452 TEMP_SET_PT_BOTH (from, from_byte);
6453 else if (! NILP (current_buffer->enable_multibyte_characters))
6454 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars),
6455 saved_pt_byte + (coding->produced - bytes));
6456 else
6457 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes),
6458 saved_pt_byte + (coding->produced - bytes));
6459 }
6460
6371 unbind_to (count, Qnil); 6461 unbind_to (count, Qnil);
6372} 6462}
6373 6463
@@ -6384,9 +6474,10 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6384 EMACS_INT chars = to - from; 6474 EMACS_INT chars = to - from;
6385 EMACS_INT bytes = to_byte - from_byte; 6475 EMACS_INT bytes = to_byte - from_byte;
6386 Lisp_Object attrs; 6476 Lisp_Object attrs;
6477 Lisp_Object buffer;
6478 int saved_pt = -1, saved_pt_byte;
6387 6479
6388 saved_coding = coding; 6480 buffer = Fcurrent_buffer ();
6389 record_unwind_protect (code_conversion_restore, save_excursion_save ());
6390 6481
6391 coding->src_object = src_object; 6482 coding->src_object = src_object;
6392 coding->src_chars = chars; 6483 coding->src_chars = chars;
@@ -6397,7 +6488,8 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6397 6488
6398 if (! NILP (CODING_ATTR_PRE_WRITE (attrs))) 6489 if (! NILP (CODING_ATTR_PRE_WRITE (attrs)))
6399 { 6490 {
6400 coding->src_object = make_conversion_work_buffer (coding->src_multibyte); 6491 coding->src_object = code_conversion_save (buffer, 1,
6492 coding->src_multibyte);
6401 set_buffer_internal (XBUFFER (coding->src_object)); 6493 set_buffer_internal (XBUFFER (coding->src_object));
6402 if (STRINGP (src_object)) 6494 if (STRINGP (src_object))
6403 insert_from_string (src_object, from, from_byte, chars, bytes, 0); 6495 insert_from_string (src_object, from, from_byte, chars, bytes, 0);
@@ -6409,6 +6501,7 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6409 if (EQ (src_object, dst_object)) 6501 if (EQ (src_object, dst_object))
6410 { 6502 {
6411 set_buffer_internal (XBUFFER (src_object)); 6503 set_buffer_internal (XBUFFER (src_object));
6504 saved_pt = PT, saved_pt_byte = PT_BYTE;
6412 del_range_both (from, from_byte, to, to_byte, 1); 6505 del_range_both (from, from_byte, to, to_byte, 1);
6413 set_buffer_internal (XBUFFER (coding->src_object)); 6506 set_buffer_internal (XBUFFER (coding->src_object));
6414 } 6507 }
@@ -6426,14 +6519,17 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6426 } 6519 }
6427 else if (STRINGP (src_object)) 6520 else if (STRINGP (src_object))
6428 { 6521 {
6522 code_conversion_save (buffer, 0, 0);
6429 coding->src_pos = from; 6523 coding->src_pos = from;
6430 coding->src_pos_byte = from_byte; 6524 coding->src_pos_byte = from_byte;
6431 } 6525 }
6432 else if (BUFFERP (src_object)) 6526 else if (BUFFERP (src_object))
6433 { 6527 {
6528 code_conversion_save (buffer, 0, 0);
6434 set_buffer_internal (XBUFFER (src_object)); 6529 set_buffer_internal (XBUFFER (src_object));
6435 if (EQ (src_object, dst_object)) 6530 if (EQ (src_object, dst_object))
6436 { 6531 {
6532 saved_pt = PT, saved_pt_byte = PT_BYTE;
6437 coding->src_object = del_range_1 (from, to, 1, 1); 6533 coding->src_object = del_range_1 (from, to, 1, 1);
6438 coding->src_pos = 0; 6534 coding->src_pos = 0;
6439 coding->src_pos_byte = 0; 6535 coding->src_pos_byte = 0;
@@ -6446,6 +6542,8 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6446 coding->src_pos_byte = from_byte; 6542 coding->src_pos_byte = from_byte;
6447 } 6543 }
6448 } 6544 }
6545 else
6546 code_conversion_save (buffer, 0, 0);
6449 6547
6450 if (BUFFERP (dst_object)) 6548 if (BUFFERP (dst_object))
6451 { 6549 {
@@ -6493,6 +6591,25 @@ encode_coding_object (coding, src_object, from, from_byte, to, to_byte,
6493 } 6591 }
6494 } 6592 }
6495 6593
6594 if (saved_pt >= 0)
6595 {
6596 /* This is the case of:
6597 (BUFFERP (src_object) && EQ (src_object, dst_object))
6598 As we have moved PT while replacing the original buffer
6599 contents, we must recover it now. */
6600 set_buffer_internal (XBUFFER (src_object));
6601 if (saved_pt < from)
6602 TEMP_SET_PT_BOTH (saved_pt, saved_pt_byte);
6603 else if (saved_pt < from + chars)
6604 TEMP_SET_PT_BOTH (from, from_byte);
6605 else if (! NILP (current_buffer->enable_multibyte_characters))
6606 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars),
6607 saved_pt_byte + (coding->produced - bytes));
6608 else
6609 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes),
6610 saved_pt_byte + (coding->produced - bytes));
6611 }
6612
6496 unbind_to (count, Qnil); 6613 unbind_to (count, Qnil);
6497} 6614}
6498 6615
@@ -6589,7 +6706,6 @@ detect_coding_system (src, src_bytes, highest, multibytep, coding_system)
6589 Lisp_Object coding_system; 6706 Lisp_Object coding_system;
6590{ 6707{
6591 unsigned char *src_end = src + src_bytes; 6708 unsigned char *src_end = src + src_bytes;
6592 int mask = CATEGORY_MASK_ANY;
6593 Lisp_Object attrs, eol_type; 6709 Lisp_Object attrs, eol_type;
6594 Lisp_Object val; 6710 Lisp_Object val;
6595 struct coding_system coding; 6711 struct coding_system coding;
@@ -8005,7 +8121,7 @@ usage: (define-coding-system-internal ...) */)
8005 else if (EQ (coding_type, Qiso_2022)) 8121 else if (EQ (coding_type, Qiso_2022))
8006 { 8122 {
8007 Lisp_Object initial, reg_usage, request, flags; 8123 Lisp_Object initial, reg_usage, request, flags;
8008 int i, id; 8124 int i;
8009 8125
8010 if (nargs < coding_arg_iso2022_max) 8126 if (nargs < coding_arg_iso2022_max)
8011 goto short_args; 8127 goto short_args;