From cac4219c9121a00f22eeb8716be0453f2d848228 Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Fri, 24 Aug 2007 05:36:39 +0000 Subject: [PATCH] (Finsert_file_contents): Consult CHARS_MODIFF to tell whether decoding has modified buffer contents. --- src/ChangeLog | 5 +++++ src/fileio.c | 26 +++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index fca37df9e8d..164a6c19d60 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2007-08-24 Martin Rudalics + + * fileio.c (Finsert_file_contents): Consult CHARS_MODIFF to tell + whether decoding has modified buffer contents. + 2007-08-24 Jason Rumney * image.c [HAVE_NTGUI]: Define dynamic loaded functions for SVG. diff --git a/src/fileio.c b/src/fileio.c index 45eb7d29f91..62331122a24 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -4733,14 +4733,21 @@ variable `last-coding-system-used' to the coding system actually used. */) int opoint = PT; int opoint_byte = PT_BYTE; int oinserted = ZV - BEGV; + int ochars_modiff = CHARS_MODIFF; TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE); insval = call3 (Qformat_decode, Qnil, make_number (oinserted), visit); CHECK_NUMBER (insval); - if (XINT (insval) == oinserted) + if (ochars_modiff == CHARS_MODIFF) + /* format_decode didn't modify buffer's characters => move + point back to position before inserted text and leave + value of inserted alone. */ SET_PT_BOTH (opoint, opoint_byte); - inserted = XFASTINT (insval); + else + /* format_decode modified buffer's characters => consider + entire buffer changed and leave point at point-min. */ + inserted = XFASTINT (insval); } /* For consistency with format-decode call these now iff inserted > 0 @@ -4763,15 +4770,24 @@ variable `last-coding-system-used' to the coding system actually used. */) int opoint = PT; int opoint_byte = PT_BYTE; int oinserted = ZV - BEGV; - + int ochars_modiff = CHARS_MODIFF; + TEMP_SET_PT_BOTH (BEGV, BEGV_BYTE); insval = call1 (XCAR (p), make_number (oinserted)); if (!NILP (insval)) { CHECK_NUMBER (insval); - if (XINT (insval) == oinserted) + if (ochars_modiff == CHARS_MODIFF) + /* after_insert_file_functions didn't modify + buffer's characters => move point back to + position before inserted text and leave value of + inserted alone. */ SET_PT_BOTH (opoint, opoint_byte); - inserted = XFASTINT (insval); + else + /* after_insert_file_functions did modify buffer's + characters => consider entire buffer changed and + leave point at point-min. */ + inserted = XFASTINT (insval); } } -- 2.39.2