Bug #727
Emacs UI: send-file (C-c C-f) should check if buffer and file are synchronized
Description
The emacs command C-c C-f
send a source
command to CoCoA-5, so CoCoA-5 reads the file on disk which may not be the same as the buffer -- I had edited my file using a second emacs, so the buffer was marked as "up-to-date" but the file on disk was different.
History
#1 Updated by John Abbott over 7 years ago
There is an emacs function diff-buffer-with-file
.
Another possibility is to run sum
on the buffer contents, and again on the underlying file; then compare the results.
Another possibility is to save the buffer contents to a temporary file (in /tmp/???
) then run cmp
on that file and the file underlying the buffer. I think diff-buffer-with-file
does more or less this.
#2 Updated by John Abbott over 4 years ago
It seems that a useful Emacs keyword is revert
.
There is auto-revert-mode
(and a global version).
Another possibility could be to try to insert a character, which would presumably trigger a check that buffer and disk file are synchronized, then try to delete the inserted character --- Mmmm, but what happens if the buffer is reverted? Then no character should be deleted. Maybe deletion should occur only if the buffer is still marked as modified (after reverting it would be marked as unmodified).
#3 Updated by John Abbott over 3 years ago
- Target version changed from CoCoA-5.?.? to CoCoA-5.4.2
I got caught out by this just a short while ago.
I have searched on internet, but there does not seem to be an easy fn to check whether buffer and file are still byte identical (giving the answer as a boolean).
Another approach could be to try to force saving the buffer even though it is marked as unchanged (not sure how to do this).
Using sum
is probably a decent compromise (unless the file is very large).
Perhaps use wc
first to make sure that the byte lengths are the same?
NOTE: there is an emacs fn mark-whole-buffer
which could be useful
#4 Updated by John Abbott about 2 months ago
- Status changed from New to In Progress
- Target version changed from CoCoA-5.4.2 to CoCoA-5.4.4
- % Done changed from 0 to 10
https://superuser.com/questions/712237/safely-reload-files-which-are-changed-on-disc