Debug Emacs Lisp major mode

elisp, emacs

Solution

Find the Lisp source of the function you'd like to step through, and type `M-x edebug-defun` there. Then, whenever that function is executed, you'll automatically be placed into Edebug, where you can step through it if you wish.

Fontification functions can be a bit tricky though, as they can be invoked at odd times. You can use the `message` function to write messages into the `*Messages*` buffer. Another trick is to turn off Font Lock (so your function doesn't get invoked automatically), then prep the function you're debugging with `edebug-defun` and invoke it manually. (Note that you can use `M-:` (a.k.a. `eval-expression`) to invoke a non-interactive function.)

Problem

I'm developing a major mode for Emacs. Is there any way that I can set a break point in the source code when fontification happens, for example?

Original source