[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master e2913dc: * src/fileio.c (Finsert_file_contents): Fi
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] master e2913dc: * src/fileio.c (Finsert_file_contents): Fix hook handling (bug#24340) |
Date: |
Mon, 3 Oct 2016 13:47:49 +0000 (UTC) |
branch: master
commit e2913dc880b9843bf69cf885270551bafeb46120
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>
* 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.
---
src/fileio.c | 33 +++++++++++++++++----------------
src/fns.c | 2 +-
src/insdel.c | 35 +++++++++++++++++------------------
src/lisp.h | 2 +-
4 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/src/fileio.c b/src/fileio.c
index 5fe0411..8f16d1e 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -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. */
diff --git a/src/fns.c b/src/fns.c
index 4f12dd5..dfc7842 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -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. */
diff --git a/src/insdel.c b/src/insdel.c
index 5d3884b..ed914ec 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -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;
-
- 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);
- }
+ {
+ 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);
+ }
del_range_2 (from, from_byte, to, to_byte, 0);
signal_after_change (from, to - from, 0);
diff --git a/src/lisp.h b/src/lisp.h
index 7430898..2e46592 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -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);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master e2913dc: * src/fileio.c (Finsert_file_contents): Fix hook handling (bug#24340),
Stefan Monnier <=