Debugging Elisp Part 1: Earn your independence24 Nov 2014, by Artur Malabarba.
Debugging Emacs-Lisp post series
- Debugging Elisp Part 1: Earn your independence
- Debugging Elisp Part 2: Advanced topics
Running into errors is not only a consequence of tinkering with your editor, it is the only road to graduating in Emacs. Therefore, it stands to reason that Emacs would contain the most impressive debugging utilities know to mankind, Edebug.
Learning to Edebug is the right decision for anyone who doesn't know how to Edebug.
- It's easy as pie, you have no excuse not to learn it.
- It helps you solve your own problems. Not that the community isn't helpful, it just allows you to help yourself—which will eventually allow you to help the community.
- If you're a newcomer, it will teach you more about elisp than most tutorials out there.
- If you're anything other than a newcomer, then it's about time and you should be ashamed of yourself.
A quick first stop
How to Edebug a function
- Go to where the function is defined. You can usually do that with C-h f (which calls describe function) or just M-x find-function.
- Press C-u C-M-x. This turns on Edebug for that function.
- Now, just invoke the function (or some other command that calls that function).
The next time the Edebugged function gets called, Emacs will display its source code and will take you through it step-by-step. Press n to continue to the next step or c to stop fooling around and skip to the end.
For instance, to solve the issue that lead me to write this, we could perform the following sequence of commands:
Once a function has been instrumented, it will trigger Edebug every time it is called. To undo this effect (to remove instrumentation) simply visit its definition again and hit C-M-x without the prefix.q