* src/fileio.c (Finsert_file_contents): Fix hook handling (bug#24340)

* src/fileio.c (Finsert_file_contents): Run before-change-hooks before
deleting the old buffer content.
* src/lisp.h (del_range_byte):
* src/insdel.c (del_range_byte): Drop the last argument.
* src/fns.c (Fbase64_encode_region): Adjust accordingly.
This commit is contained in:
Stefan Monnier 2016-10-03 09:47:46 -04:00
parent a7e9d1cce3
commit e2913dc880
4 changed files with 35 additions and 35 deletions

View file

@ -3858,6 +3858,7 @@ by calling `format-decode', which see. */)
if (! giveup_match_end)
{
ptrdiff_t temp;
ptrdiff_t this_count = SPECPDL_INDEX ();
/* We win! We can handle REPLACE the optimized way. */
@ -3887,13 +3888,19 @@ by calling `format-decode', which see. */)
beg_offset += same_at_start - BEGV_BYTE;
end_offset -= ZV_BYTE - same_at_end;
invalidate_buffer_caches (current_buffer,
BYTE_TO_CHAR (same_at_start),
same_at_end_charpos);
del_range_byte (same_at_start, same_at_end, 0);
/* This binding is to avoid ask-user-about-supersession-threat
being called in insert_from_buffer or del_range_bytes (via
prepare_to_modify_buffer).
AFAICT we could avoid ask-user-about-supersession-threat by setting
current_buffer->modtime earlier, but we could still end up calling
ask-user-about-supersession-threat if the file is modified while
we read it, so we bind buffer-file-name instead. */
specbind (intern ("buffer-file-name"), Qnil);
del_range_byte (same_at_start, same_at_end);
/* Insert from the file at the proper position. */
temp = BYTE_TO_CHAR (same_at_start);
SET_PT_BOTH (temp, same_at_start);
unbind_to (this_count, Qnil);
/* If display currently starts at beginning of line,
keep it that way. */
@ -3998,10 +4005,9 @@ by calling `format-decode', which see. */)
/* Truncate the buffer to the size of the file. */
if (same_at_start != same_at_end)
{
invalidate_buffer_caches (current_buffer,
BYTE_TO_CHAR (same_at_start),
BYTE_TO_CHAR (same_at_end));
del_range_byte (same_at_start, same_at_end, 0);
/* See previous specbind for the reason behind this. */
specbind (intern ("buffer-file-name"), Qnil);
del_range_byte (same_at_start, same_at_end);
}
inserted = 0;
@ -4049,12 +4055,11 @@ by calling `format-decode', which see. */)
we are taking from the decoded string. */
inserted -= (ZV_BYTE - same_at_end) + (same_at_start - BEGV_BYTE);
/* See previous specbind for the reason behind this. */
specbind (intern ("buffer-file-name"), Qnil);
if (same_at_end != same_at_start)
{
invalidate_buffer_caches (current_buffer,
BYTE_TO_CHAR (same_at_start),
same_at_end_charpos);
del_range_byte (same_at_start, same_at_end, 0);
del_range_byte (same_at_start, same_at_end);
temp = GPT;
eassert (same_at_start == GPT_BYTE);
same_at_start = GPT_BYTE;
@ -4075,10 +4080,6 @@ by calling `format-decode', which see. */)
same_at_start + inserted - BEGV_BYTE
+ BUF_BEG_BYTE (XBUFFER (conversion_buffer)))
- same_at_start_charpos);
/* This binding is to avoid ask-user-about-supersession-threat
being called in insert_from_buffer (via in
prepare_to_modify_buffer). */
specbind (intern ("buffer-file-name"), Qnil);
insert_from_buffer (XBUFFER (conversion_buffer),
same_at_start_charpos, inserted_chars, 0);
/* Set `inserted' to the number of inserted characters. */

View file

@ -3193,7 +3193,7 @@ into shorter lines. */)
SET_PT_BOTH (XFASTINT (beg), ibeg);
insert (encoded, encoded_length);
SAFE_FREE ();
del_range_byte (ibeg + encoded_length, iend + encoded_length, 1);
del_range_byte (ibeg + encoded_length, iend + encoded_length);
/* If point was outside of the region, restore it exactly; else just
move to the beginning of the region. */

View file

@ -1690,7 +1690,7 @@ del_range_1 (ptrdiff_t from, ptrdiff_t to, bool prepare, bool ret_string)
/* Like del_range_1 but args are byte positions, not char positions. */
void
del_range_byte (ptrdiff_t from_byte, ptrdiff_t to_byte, bool prepare)
del_range_byte (ptrdiff_t from_byte, ptrdiff_t to_byte)
{
ptrdiff_t from, to;
@ -1706,23 +1706,22 @@ del_range_byte (ptrdiff_t from_byte, ptrdiff_t to_byte, bool prepare)
from = BYTE_TO_CHAR (from_byte);
to = BYTE_TO_CHAR (to_byte);
if (prepare)
{
ptrdiff_t old_from = from, old_to = Z - to;
ptrdiff_t range_length = to - from;
prepare_to_modify_buffer (from, to, &from);
to = from + range_length;
{
ptrdiff_t old_from = from, old_to = Z - to;
ptrdiff_t range_length = to - from;
prepare_to_modify_buffer (from, to, &from);
to = from + range_length;
if (old_from != from)
from_byte = CHAR_TO_BYTE (from);
if (to > ZV)
{
to = ZV;
to_byte = ZV_BYTE;
}
else if (old_to == Z - to)
to_byte = CHAR_TO_BYTE (to);
}
if (old_from != from)
from_byte = CHAR_TO_BYTE (from);
if (to > ZV)
{
to = ZV;
to_byte = ZV_BYTE;
}
else if (old_to == Z - to)
to_byte = CHAR_TO_BYTE (to);
}
del_range_2 (from, from_byte, to, to_byte, 0);
signal_after_change (from, to - from, 0);

View file

@ -3505,7 +3505,7 @@ extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t,
ptrdiff_t, bool);
extern void del_range (ptrdiff_t, ptrdiff_t);
extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, bool, bool);
extern void del_range_byte (ptrdiff_t, ptrdiff_t, bool);
extern void del_range_byte (ptrdiff_t, ptrdiff_t);
extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool);
extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
ptrdiff_t, ptrdiff_t, bool);