*** fileio.c.~1.581.~ Sun Jun 10 17:46:54 2007 --- fileio.c Sun Jun 17 15:08:20 2007 *************** *** 4715,4729 **** current_buffer->undo_list = Qt; } ! insval = call3 (Qformat_decode, ! Qnil, make_number (inserted), visit); ! CHECK_NUMBER (insval); ! inserted = XFASTINT (insval); if (!NILP (visit)) current_buffer->undo_list = empty_undo_list_p ? Qnil : Qt; } /* Call after-change hooks for the inserted text, aside from the case of normal visiting (not with REPLACE), which is done in a new buffer "before" the buffer is changed. */ --- 4715,4789 ---- current_buffer->undo_list = Qt; } ! if (NILP (replace)) ! { ! insval = call3 (Qformat_decode, ! Qnil, make_number (inserted), visit); ! CHECK_NUMBER (insval); ! inserted = XFASTINT (insval); ! } ! else ! { ! /* Suppose replace is non-nil and we succeeded in not replacing the ! beginning or end of the buffer text with the file's contents. In this ! case we neverthelss have to call format-decode with `point' positioned ! at the beginning of the buffer and `inserted' equalling the number of ! characters in the buffer. Otherwise, format-decode might fail to ! correctly analyze the beginning or end of the buffer. Hence we ! temporarily save `point' and `inserted' here and restore `point' iff ! format-decode didn't insert or delete any text. Otherwise we leave ! `point' at point-min. */ ! int opoint = PT; ! int opoint_byte = PT_BYTE; ! int oinserted = ZV - BEGV; ! ! TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE); ! insval = call3 (Qformat_decode, ! Qnil, make_number (oinserted), visit); ! CHECK_NUMBER (insval); ! if (insval = oinserted) ! SET_PT_BOTH (opoint, opoint_byte); ! inserted = XFASTINT (insval); ! } if (!NILP (visit)) current_buffer->undo_list = empty_undo_list_p ? Qnil : Qt; } + p = Vafter_insert_file_functions; + while (CONSP (p)) + { + if (NILP (replace)) + { + insval = call1 (XCAR (p), make_number (inserted)); + if (!NILP (insval)) + { + CHECK_NUMBER (insval); + inserted = XFASTINT (insval); + } + } + else + { + /* For the rationale of this see the comment on format-decode above. */ + int opoint = PT; + int opoint_byte = PT_BYTE; + int oinserted = ZV - BEGV; + + TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE); + insval = call1 (XCAR (p), make_number (oinserted)); + if (!NILP (insval)) + { + CHECK_NUMBER (insval); + if (insval = oinserted) + SET_PT_BOTH (opoint, opoint_byte); + inserted = XFASTINT (insval); + } + } + + QUIT; + p = XCDR (p); + } + /* Call after-change hooks for the inserted text, aside from the case of normal visiting (not with REPLACE), which is done in a new buffer "before" the buffer is changed. */ *************** *** 4734,4752 **** update_compositions (PT, PT, CHECK_BORDER); } - p = Vafter_insert_file_functions; - while (CONSP (p)) - { - insval = call1 (XCAR (p), make_number (inserted)); - if (!NILP (insval)) - { - CHECK_NUMBER (insval); - inserted = XFASTINT (insval); - } - QUIT; - p = XCDR (p); - } - if (!NILP (visit) && current_buffer->modtime == -1) { --- 4794,4799 ----