How can I make Emacs break on an error, even if the error is being handled somewhere?

In my current scenario, the setup of a major mode is modifying the buffer and I want to find out why (and then fix it). I made a buffer read-only, ran edebug-defun on the major mode function and set debug-on-error to t, but running the major mode function still proceeds until it aborts with a “Buffer is read-only” error. How do I get it to break on error, so that I know where it is raised and can examine the environment? Or at the very least how do I get a backtrace?

  • You can try to temporary clear debug-ignored-errors, it contains a list of error symbols and regexp:s for which the debugger shouldn't start. Mar 29, 2016 at 11:34
  • @Lindydancer Indeed, thanks. I found that in the docstring of debug-on-error. Mar 29, 2016 at 11:52

1 Answer 1


Setting edebug options doesn't actually help here. Errors that are listed in debug-ignored-errors are ignored even while executing under Edebug. This isn't mentioned in the manual (as of Emacs 24.5) but it is mentioned in the docstring of debug-on-error (for which edebug-on-error is just a proxy). (I don't understand why debug-ignored-errors has any influence on Edebug: it only makes sense to me as errors for which the debugger should not trigger during normal operation, not while debugging.)

So remove the problematic error from debug-ignored-errors:

(setq debug-ignored-errors (delq 'buffer-read-only debug-ignored-errors))

or just set debug-ignored-errors to nil while doing any debugging. This plus setting debug-on-error to t is enough to break on the error and get a backtrace.

  • The idea with the debug-ignored-errors variable is to let users have debug-on-error set to t at all times, and only enter the debugger when a real error occurs. Things like moving the point beyond the end of a buffer or a normal user error should not activate the debugger. However, a buffer-read-only error is borderline, in most cases it should not start the debugger but in some cases it should. The manual should really include this information, please report this as an error. Mar 29, 2016 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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