diff options
| author | Stefan Monnier | 2016-10-03 09:47:46 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2016-10-03 09:47:46 -0400 |
| commit | e2913dc880b9843bf69cf885270551bafeb46120 (patch) | |
| tree | 99e8fcb0aa17f60ddb3e68d91043c6b9a4d113f7 /src | |
| parent | a7e9d1cce3f935dbe9f242f0bf2dbf34f5919952 (diff) | |
| download | emacs-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')
| -rw-r--r-- | src/fileio.c | 33 | ||||
| -rw-r--r-- | src/fns.c | 2 | ||||
| -rw-r--r-- | src/insdel.c | 35 | ||||
| -rw-r--r-- | src/lisp.h | 2 |
4 files changed, 36 insertions, 36 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. */ |
| @@ -3193,7 +3193,7 @@ into shorter lines. */) | |||
| 3193 | SET_PT_BOTH (XFASTINT (beg), ibeg); | 3193 | SET_PT_BOTH (XFASTINT (beg), ibeg); |
| 3194 | insert (encoded, encoded_length); | 3194 | insert (encoded, encoded_length); |
| 3195 | SAFE_FREE (); | 3195 | SAFE_FREE (); |
| 3196 | del_range_byte (ibeg + encoded_length, iend + encoded_length, 1); | 3196 | del_range_byte (ibeg + encoded_length, iend + encoded_length); |
| 3197 | 3197 | ||
| 3198 | /* If point was outside of the region, restore it exactly; else just | 3198 | /* If point was outside of the region, restore it exactly; else just |
| 3199 | move to the beginning of the region. */ | 3199 | move to the beginning of the region. */ |
diff --git a/src/insdel.c b/src/insdel.c index 5d3884b4059..ed914ec6f75 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) | |||
| 1690 | /* Like del_range_1 but args are byte positions, not char positions. */ | 1690 | /* Like del_range_1 but args are byte positions, not char positions. */ |
| 1691 | 1691 | ||
| 1692 | void | 1692 | void |
| 1693 | del_range_byte (ptrdiff_t from_byte, ptrdiff_t to_byte, bool prepare) | 1693 | del_range_byte (ptrdiff_t from_byte, ptrdiff_t to_byte) |
| 1694 | { | 1694 | { |
| 1695 | ptrdiff_t from, to; | 1695 | ptrdiff_t from, to; |
| 1696 | 1696 | ||
| @@ -1706,23 +1706,22 @@ del_range_byte (ptrdiff_t from_byte, ptrdiff_t to_byte, bool prepare) | |||
| 1706 | from = BYTE_TO_CHAR (from_byte); | 1706 | from = BYTE_TO_CHAR (from_byte); |
| 1707 | to = BYTE_TO_CHAR (to_byte); | 1707 | to = BYTE_TO_CHAR (to_byte); |
| 1708 | 1708 | ||
| 1709 | if (prepare) | 1709 | { |
| 1710 | { | 1710 | ptrdiff_t old_from = from, old_to = Z - to; |
| 1711 | ptrdiff_t old_from = from, old_to = Z - to; | 1711 | ptrdiff_t range_length = to - from; |
| 1712 | ptrdiff_t range_length = to - from; | 1712 | prepare_to_modify_buffer (from, to, &from); |
| 1713 | prepare_to_modify_buffer (from, to, &from); | 1713 | to = from + range_length; |
| 1714 | to = from + range_length; | 1714 | |
| 1715 | 1715 | if (old_from != from) | |
| 1716 | if (old_from != from) | 1716 | from_byte = CHAR_TO_BYTE (from); |
| 1717 | from_byte = CHAR_TO_BYTE (from); | 1717 | if (to > ZV) |
| 1718 | if (to > ZV) | 1718 | { |
| 1719 | { | 1719 | to = ZV; |
| 1720 | to = ZV; | 1720 | to_byte = ZV_BYTE; |
| 1721 | to_byte = ZV_BYTE; | 1721 | } |
| 1722 | } | 1722 | else if (old_to == Z - to) |
| 1723 | else if (old_to == Z - to) | 1723 | to_byte = CHAR_TO_BYTE (to); |
| 1724 | to_byte = CHAR_TO_BYTE (to); | 1724 | } |
| 1725 | } | ||
| 1726 | 1725 | ||
| 1727 | del_range_2 (from, from_byte, to, to_byte, 0); | 1726 | del_range_2 (from, from_byte, to, to_byte, 0); |
| 1728 | signal_after_change (from, to - from, 0); | 1727 | signal_after_change (from, to - from, 0); |
diff --git a/src/lisp.h b/src/lisp.h index 74308985f18..2e46592c3d4 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3505,7 +3505,7 @@ extern void insert_from_string_before_markers (Lisp_Object, ptrdiff_t, | |||
| 3505 | ptrdiff_t, bool); | 3505 | ptrdiff_t, bool); |
| 3506 | extern void del_range (ptrdiff_t, ptrdiff_t); | 3506 | extern void del_range (ptrdiff_t, ptrdiff_t); |
| 3507 | extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, bool, bool); | 3507 | extern Lisp_Object del_range_1 (ptrdiff_t, ptrdiff_t, bool, bool); |
| 3508 | extern void del_range_byte (ptrdiff_t, ptrdiff_t, bool); | 3508 | extern void del_range_byte (ptrdiff_t, ptrdiff_t); |
| 3509 | extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool); | 3509 | extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool); |
| 3510 | extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t, | 3510 | extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t, |
| 3511 | ptrdiff_t, ptrdiff_t, bool); | 3511 | ptrdiff_t, ptrdiff_t, bool); |