reddit / emacs
Emacs Debugging Basics
whatacold · 2022-10-04 07:23
xenodium · 2022-10-04 07:35
Thanks. Today I learned of `debug-on-message`.
pwnedary · 2022-10-04 09:46
> (In case you do not know yet, here is how to type M-x toggle-debug-on-error on the keyboard: alt+x SPACE toggle-debug-on-error RETURN)
`SPACE` should not be there right?
whatacold · 2022-10-04 10:57
Good catch, thanks for pointing it out.
Just fixed it.
00-11 · 2022-10-04 16:01
`C-h f debug-on-entry`
`C-h f debug`
donio · 2022-10-04 17:24
For more in-depth debugging there is also edebug which has the usual debugger features like of stepping through code, breakpoints, watches. You need to instrument the function(s) to be debugged using `C-u C-M-x`.
For macros I find the `macrostep` package very handy, it lets you interactive expand or collapse macros in their source context. Or just `M-x pp-macroexpand-last-sexp` often does the job too.
Drack37 · 2022-10-04 19:19
Very helpful to learn how to debug errors, thanks! What about a next post concerning how to debug performance issues?
whatacold · 2022-10-05 00:35
Thanks for mentioning these.
I briefly mentioned `debug-on-entry` in the end, but as to `debug`, I still don't know when to use it after reading the docstring.
Would you like to elaborate on it? Thanks.
whatacold · 2022-10-05 00:45
Good idea, but I don't yet have much experience about debugging performance issues myself (I did try to write a post about how not to make emacs slow while we're interacting with it), I will think about it, thanks for the suggestion.
whatacold · 2022-10-05 00:53
Yes, edebug is powerful for debugging in the source code level. I did not mention it because it isn't suitable (or is over killed) for beginners.
Maybe I'd write an advanced emacs/elisp debugging techniques in the future:)
00-11 · 2022-10-05 04:03
Function `debug` opens the debugger; nothing more.
You can put calls to `debug` at places in code where you want a breakpoint, i.e., you want to enter the debugger.
Read the fine manual (and doc string) about using the debugger.
In a nutshell: `d` to single-step through evaluation. `c` to skip through evaluation (i.e., just evaluate the current sexp completely, without going through its evaluation step-by-step). `q` to quit the debugger.
whatacold · 2022-10-05 06:02
Got it, thanks for the detailed explanation.
celeritasCelery · 2022-10-05 14:58
For debugging init file problems, I have gotten a lot of mileage out of [elisp-bug-hunter](https://github.com/Malabarba/elisp-bug-hunter). It will automatically bisect your init file to find the problematic code. It is one of the first things I load in my init.
whatacold · 2022-10-05 15:45
Wow, cool package!
Gonna put a link to it in my post, thanks!