8

When programming, I often switch from emacs to Xcode and viceversa. When I switch to Xcode, it automatically updates the current file when I focus Xcode window, if it detects that there are some external changes.

In emacs I have to press C-x C-v (but I lose the cursor position) or I have to press something and then insert r (reload?) in the minibuffer when emacs asks me what to do.

How to make emacs automatically reload the file (without losing the cursor position), it when I select back a buffer it corresponds to a modified file?

Thank you.

Drew
  • 75,699
  • 9
  • 109
  • 225
Nisba
  • 895
  • 8
  • 19
  • After 24.4, there are focus hooks. See for example: http://emacsredux.com/blog/2014/03/22/a-peek-at-emacs-24-dot-4-focus-hooks/ – Håkon Hægland Oct 30 '16 at 14:10

1 Answers1

11

This isn't specific to focus in/out but rather to just updating buffers when the underlying file changes. Emacs calls this "reverting" the buffer and has the functions revert-buffer to do it manually and auto-revert-mode to revert automatically when the file changes on disk. auto-revert-mode can be added to the hook for whatever mode your using or you turn on global-auto-revert-mode (by adding (global-auto-revert-mode) to your .emacs).

erikstokes
  • 12,686
  • 2
  • 34
  • 56