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?
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.)
The manual for debugging elisp can be found here.
You can used edebug
as mentioned, there's also M-x debug-on-entry and you can set (setq debug-on-quit t)
. Check out all the options in the link, it all depends on how you want to skin the cat.
And just like in any other programming language, you can debug with print statements. (message "here, foo=%d" foo)
is your friend. (You probably know that these messages are accumulated in the *Messages*
buffer, so if they go by too quickly, that's not a problem.) trace-function
is also helpful.
I have written a lot of emacs modes and have only rarely needed the debugger. Usually the problem exposes itself with a few well-placed print statements.
On an another note as well if you want to just quickly debug some lisp snippet you maybe want to use the ielm mode as well which works like for example the python interactive mode.