diff options
| author | Stefan Monnier | 2025-06-22 22:25:03 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2025-06-27 23:11:39 -0400 |
| commit | 6c0bbf0f921682a185ebd57efef1e9d4f8ced788 (patch) | |
| tree | a07e91ca4549ce6b5c273aa0cbd1e0b19a4b7540 /src/fileio.c | |
| parent | cb484ead91cb20f1cad31ac878a65ea1e9354871 (diff) | |
| download | emacs-6c0bbf0f921682a185ebd57efef1e9d4f8ced788.tar.gz emacs-6c0bbf0f921682a185ebd57efef1e9d4f8ced788.zip | |
(Finsert_file_contents): Refine commit d07af40d8826
* src/fileio.c (Finsert_file_contents): Inhibit ask-supersession
only if we're VISITing in a non-narrowed buffer (bug#78866).
* test/src/fileio-tests.el (ert--tests-dir): New var.
(fileio-tests--insert-file-contents-supersession): New test.
Diffstat (limited to 'src/fileio.c')
| -rw-r--r-- | src/fileio.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/fileio.c b/src/fileio.c index 7e1ac3fc383..9f04a5928bb 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -4550,14 +4550,19 @@ by calling `format-decode', which see. */) | |||
| 4550 | beg_offset += same_at_start - BEGV_BYTE; | 4550 | beg_offset += same_at_start - BEGV_BYTE; |
| 4551 | end_offset -= ZV_BYTE - same_at_end; | 4551 | end_offset -= ZV_BYTE - same_at_end; |
| 4552 | 4552 | ||
| 4553 | /* This binding is to avoid ask-user-about-supersession-threat | 4553 | if (!NILP (visit) && BEG == BEGV && Z == ZV) |
| 4554 | being called in insert_from_buffer or del_range_bytes (via | 4554 | /* This binding is to avoid ask-user-about-supersession-threat |
| 4555 | prepare_to_modify_buffer). | 4555 | being called in insert_from_buffer or del_range_bytes (via |
| 4556 | AFAICT we could avoid ask-user-about-supersession-threat by setting | 4556 | prepare_to_modify_buffer). |
| 4557 | current_buffer->modtime earlier, but we could still end up calling | 4557 | Such a prompt makes no sense if we're VISITing the file, |
| 4558 | ask-user-about-supersession-threat if the file is modified while | 4558 | since the insertion makes the buffer *more* like the file |
| 4559 | we read it, so we bind buffer-file-name instead. */ | 4559 | rather than the reverse. |
| 4560 | specbind (Qbuffer_file_name, Qnil); | 4560 | AFAICT we could avoid ask-user-about-supersession-threat by |
| 4561 | setting current_buffer->modtime earlier, but we could still | ||
| 4562 | end up calling ask-user-about-supersession-threat if the file | ||
| 4563 | is modified while we read it, so we bind buffer-file-name | ||
| 4564 | instead. */ | ||
| 4565 | specbind (Qbuffer_file_name, Qnil); | ||
| 4561 | del_range_byte (same_at_start, same_at_end); | 4566 | del_range_byte (same_at_start, same_at_end); |
| 4562 | /* Insert from the file at the proper position. */ | 4567 | /* Insert from the file at the proper position. */ |
| 4563 | temp = BYTE_TO_CHAR (same_at_start); | 4568 | temp = BYTE_TO_CHAR (same_at_start); |
| @@ -4666,8 +4671,9 @@ by calling `format-decode', which see. */) | |||
| 4666 | /* Truncate the buffer to the size of the file. */ | 4671 | /* Truncate the buffer to the size of the file. */ |
| 4667 | if (same_at_start != same_at_end) | 4672 | if (same_at_start != same_at_end) |
| 4668 | { | 4673 | { |
| 4669 | /* See previous specbind for the reason behind this. */ | 4674 | if (!NILP (visit) && BEG == BEGV && Z == ZV) |
| 4670 | specbind (Qbuffer_file_name, Qnil); | 4675 | /* See previous specbind for the reason behind this. */ |
| 4676 | specbind (Qbuffer_file_name, Qnil); | ||
| 4671 | del_range_byte (same_at_start, same_at_end); | 4677 | del_range_byte (same_at_start, same_at_end); |
| 4672 | } | 4678 | } |
| 4673 | inserted = 0; | 4679 | inserted = 0; |
| @@ -4716,8 +4722,9 @@ by calling `format-decode', which see. */) | |||
| 4716 | we are taking from the decoded string. */ | 4722 | we are taking from the decoded string. */ |
| 4717 | inserted -= (ZV_BYTE - same_at_end) + (same_at_start - BEGV_BYTE); | 4723 | inserted -= (ZV_BYTE - same_at_end) + (same_at_start - BEGV_BYTE); |
| 4718 | 4724 | ||
| 4719 | /* See previous specbind for the reason behind this. */ | 4725 | if (!NILP (visit) && BEG == BEGV && Z == ZV) |
| 4720 | specbind (Qbuffer_file_name, Qnil); | 4726 | /* See previous specbind for the reason behind this. */ |
| 4727 | specbind (Qbuffer_file_name, Qnil); | ||
| 4721 | if (same_at_end != same_at_start) | 4728 | if (same_at_end != same_at_start) |
| 4722 | { | 4729 | { |
| 4723 | del_range_byte (same_at_start, same_at_end); | 4730 | del_range_byte (same_at_start, same_at_end); |