Posts Tagged ‘emacs’

emacs – Reload File

Tuesday, October 21st, 2008

I wrote my first emacs lisp function today. Emacs is a little annoying when the files get changed outside of the editor – such as when you are working with svn. I found several methods to tell emacs to reload the file (C-x C-v) but they all have one caveat: they forget where you are in the buffer. I fixed this situation with a short function:

(defun reload-file ()
  (interactive)
  (let ((curr-scroll (window-vscroll)))
    (find-file (buffer-name))
    (set-window-vscroll nil curr-scroll)
    (message "Reloaded file")))
 
(global-set-key "\C-c\C-r" 'reload-file)

Put that in .emacs, and you simply have to type C-c C-r to reload the current file (while saving your scroll position!)