emacs refresh F5 key
I use this little addition to my .emacs file to support reloading the current file I’m editing.
(defun refresh-file () (interactive) (revert-buffer t t t) ) (global-set-key [f5] 'refresh-file)
You can also use CTRL-x CTRL-v to do a “Find alternative file” and choose the same file that you are currently editing. F5 is a little quicker though.
July 18th, 2008 at 8:38 pm
Thanks, I like this little script!
January 7th, 2009 at 8:28 pm
A slight “enhancement” might be to have it prompt you if before reverting if the buffer is modified. That way you don’t lose all your work if you accidentally hit the F5 key.
You can do this by replacing the second “t” parameter to revert-buffer with “(not (buffer-modified-p))” like so…
(global-set-key [f5]
‘(lambda () “Refresh the buffer from the disk (prompt of modified).”
(interactive)
(revert-buffer t (not (buffer-modified-p)) t)))
May 12th, 2009 at 7:07 pm
Awesome tip. Thanks!
September 13th, 2010 at 5:58 am
Thanks for sharing this. I’m using it now and really like it.
> You can also use CTRL-x CTRL-v to do a
> “Find alternative file” and choose the same file
> that you are currently editing. F5 is a little quicker though.
Also, the C-x C-v method doesn’t preserve cursor position in the buffer, so I really think binding (revert-buffer) is superior.
June 28th, 2011 at 8:33 pm
This is extremely useful. Thank you so much!!