154

M-x revert-buffer will do exactly what you want. It will still ask for confirmation. Another option (my favorite) is the below function: ;; Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el (defun revert-buffer-no-confirm () "Revert buffer without confirmation." (interactive) (revert-buffer :ignore-auto :noconfirm))


66

There is also auto-revert-mode which does it automatically and gives you feedback. From the doc string: auto-revert-mode is an interactive autoloaded compiled Lisp function in `autorevert.el'. (auto-revert-mode &optional ARG) Toggle reverting buffer when the file changes (Auto Revert mode). With a prefix argument ARG, enable Auto Revert mode if ARG ...


63

Another option, which I use, is find-alternate-file bound to C-x C-v. This opens a file reusing your current buffer. By default, it points to the file you're currently on, so you can just type C-x C-v RET to reload your file. It won't prompt unless your buffer has unsaved data. Some non-text modes like image-mode (used for rendering pictures, pdfs, svgs......


14

A minor mode is not enabled/disabled by setting a variable. The minor mode variable should be used to check the "mode enabled" status, not to set the mode state. If its value is t, the minor mode is on, else the mode is off. See the below snippets to see how to control any minor mode. Replace MINOR-MODE-NAME with the actual minor mode name you are dealing ...


13

Customize option auto-revert-verbose to nil. C-h v tells you this: auto-revert-verbose is a variable defined in autorevert.el. Its value is t Documentation: When nil, Auto-Revert Mode does not generate any messages. When non-nil, a message is generated whenever a file is reverted. You can customize this variable. It's kind of a shame that the doc of auto-...


12

If you use magit you can create a stash with the z z command from the magit-status buffer. You can also pop a stash using the A command. If you use these commands, affected files will be automatically reverted (changes are loaded). Check out the magit documentation for more info on how to use magit effectively.


12

Emacs calls this reverting. You can revert the current file with M-x revert-buffer. This prompts for confirmation whether the file has been modified or not, except for files that match patterns listed in the variable revert-without-query (see the manual for details). Another occasional annoyance of revert-buffer is that it resets the file mode to the ...


12

Original Here is my slightly improved version of the snippet in the question. Reviewing my VC history, I confirm that the below snippet started out as the snippet posted by the OP. So I do pay attribute to that. Here's the code that has been stable for me: (defun modi/revert-all-file-buffers () "Refresh all open buffers from their respective files.&...


10

you can also enable global-auto-revert-mode as shown below (global-auto-revert-mode 1) this is helpful when you do a lot of checks of your js files with auto-fix mode enabled, like in jssc.


9

revert-buffer is there. But I like to have some feedback. I have the following in my .emacs. (global-set-key (kbd "C-c r") (lambda () (interactive) (revert-buffer t t t) (message "buffer is reverted")))


8

Not sure what you're asking. But FWIW, I use this, and I bind it to <f5>: (defun revert-buffer-no-confirm () "Revert buffer without confirmation." (interactive) (revert-buffer t t)) Note that you probably do not want to redefine or advise revert-buffer. You probably want to change the behavior only for interactive calls (there are plenty of Lisp ...


8

In case someone else runs into this, I had enabled TeX-auto-save, which saves settings to an auto/ directory and loads them when a file is revisited. https://www.gnu.org/software/auctex/manual/auctex/Parsing-Files.html


7

Set auto-revert-remote-files to nil. This disables auto reverting for all files with Tramp syntax. If you want to disable auto reverting of remote files in a mounted directory, or in a sync directory, add that directory name to auto-revert-notify-exclude-dir-regexp.


6

Another: (defun revert-all-no-confirm () "Revert all file buffers, without confirmation. Buffers visiting files that no longer exist are ignored. Files that are not readable (including do not exist) are ignored. Other errors while reverting a buffer are reported only as messages." (interactive) (let (file) (dolist (buf (buffer-list)) (setq ...


6

For spacemacs users: SPC b R (spacemacs/safe-revert-buffer). For skipping confirmation, other answers already cover that, though I agree with others that it's probably not a good idea to bind that to a key.


5

Magit manages file reversions for you automatically, thus solving your core problem. You also benefit from its other features. Here are the docs for the tweaking the settings you're interested in: If you stick with Magit, also be sure to enable all 3 global WIP modes (Work In Progress) to avoid losing work. You can thus perform version-control actions ...


4

If I understand correctly, "revert" means to reload the file in the file system into the emacs buffer This is correct. (There are other details which you can read about in the documentation, including what "revert" means to non-file-visiting buffers; but broadly speaking your understanding is accurate.) so the buffer will be updated with the latest ...


4

As Dan pointed out, by default you need to manually revert dired buffers (e.g., by typing g) in order to update the directory listing view. If you want this to happen automatically, then you can turn on auto-revert mode. For example, (add-hook 'dired-mode-hook #'(turn-on-auto-revert-mode)) But see the Emacs manual, node Auto Reverting Dired for some ...


3

You can see what command a key sequence is bound to by using 'M-x describe-key' (normally bound to 'C-h k'). Switching to a dired buffer and running C-h k gives an extensive help text. The start is: g runs the command revert-buffer (found in dired-mode-map), which is ...


3

You don't set the variable using setq, you call the function: (global-auto-revert-mode)


3

It seems that this problem is caused by a bug of emacs-jedi. To avoid it, Upgrade emacs-jedi to the latest version (newer than 736300f). Set jedi:install-imenu to nil (the default value is nil). Something is wrong with jedi:after-change-handler. But I do not fully understand why the problem occurs. It is related to asynchronous programming and is hard to ...


3

You could use C-hv global-auto-revert-ignore-buffer with C-hv find-file-hook (defun my-inhibit-remote-auto-revert () "Used in `find-file-hook'." (when (file-remote-p buffer-file-name) (setq global-auto-revert-ignore-buffer t))) (add-hook 'find-file-hook #'my-inhibit-remote-auto-revert)


