2

In one of my windows I've opened "output.png" and I would like emacs to automatically reload it if it has changed.

I would like to do this for all PNG files which are currently open, but only PNG files. How to I do this?

1

You need to enable the auto-revert-mode. It will reload the file every 5 seconds. see gnu.org/emacs/manual/Reverting

To enable it in the image buffer for the current session only type M-x auto-revert-mode

Note: in my experience with Emacs 25.3 the buffer will display the image as ascii text after reverting it. To fix that type: M-x auto-image-file-mode

To use these settings for all buffers displaying an image I've added to my ~/.emacs/ file:

(add-hook 'image-mode-hook
  (lambda ()
    (auto-revert-mode)
    (auto-image-file-mode)))
  • Thanks to this answer for setting me on the right path: emacs.stackexchange.com/a/245/17434 – basilikode Jan 15 '18 at 20:22
  • Note that nowadays Emacs tries to use filesystem notifications rather than polling (i.e. changes are reported to Emacs by the OS if and when they occur). auto-revert-use-notify was introduced in 24.4, but then disabled by global-auto-revert-mode in 25.1 due to bug#22814 (which seems like it was specific to OSX, but I haven't read it in detail), and was re-enabled again in 26.1, with a solution for that bug having been committed. – phils Sep 13 '18 at 7:35
  • auto-image-file-mode is a global minor mode, so just use (auto-image-file-mode 1) in your init file, rather than calling it every time image-mode-hook runs. – phils Sep 13 '18 at 7:39
  • After which you can reduce that hook to: (add-hook 'image-mode-hook 'auto-revert-mode) – phils Sep 13 '18 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.