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.

Advertisements

28 thoughts on “emacs reload a file

  1. Klaus says:

    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 )
    )

  2. 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.

  3. Sparsile says:

    I use Eclipse for Android programming, but prefer Emacs for long stretches of entering code into files. When I change a file in Eclipse (import a package, for example), it’s nice to have the same file already loaded in emacs automatically refresh. To do this, add “global-auto-revert-mode 1)” in your emacs start up file. Magic!

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 )

Google+ photo

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

Connecting to %s