Created
July 28, 2012 00:01
-
-
Save jacott/3191131 to your computer and use it in GitHub Desktop.
Fix Emacs thinking a file has changed when its contents haven't only its modification time. Useful when using git checkout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun update-visited-file-modtime-if-unchanged () | |
"Check the contents of all file buffers with changed file-modtime to see if they have really changed. | |
If not `set-visited-file-modtime' to match file." | |
(interactive) | |
(with-temp-buffer | |
(buffer-disable-undo) | |
(let (buf | |
fn | |
(cbuf (current-buffer)) | |
(buffers (buffer-list))) | |
(while buffers | |
(setq buf (car buffers)) | |
(setq buffers (cdr buffers)) | |
(when (and (setq fn (buffer-file-name buf)) (not (verify-visited-file-modtime buf)) (file-exists-p fn)) | |
(erase-buffer) | |
(insert-file-contents fn) | |
(when (= (buffer-size) (buffer-size buf)) | |
(with-current-buffer buf | |
(save-restriction | |
(widen) | |
(when (= 0 (compare-buffer-substrings cbuf 1 (buffer-size) buf 1 (buffer-size))) | |
(set-visited-file-modtime)))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment