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


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.

  • That's a good observation. Passing another t along works nicely, thanks! – Jon Chesterfield Feb 14 '17 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.