2
votes

I have about 400 files open in my Emacs session. I was configuring some modes and all my buffers changed to fundamental-mode.

Now, when I open a file Emacs chooses the correct major mode, but the already opened files are still in fundamental mode. How do I force Emacs to reopen all the opened files and choose the right mode for each of them?

2

2 Answers

3
votes

Try this:

(defun aak/auto-mode-anywhere ()
  (interactive)
  (dolist (buffer (buffer-list))
    (with-current-buffer buffer
      (when (and
             (eq major-mode 'fundamental-mode)
             (buffer-file-name))
         (set-auto-mode)))))

M-x aak/auto-mode-anywhere won't exactly "reopen" files (no reverting or reloading), but it will set appropriate major mode for fundamental-mode buffers that are visiting files (based on auto-mode-alist etc.).

0
votes
  • M-x ibuffer RET
  • *M fundamental-mode RET -- to mark all fundamental-mode buffers
  • E (normal-mode) RET -- evaluate elisp in selected buffers
  • **RET -- remove all marks
  • q -- dismiss the ibuffer buffer