From: Kenichi Handa Date: Wed, 4 Mar 1998 07:41:41 +0000 (+0000) Subject: (Fset_buffer_multibyte): Fix arg for chars_in_text. X-Git-Tag: emacs-20.3~2009 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=673c57d22a2d87b1d5fcca0065c82d8bcaf7cc1b;p=emacs.git (Fset_buffer_multibyte): Fix arg for chars_in_text. Be sure not to have a multibyte sequence striding over the GAP --- diff --git a/src/buffer.c b/src/buffer.c index fa01de36a67..9879e8520bf 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1737,6 +1737,24 @@ but the contents viewed as characters do change.") } else { + /* Be sure not to have a multibyte sequence striding over the GAP. + Ex: We change this: "...abc\201\241\241 _GAP_ \241\241\241..." + to: "...abc _GAP_ \201\241\241\241\241\241..." */ + + if (GPT_BYTE > 1 && GPT_BYTE < Z_BYTE + && ! CHAR_HEAD_P (*(GAP_END_ADDR))) + { + unsigned char *p = GPT_ADDR - 1; + + while (! CHAR_HEAD_P (*p) && p > BEG_ADDR) p--; + if (BASE_LEADING_CODE_P (*p)) + { + int new_gpt = GPT_BYTE - (GPT_ADDR - p); + + move_gap_both (new_gpt, new_gpt); + } + } + /* Do this first, so that chars_in_text asks the right question. set_intervals_multibyte needs it too. */ current_buffer->enable_multibyte_characters = Qt; @@ -1744,17 +1762,17 @@ but the contents viewed as characters do change.") GPT_BYTE = advance_to_char_boundary (GPT_BYTE); GPT = chars_in_text (BEG_ADDR, GPT_BYTE - BEG_BYTE) + BEG; - Z = chars_in_text (GPT_ADDR, Z_BYTE - GPT_BYTE) + GPT; + Z = chars_in_text (GAP_END_ADDR, Z_BYTE - GPT_BYTE) + GPT; BEGV_BYTE = advance_to_char_boundary (BEGV_BYTE); if (BEGV_BYTE > GPT_BYTE) - BEGV = chars_in_text (GPT_ADDR, BEGV_BYTE - GPT_BYTE) + GPT; + BEGV = chars_in_text (GAP_END_ADDR, BEGV_BYTE - GPT_BYTE) + GPT; else BEGV = chars_in_text (BEG_ADDR, BEGV_BYTE - BEG_BYTE) + BEG; ZV_BYTE = advance_to_char_boundary (ZV_BYTE); if (ZV_BYTE > GPT_BYTE) - ZV = chars_in_text (GPT_ADDR, ZV_BYTE - GPT_BYTE) + GPT; + ZV = chars_in_text (GAP_END_ADDR, ZV_BYTE - GPT_BYTE) + GPT; else ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG; @@ -1763,7 +1781,7 @@ but the contents viewed as characters do change.") int pt; if (pt_byte > GPT_BYTE) - pt = chars_in_text (GPT_ADDR, pt_byte - GPT_BYTE) + GPT; + pt = chars_in_text (GAP_END_ADDR, pt_byte - GPT_BYTE) + GPT; else pt = chars_in_text (BEG_ADDR, pt_byte - BEG_BYTE) + BEG; TEMP_SET_PT_BOTH (pt, pt_byte);