comparison src/coding.c @ 91344:56f3473b139e

(decode_coding_object): Adjuste marker positions after conversion. (encode_coding_object): Likewise.
author Kenichi Handa <handa@m17n.org>
date Fri, 18 Jan 2008 07:08:52 +0000
parents 606f2d163a64
children c70e45a7acfd
comparison
equal deleted inserted replaced
91343:347746964570 91344:56f3473b139e
6849 EMACS_INT chars = to - from; 6849 EMACS_INT chars = to - from;
6850 EMACS_INT bytes = to_byte - from_byte; 6850 EMACS_INT bytes = to_byte - from_byte;
6851 Lisp_Object attrs; 6851 Lisp_Object attrs;
6852 Lisp_Object buffer; 6852 Lisp_Object buffer;
6853 int saved_pt = -1, saved_pt_byte; 6853 int saved_pt = -1, saved_pt_byte;
6854 int need_marker_adjustment = 0;
6854 6855
6855 buffer = Fcurrent_buffer (); 6856 buffer = Fcurrent_buffer ();
6856 6857
6857 if (NILP (dst_object)) 6858 if (NILP (dst_object))
6858 { 6859 {
6875 set_buffer_internal (XBUFFER (src_object)); 6876 set_buffer_internal (XBUFFER (src_object));
6876 if (from != GPT) 6877 if (from != GPT)
6877 move_gap_both (from, from_byte); 6878 move_gap_both (from, from_byte);
6878 if (EQ (src_object, dst_object)) 6879 if (EQ (src_object, dst_object))
6879 { 6880 {
6881 struct Lisp_Marker *tail;
6882
6883 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next)
6884 {
6885 tail->need_adjustment
6886 = tail->charpos == (tail->insertion_type ? from : to);
6887 need_marker_adjustment |= tail->need_adjustment;
6888 }
6880 saved_pt = PT, saved_pt_byte = PT_BYTE; 6889 saved_pt = PT, saved_pt_byte = PT_BYTE;
6881 TEMP_SET_PT_BOTH (from, from_byte); 6890 TEMP_SET_PT_BOTH (from, from_byte);
6882 del_range_both (from, from_byte, to, to_byte, 1); 6891 del_range_both (from, from_byte, to, to_byte, 1);
6883 coding->src_pos = -chars; 6892 coding->src_pos = -chars;
6884 coding->src_pos_byte = -bytes; 6893 coding->src_pos_byte = -bytes;
6980 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars), 6989 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars),
6981 saved_pt_byte + (coding->produced - bytes)); 6990 saved_pt_byte + (coding->produced - bytes));
6982 else 6991 else
6983 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes), 6992 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes),
6984 saved_pt_byte + (coding->produced - bytes)); 6993 saved_pt_byte + (coding->produced - bytes));
6994
6995 if (need_marker_adjustment)
6996 {
6997 struct Lisp_Marker *tail;
6998
6999 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next)
7000 if (tail->need_adjustment)
7001 {
7002 tail->need_adjustment = 0;
7003 if (tail->insertion_type)
7004 {
7005 tail->bytepos = from_byte;
7006 tail->charpos = from;
7007 }
7008 else
7009 {
7010 tail->bytepos = from_byte + coding->produced;
7011 tail->charpos
7012 = (NILP (current_buffer->enable_multibyte_characters)
7013 ? tail->bytepos : from + coding->produced_char);
7014 }
7015 }
7016 }
6985 } 7017 }
6986 7018
6987 unbind_to (count, coding->dst_object); 7019 unbind_to (count, coding->dst_object);
6988 } 7020 }
6989 7021
7000 EMACS_INT chars = to - from; 7032 EMACS_INT chars = to - from;
7001 EMACS_INT bytes = to_byte - from_byte; 7033 EMACS_INT bytes = to_byte - from_byte;
7002 Lisp_Object attrs; 7034 Lisp_Object attrs;
7003 Lisp_Object buffer; 7035 Lisp_Object buffer;
7004 int saved_pt = -1, saved_pt_byte; 7036 int saved_pt = -1, saved_pt_byte;
7037 int need_marker_adjustment = 0;
7005 int kill_src_buffer = 0; 7038 int kill_src_buffer = 0;
7006 7039
7007 buffer = Fcurrent_buffer (); 7040 buffer = Fcurrent_buffer ();
7008 7041
7009 coding->src_object = src_object; 7042 coding->src_object = src_object;
7010 coding->src_chars = chars; 7043 coding->src_chars = chars;
7011 coding->src_bytes = bytes; 7044 coding->src_bytes = bytes;
7012 coding->src_multibyte = chars < bytes; 7045 coding->src_multibyte = chars < bytes;
7013 7046
7014 attrs = CODING_ID_ATTRS (coding->id); 7047 attrs = CODING_ID_ATTRS (coding->id);
7048
7049 if (EQ (src_object, dst_object))
7050 {
7051 struct Lisp_Marker *tail;
7052
7053 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next)
7054 {
7055 tail->need_adjustment
7056 = tail->charpos == (tail->insertion_type ? from : to);
7057 need_marker_adjustment |= tail->need_adjustment;
7058 }
7059 }
7015 7060
7016 if (! NILP (CODING_ATTR_PRE_WRITE (attrs))) 7061 if (! NILP (CODING_ATTR_PRE_WRITE (attrs)))
7017 { 7062 {
7018 coding->src_object = code_conversion_save (1, coding->src_multibyte); 7063 coding->src_object = code_conversion_save (1, coding->src_multibyte);
7019 set_buffer_internal (XBUFFER (coding->src_object)); 7064 set_buffer_internal (XBUFFER (coding->src_object));
7140 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars), 7185 TEMP_SET_PT_BOTH (saved_pt + (coding->produced_char - chars),
7141 saved_pt_byte + (coding->produced - bytes)); 7186 saved_pt_byte + (coding->produced - bytes));
7142 else 7187 else
7143 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes), 7188 TEMP_SET_PT_BOTH (saved_pt + (coding->produced - bytes),
7144 saved_pt_byte + (coding->produced - bytes)); 7189 saved_pt_byte + (coding->produced - bytes));
7190
7191 if (need_marker_adjustment)
7192 {
7193 struct Lisp_Marker *tail;
7194
7195 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next)
7196 if (tail->need_adjustment)
7197 {
7198 tail->need_adjustment = 0;
7199 if (tail->insertion_type)
7200 {
7201 tail->bytepos = from_byte;
7202 tail->charpos = from;
7203 }
7204 else
7205 {
7206 tail->bytepos = from_byte + coding->produced;
7207 tail->charpos
7208 = (NILP (current_buffer->enable_multibyte_characters)
7209 ? tail->bytepos : from + coding->produced_char);
7210 }
7211 }
7212 }
7145 } 7213 }
7146 7214
7147 if (kill_src_buffer) 7215 if (kill_src_buffer)
7148 Fkill_buffer (coding->src_object); 7216 Fkill_buffer (coding->src_object);
7149 unbind_to (count, Qnil); 7217 unbind_to (count, Qnil);