4

M-x revert-buffer resets the active minor modes to the defaults for the underlying file. How can I preserve the minor modes active while reverting the buffer?

My attempt so far:

(defun revert ()
  (interactive)
  (let ((active-modes minor-mode-list))
   (revert-buffer t t)
   (setq minor-mode-list active-modes)))

This seemed broadly reasonable. Save minor-mode-list, revert the buffer, setq to restore. Calling (revert) seems to be exactly equivalent to calling revert-buffer and I'm not sure how to debug this.

What am I missing?

1 Answers1

7

I think you're missing the third argument to revert-buffer:

Optional third argument PRESERVE-MODES non-nil means don’t alter the files modes. Normally we reinitialize them using ‘normal-mode’.

That should do exactly what you want, without requiring any further book-keeping on your part.

Tyler
  • 22,234
  • 1
  • 54
  • 94