3

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?

Malabarba
  • 4,473
  • 2
  • 30
  • 49

2 Answers2

1

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).

Raja Selvaraj
  • 7,178
  • 3
  • 20
  • 13
1

Try

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

See Section 27.6 Buffer Modification Time.

huaiyuan
  • 26,129
  • 5
  • 57
  • 63