Is it possible to set Emacs start-up command-line flags such as -nw and -q in an init file? If it is, how can I do that?

  • Being a non-native English speaker, your corrections are gold to me, @Drew -- thanks!
    – solr
    Jun 23, 2019 at 23:57

2 Answers 2


You can modify the command line arguments in an init file if you want. But if you do that after Emacs has processed the argument, it won't have any effect.

Emacs processes command line arguments in two places: in the C startup code, and in startup.el. The C startup code processes arguments before it executes any Lisp code, so there's no way to influence that from an init file. As of Emacs 26.2, the following options are handled in C: --version, --chdir, -t, -nw, --batch, --script, -daemon, --bg-daemon, --fg-daemon, --help, --no-loadup, --no-site-lisp, --no-build-details, --module-assertions and (partially) --display.

So in particular there's no way to completely prevent the initialization of the window system (-nw) from Lisp.

You can modify other options from a Lisp file that's loaded before startup.el processes the command line. The main relevant steps are:

  • Load subdirs.el from directories on the load path. You can control this with the environment variable EMACSLOADPATH.
  • Process some command line options (code), including the ones that control what init files to load (e.g. -Q, -q) and a few user interface variables (including -display).
  • Finish initializing the window system and create the initial frame.
  • Load site-start.el (prevented by -Q) and the user init file (.emacs or other name, prevented by -q or -batch).
  • Call package-initialize.
  • Process remaining command line options (code), including options that control the appearance of Emacs and options to run code and open files (-l, --eval, --find-file, …).
  • There're tons of stuff to digest in this answer, thank you for your thorough answer, Gilles.
    – solr
    Jun 23, 2019 at 23:52

Is it possible to set Emacs start-up command-line flags such as -nw and -q in an init file? If it is, how can I do that?

In general, no, you can't do that -- and your second example option is precisely what I would have used to explain why:

-q (aka --no-init-file) tells Emacs not to load your init file, so trying to set that option in your init file does not make sense.

That said... some arguments are processed after loading the init file, and so for certain arguments you could populate the command-line-args variable in your init file to imitate using them on the command line. These options include:



(setq command-line-args
      (append command-line-args '("--eval"
                                  "(message \"hello\")")))

I would not expect there to be any benefit to jumping through such hoops to use these "Action options" in your init file, as there are more direct ways of performing the actions.

  • Oh.. I meant -Q! I didn't know about command-line-args, that's a great piece of advice -- thank you.
    – solr
    Jun 23, 2019 at 23:52
  • 1
    Note that -Q implies -q, and so the same issue applies.
    – phils
    Jun 24, 2019 at 0:14
  • Ohh... Your comment surely solved me future headaches 🙌
    – solr
    Jun 24, 2019 at 0:35
  • I would assume the bigger use-case is the opposite - not to add arguments, but to remove them. Not sure when you'd want that, but I could imagine a situation where I have a custom argument which causes some behavior that is incompatible with some other arguments, and either it conceptually makes sense to treat the custom argument as implying an ignoring of those incompatible arguments, or it's more practically convenient for the sake of some scripts which programmatically build or add arguments for an emacs invocation.
    – mtraceur
    Mar 30, 2023 at 6:32

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.