I'd like to turn some things off normally and then re-enable them when emacs is started with --debug-init. For example, I get loads of warnings about the length of doc-strings in packages. I want to suppress these warnings normally, but I'd like to be able to see wall these warnings when I am in debug mode.
2 Answers
Most directly:
(when init-file-debug (message "--debug-init")) as the --debug-init argument results in (setq init-file-debug t)
Or more indirectly:
(when (eq debug-on-error 'startup) (message "--debug-init")) as startup is the value given when (eq init-file-debug t)
(I'd go with the first option, though.)
I looked at C-h describe-variable and was able to find the variable debug-on-error. This might be an even better option than just a variable which signifies that the --debug-init argument was called, as this is a non-nil whenever emacs is set to enter debugger on an error signal, and not just if a specific CLI argument is called.
This something to the effect of
(if debug-on-error (foo) (bar)) Should do the trick to run foo when the debug-on-error is t and run bar otherwise.
If you only want this to work when --debug-init is called look check @phils solution instead.
- 1In my tests,
--debug-inithad already been removed fromcommand-line-argsby the time custom init code was executed, so that wasn't a viable method of detection.phils– phils2023-08-15 14:48:31 +00:00Commented Aug 15, 2023 at 14:48 - Thanks for that catch, I've updated that portion to point to your answer!Ian Pringle– Ian Pringle2023-08-15 14:53:00 +00:00Commented Aug 15, 2023 at 14:53