From: Kenichi Handa Date: Wed, 4 Mar 1998 07:41:41 +0000 (+0000) Subject: (code_convert_region): Handle the case that codes X-Git-Tag: emacs-20.3~2012 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4b5ce591343f51796b5844c770a27c21eaa16307;p=emacs.git (code_convert_region): Handle the case that codes 0240..0377 are generated just after a multibyte character. --- diff --git a/src/coding.c b/src/coding.c index 2c1364d540d..bf5677b8a43 100644 --- a/src/coding.c +++ b/src/coding.c @@ -4238,8 +4238,50 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, adjust) } if (src - dst > 0) *dst = 0; /* Put an anchor. */ - if (multibyte && (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte))) - inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte); + if (multibyte) + { + if (fake_multibyte || !encodep && (to - from) != (to_byte - from_byte)) + inserted = multibyte_chars_in_text (GPT_ADDR, inserted_byte); + + if (! CHAR_HEAD_P (*GPT_ADDR) + && GPT_BYTE > 1 + && from_byte == from_byte_orig) + { + unsigned char *p0 = GPT_ADDR - 1, *pmin = BEG_ADDR, *p1, *pmax; + + while (! CHAR_HEAD_P (*p0) && p0 > pmin) p0--; + if (BASE_LEADING_CODE_P (*p0)) + { + /* Codes in the range 0240..0377 were inserted after a + multibyte sequence. We must treat those codes as + tailing constituents of the multibyte sequence. For + that, we increase byte positions of position keepers + whose char positions are GPT. */ + int byte_increase; + p1 = GPT_ADDR + 2, pmax = p0 + 1 + inserted_byte; + Lisp_Object tail; + + while (! CHAR_HEAD_P (*p1) && p1 < pmax) p1++; + /* Now, codes from P0 to P1 constitute a single + multibyte character. */ + + byte_increase = p1 - GPT_ADDR; + if (PT == GPT) + current_buffer->pt_byte += byte_increase; + tail = BUF_MARKERS (current_buffer); + while (XSYMBOL (tail) != XSYMBOL (Qnil)) + { + if (XMARKER (tail)->charpos == GPT) + XMARKER (tail)->bytepos += byte_increase; + tail = XMARKER (tail)->chain; + } + + from_byte += byte_increase; + from_byte_orig = from_byte; + inserted -= byte_increase; + } + } + } /* Update various buffer positions for the new text. */ GAP_SIZE -= inserted_byte;