diff options
| author | Eli Zaretskii | 2022-07-07 11:56:31 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2022-07-07 11:56:31 +0300 |
| commit | 74f43f82e6b4702027d99edb6ca125f3243ce4ba (patch) | |
| tree | 7d8fbfec626fe32b87ea7518219a5365d47bfd3e /src | |
| parent | b075a59a1a4ddfd0668da4fb2312a6ec747dd53b (diff) | |
| download | emacs-74f43f82e6b4702027d99edb6ca125f3243ce4ba.tar.gz emacs-74f43f82e6b4702027d99edb6ca125f3243ce4ba.zip | |
Fix undo of changes in cloned indirect buffers
* lisp/simple.el (primitive-undo): If the visited-modtime of the
indirect buffer's file is bogus, use the modtime of the file
visited by its base buffer.
* src/undo.c (record_first_change): Call
'buffer_visited_file_modtime' with the correct buffer, instead of
always calling 'Fvisited_file_modtime', which returns possibly
bogus values for indirect buffers.
* src/fileio.c (Fset_visited_file_modtime): Signal a meaningful
error for indirect buffers.
(buffer_visited_file_modtime): New function, with implementation
taken from 'Fvisited_file_modtime'.
(Fvisited_file_modtime): Call 'buffer_visited_file_modtime'.
* src/lisp.h: Add prototype for 'buffer_visited_file_modtime'.
(Bug#56397)
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 16 | ||||
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | src/undo.c | 2 |
3 files changed, 14 insertions, 5 deletions
diff --git a/src/fileio.c b/src/fileio.c index 10d4b8bc15e..d07e62a1212 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -5832,6 +5832,15 @@ See Info node `(elisp)Modification Time' for more details. */) | |||
| 5832 | return Qnil; | 5832 | return Qnil; |
| 5833 | } | 5833 | } |
| 5834 | 5834 | ||
| 5835 | Lisp_Object | ||
| 5836 | buffer_visited_file_modtime (struct buffer *buf) | ||
| 5837 | { | ||
| 5838 | int ns = buf->modtime.tv_nsec; | ||
| 5839 | if (ns < 0) | ||
| 5840 | return make_fixnum (UNKNOWN_MODTIME_NSECS - ns); | ||
| 5841 | return make_lisp_time (buf->modtime); | ||
| 5842 | } | ||
| 5843 | |||
| 5835 | DEFUN ("visited-file-modtime", Fvisited_file_modtime, | 5844 | DEFUN ("visited-file-modtime", Fvisited_file_modtime, |
| 5836 | Svisited_file_modtime, 0, 0, 0, | 5845 | Svisited_file_modtime, 0, 0, 0, |
| 5837 | doc: /* Return the current buffer's recorded visited file modification time. | 5846 | doc: /* Return the current buffer's recorded visited file modification time. |
| @@ -5841,10 +5850,7 @@ visited file doesn't exist. | |||
| 5841 | See Info node `(elisp)Modification Time' for more details. */) | 5850 | See Info node `(elisp)Modification Time' for more details. */) |
| 5842 | (void) | 5851 | (void) |
| 5843 | { | 5852 | { |
| 5844 | int ns = current_buffer->modtime.tv_nsec; | 5853 | return buffer_visited_file_modtime (current_buffer); |
| 5845 | if (ns < 0) | ||
| 5846 | return make_fixnum (UNKNOWN_MODTIME_NSECS - ns); | ||
| 5847 | return make_lisp_time (current_buffer->modtime); | ||
| 5848 | } | 5854 | } |
| 5849 | 5855 | ||
| 5850 | DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime, | 5856 | DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime, |
| @@ -5871,6 +5877,8 @@ in `current-time' or an integer flag as returned by `visited-file-modtime'. */) | |||
| 5871 | current_buffer->modtime = mtime; | 5877 | current_buffer->modtime = mtime; |
| 5872 | current_buffer->modtime_size = -1; | 5878 | current_buffer->modtime_size = -1; |
| 5873 | } | 5879 | } |
| 5880 | else if (current_buffer->base_buffer) | ||
| 5881 | error ("An indirect buffer does not have a visited file"); | ||
| 5874 | else | 5882 | else |
| 5875 | { | 5883 | { |
| 5876 | register Lisp_Object filename; | 5884 | register Lisp_Object filename; |
diff --git a/src/lisp.h b/src/lisp.h index e4a49b8ef94..35cc7f5a098 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -4733,6 +4733,7 @@ extern bool internal_delete_file (Lisp_Object); | |||
| 4733 | extern Lisp_Object check_emacs_readlinkat (int, Lisp_Object, char const *); | 4733 | extern Lisp_Object check_emacs_readlinkat (int, Lisp_Object, char const *); |
| 4734 | extern bool file_directory_p (Lisp_Object); | 4734 | extern bool file_directory_p (Lisp_Object); |
| 4735 | extern bool file_accessible_directory_p (Lisp_Object); | 4735 | extern bool file_accessible_directory_p (Lisp_Object); |
| 4736 | extern Lisp_Object buffer_visited_file_modtime (struct buffer *); | ||
| 4736 | extern void init_fileio (void); | 4737 | extern void init_fileio (void); |
| 4737 | extern void syms_of_fileio (void); | 4738 | extern void syms_of_fileio (void); |
| 4738 | 4739 | ||
diff --git a/src/undo.c b/src/undo.c index 36664d16424..f76977dbe50 100644 --- a/src/undo.c +++ b/src/undo.c | |||
| @@ -218,7 +218,7 @@ record_first_change (void) | |||
| 218 | base_buffer = base_buffer->base_buffer; | 218 | base_buffer = base_buffer->base_buffer; |
| 219 | 219 | ||
| 220 | bset_undo_list (current_buffer, | 220 | bset_undo_list (current_buffer, |
| 221 | Fcons (Fcons (Qt, Fvisited_file_modtime ()), | 221 | Fcons (Fcons (Qt, buffer_visited_file_modtime (base_buffer)), |
| 222 | BVAR (current_buffer, undo_list))); | 222 | BVAR (current_buffer, undo_list))); |
| 223 | } | 223 | } |
| 224 | 224 | ||