Skip to content
May 31, 2007 / edivad

emacs reload a file

In order to reload a file, you can use the macro M-x revert-buffer (if you want you can bind it to a key), or use a more practice trick: use C-x C-v RET. This tell to find an alternate file and by default emacs suggests you the current file.

25 Comments

Leave a Comment
  1. Marko Anastasov / Jun 19 2007 9:52 am

    Nice tip, thanks (I was looking for it). The manual doesn’t explicitly mention that C-x C-v can be used that way…

  2. arulkumar c / Mar 26 2008 11:19 am

    Thanks for this post. It was what I was looking for…

  3. Ashrentum / Jul 3 2008 2:28 pm

    thanks ^^

  4. fofu / Aug 5 2008 2:46 pm

    thanks a lot, I was looking for that a long time ago,

  5. Krishnan / Aug 12 2008 8:18 am

    my thanks too for the tip.

  6. Neville Grech / Dec 30 2008 2:48 pm

    Thanks. I knew about the c-x c-v command but it never occured to me to use it for that purpose!

  7. Jochem / Mar 10 2009 2:24 pm

    cool! thanks!

  8. Mort / Mar 25 2009 4:18 pm

    Very useful, thanks for the tip!

  9. Johan / Jun 8 2009 3:18 pm

    Very nice! Thanks

  10. Klaus / Aug 4 2009 8:05 am

    I wrote a revert buffer function and bound it to a key that avoids a confirmation:
    (defun my-revert-buffer()
    “revert buffer without asking for confirmation”
    (interactive “”)
    (revert-buffer t t)
    )

    Useful I also find the following kill-buffer function that does not ask for confirmation.
    I bind it to a F3 say, and Shift-F3 to reload the buffer:

    (global-set-key [f3] ‘my-kill-buffer)
    (global-set-key [S-f3] ‘my-unkill-buffer)

    (defvar my-latest-killed-buffer)
    (defun my-kill-buffer()

    Kill current buffer without confirmation.
    To undo latest kill call ‘my-unkill-buffer’

    (interactive)
    (setq my-latest-killed-buffer (buffer-file-name) )
    (kill-buffer (buffer-name))
    )
    (defun my-unkill-buffer()

    Undo the latest buffer kill

    (interactive)
    (find-file my-latest-killed-buffer )
    )

    • edivad / Aug 4 2009 9:31 am

      Thanks for sharing :)

    • vivianne / Jun 7 2010 1:56 pm

      Nice!!! Thanks!!!

  11. Chris D. / Nov 2 2009 6:13 am

    Thanks, very helpful!

  12. tom / Jan 4 2010 4:27 pm

    Thank you for this, exactly what I was looking for :)

  13. ruslan / Jan 12 2010 12:54 pm

    great! thx!

  14. yanni / Feb 10 2010 6:10 pm

    Cool! Thanks!

  15. Æ / Mar 3 2010 9:42 am

    Nice, thx.

  16. kasidit / Apr 28 2010 3:29 am

    Thanks! exactly looking for this emacs refresh cmd.

  17. vivianne / Jun 7 2010 1:55 pm

    Thank you so much for that! Concise and to the point, awesome!

  18. James Coleman / Dec 2 2010 8:14 pm

    Or to have emacs periodically reload external changes in all buffers:

    M-x customize-variable
    global-auto-revert-mode
    Toggle
    Save for future

    Most of the time exactly the behaviour you want.
    Sometimes not, of course if you have edited the buffer the usual revert buffer question which changes to keep is applied.

  19. hectorh30 / Dec 10 2010 6:27 pm

    thanks! very helpful (:

  20. Marcos / Jul 11 2011 6:26 am

    Muchas Gracias!!!
    thx you!

  21. ketan / Dec 6 2011 7:39 pm

    thanks

Trackbacks

  1. emacs reload a file « Yangliuosu's Blog
  2. Emacs: Reload File | daytome

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.