The Debugger
Emacs Lisp has a built-in debugging mode that can be invoked automatically under certain circumstances. Entering the debugger is controlled as follows.
debug-on-entryThis is a command. It prompts (with completion) for the name of a function. Whenever that function is invoked, Emacs will enter the debugger.
debug-on-errorThis is a variable. If it is non-
nil, then Emacs will enter the debugger whenever an error is signaled.debug-on-next-callThis is a variable. If it is non-
nil, Emacs will enter the debugger the very next time an expression is to be evaluated.debug-on-quitThis is a variable. If it is non-
nil, Emacs will enter the debugger whenever a "quit" is signaled (e.g., when the user presses C-g).
When the debugger is invoked, a window displaying the Lisp stack appears. In this buffer, called *Backtrace*, each line represents a pending function call, with the top lines representing more recent calls. You can see the pending Lisp expressions, test the values of variables and other expressions in different contexts, and force a function to return a certain value.
These are the useful debugging-mode commands.
cLeave the debugger, continuing whatever code was interrupted by entering it. This isn't possible when the debugger was invoked because of an error.
qLeave the debugger, aborting the pending computation.
dContinue execution until the next function call, then reenter the debugger.
ePrompt for a Lisp expression to evaluate in the context of the topmost stack "frame."
b"Break" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access