Notify out-of-date buffers in the mode-line

183 views Asked by At

Sometimes I use an alternative method (usually sed) to edit a file that's already being edited by Emacs. Later, if I try to edit the file in Emacs without reverting the changes first, I get an error message and a prompt asking me what to do.

That's all fine. The problem is that I tend to forget very often when I've made some parallel changes, so I'd like Emacs to remind me by showing a red "M" in the mode-line.

I know how to customize the mode-line (by adding strings to the mode-line-format variable), but I have no idea how to check if a file has been modified outside of Emacs.

Is there a function to check whether an Emacs buffer is up to date with the file it corresponds?

2

There are 2 answers

0
huaiyuan On BEST ANSWER

Try

(verify-visited-file-modtime (current-buffer))

See Section 27.6 Buffer Modification Time.

0
Raja Selvaraj On

Not really a direct answer to the question, but you can avoid this problem by turning on auto-revert globally in emacs with (global-auto-revert-mode t).