2

Variable text-scale-mode-amount holds the number of text-scale-mode steps. (Variable text-scale-mode-step holds the amount to scale for each step.) Save text-scale-mode-amount, then later pass it to text-scale-increase.


2

I accepted Kausal's answer since it was closest to what I wanted, but I grabbed part of Drew's solution, too. I wrapped revert-buffer in with-demoted-errors and dropped the :preserve-modes parameter so that my syntax checker would re-parse all of my open files. I also let it kill modified files as well as unmodified, since I often get in trouble by ...


2

grepping for "really edit the buffer" in emacs source I found function ask-user-about-supersession-threat in file userlock.el. It seems straightforward to add a d choice for calling ediff-current-file. I haven't tested this extensively, though (edits marked with ;;- comments). (defun ask-user-about-supersession-threat (fn) "Ask a user who is about to ...


2

you could use a local variable in your org files this way: # Local Variables: # eval: (auto-revert-mode) # End: Just append those lines at the end of each generated file. It'll work next time you open them. That should take care of those passive files.


2

The revert-buffer function takes a few parameters which I think make the reload faster. I've got this bound to a keyboard shortcut for reloading the current buffer, it feels as fast as when you first open the file: (defun reload-file-preserve-point () (interactive) (when (or (not (buffer-modified-p)) (y-or-n-p "Reverting will discard changes....


2

When there is an error in the syntax highlighting code, it is silently ignored by the font-lock package. When this happens, the buffer can be left in an unhighlighted state. You can use the package font-lock-studio to investigate what happens, and catch errors in the font-lock code. It is a debugger that lets you step each part of the font-lock rules and if ...


1

See: https://www.gnu.org/software/emacs/manual/html_node/elisp/Idle-Timers.html To see the mandatory and optional arguments to functions such as run-with-timer and revert-buffer, type C-h f (aka M-x describe-function). How about something like this? (run-with-timer 0 (* 60 60) (mapc (lambda (buffer) (with-current-buffer buffer (...


Only top voted, non community-wiki answers of a minimum length are eligible