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 2


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

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.

  • 1
    In my tests, --debug-init had already been removed from command-line-args by the time custom init code was executed, so that wasn't a viable method of detection.
    – phils
    Aug 15, 2023 at 14:48
  • Thanks for that catch, I've updated that portion to point to your answer! Aug 15, 2023 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.