aboutsummaryrefslogtreecommitdiffstats
path: root/src/fileio.c
diff options
context:
space:
mode:
authorStefan Monnier2016-10-03 09:47:46 -0400
committerStefan Monnier2016-10-03 09:47:46 -0400
commite2913dc880b9843bf69cf885270551bafeb46120 (patch)
tree99e8fcb0aa17f60ddb3e68d91043c6b9a4d113f7 /src/fileio.c
parenta7e9d1cce3f935dbe9f242f0bf2dbf34f5919952 (diff)
downloademacs-e2913dc880b9843bf69cf885270551bafeb46120.tar.gz
emacs-e2913dc880b9843bf69cf885270551bafeb46120.zip
* 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.
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 5fe04114a4a..8f16d1e8496 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3858,6 +3858,7 @@ by calling `format-decode', which see. */)
3858 if (! giveup_match_end) 3858 if (! giveup_match_end)
3859 { 3859 {
3860 ptrdiff_t temp; 3860 ptrdiff_t temp;
3861 ptrdiff_t this_count = SPECPDL_INDEX ();
3861 3862
3862 /* We win! We can handle REPLACE the optimized way. */ 3863 /* We win! We can handle REPLACE the optimized way. */
3863 3864
@@ -3887,13 +3888,19 @@ by calling `format-decode', which see. */)
3887 beg_offset += same_at_start - BEGV_BYTE; 3888 beg_offset += same_at_start - BEGV_BYTE;
3888 end_offset -= ZV_BYTE - same_at_end; 3889 end_offset -= ZV_BYTE - same_at_end;
3889 3890
3890 invalidate_buffer_caches (current_buffer, 3891 /* This binding is to avoid ask-user-about-supersession-threat
3891 BYTE_TO_CHAR (same_at_start), 3892 being called in insert_from_buffer or del_range_bytes (via
3892 same_at_end_charpos); 3893 prepare_to_modify_buffer).
3893 del_range_byte (same_at_start, same_at_end, 0); 3894 AFAICT we could avoid ask-user-about-supersession-threat by setting
3895 current_buffer->modtime earlier, but we could still end up calling
3896 ask-user-about-supersession-threat if the file is modified while
3897 we read it, so we bind buffer-file-name instead. */
3898 specbind (intern ("buffer-file-name"), Qnil);
3899 del_range_byte (same_at_start, same_at_end);
3894 /* Insert from the file at the proper position. */ 3900 /* Insert from the file at the proper position. */
3895 temp = BYTE_TO_CHAR (same_at_start); 3901 temp = BYTE_TO_CHAR (same_at_start);
3896 SET_PT_BOTH (temp, same_at_start); 3902 SET_PT_BOTH (temp, same_at_start);
3903 unbind_to (this_count, Qnil);
3897 3904
3898 /* If display currently starts at beginning of line, 3905 /* If display currently starts at beginning of line,
3899 keep it that way. */ 3906 keep it that way. */
@@ -3998,10 +4005,9 @@ by calling `format-decode', which see. */)
3998 /* Truncate the buffer to the size of the file. */ 4005 /* Truncate the buffer to the size of the file. */
3999 if (same_at_start != same_at_end) 4006 if (same_at_start != same_at_end)
4000 { 4007 {
4001 invalidate_buffer_caches (current_buffer, 4008 /* See previous specbind for the reason behind this. */
4002 BYTE_TO_CHAR (same_at_start), 4009 specbind (intern ("buffer-file-name"), Qnil);
4003 BYTE_TO_CHAR (same_at_end)); 4010 del_range_byte (same_at_start, same_at_end);
4004 del_range_byte (same_at_start, same_at_end, 0);
4005 } 4011 }
4006 inserted = 0; 4012 inserted = 0;
4007 4013
@@ -4049,12 +4055,11 @@ by calling `format-decode', which see. */)
4049 we are taking from the decoded string. */ 4055 we are taking from the decoded string. */
4050 inserted -= (ZV_BYTE - same_at_end) + (same_at_start - BEGV_BYTE); 4056 inserted -= (ZV_BYTE - same_at_end) + (same_at_start - BEGV_BYTE);
4051 4057
4058 /* See previous specbind for the reason behind this. */
4059 specbind (intern ("buffer-file-name"), Qnil);
4052 if (same_at_end != same_at_start) 4060 if (same_at_end != same_at_start)
4053 { 4061 {
4054 invalidate_buffer_caches (current_buffer, 4062 del_range_byte (same_at_start, same_at_end);
4055 BYTE_TO_CHAR (same_at_start),
4056 same_at_end_charpos);
4057 del_range_byte (same_at_start, same_at_end, 0);
4058 temp = GPT; 4063 temp = GPT;
4059 eassert (same_at_start == GPT_BYTE); 4064 eassert (same_at_start == GPT_BYTE);
4060 same_at_start = GPT_BYTE; 4065 same_at_start = GPT_BYTE;
@@ -4075,10 +4080,6 @@ by calling `format-decode', which see. */)
4075 same_at_start + inserted - BEGV_BYTE 4080 same_at_start + inserted - BEGV_BYTE
4076 + BUF_BEG_BYTE (XBUFFER (conversion_buffer))) 4081 + BUF_BEG_BYTE (XBUFFER (conversion_buffer)))
4077 - same_at_start_charpos); 4082 - same_at_start_charpos);
4078 /* This binding is to avoid ask-user-about-supersession-threat
4079 being called in insert_from_buffer (via in
4080 prepare_to_modify_buffer). */
4081 specbind (intern ("buffer-file-name"), Qnil);
4082 insert_from_buffer (XBUFFER (conversion_buffer), 4083 insert_from_buffer (XBUFFER (conversion_buffer),
4083 same_at_start_charpos, inserted_chars, 0); 4084 same_at_start_charpos, inserted_chars, 0);
4084 /* Set `inserted' to the number of inserted characters. */ 4085 /* Set `inserted' to the number of inserted characters. */