I frequently forget to start my X server before I fire up emacs. Obviously emacs will attempt to open an X window and fail.

In older versions of emacs (I forget when this changed) the behavior was an error message and emacs would exit. In current versions of emacs there is an error message and then emacs starts up in no-window-system mode.

How do I restore the older behavior?

2 Answers 2


Since Emacs 23, you no longer need to care whether Emacs was started from inside X. Start Emacs however you like, possibly as a daemon. Open and close frames on any display as desired.

Start Emacs with

emacs --daemon

then when you want to edit a file, run

emacsclient MYFILE

or if you just want to create a frame, run

emacsclient -c

which will create an X11 frame if an X11 display is available, and a terminal frame otherwise.

If you prefer to start Emacs with a frame on a terminal, make sure that your init file includes


Run emacs normally. If you've started it outside X, you'll get a terminal frame. You can at any point call emacsclient -c with the DISPLAY environment set to open a GUI frame. Once a GUI frame exists, you can close the terminal frame. The Emacs process will still have the original terminal as its controlling terminal, but you can send it to the background (Ctrl+Z then use the shell command bg) and close the original terminal, and keep using the new GUI frame (and any other frame you care to create). What you can't do as far as I know is close the initial terminal frame but keep Emacs running in the background to open new frames later, i.e. you can't daemonize a running Emacs.

If for some reason you want to run a new instance of Emacs and you want it to use an X11 display and refuse to start otherwise, you can do this with a shell command:

emacs -d "$DISPLAY"

Explicitly passing the -d option forces the use of an X11 display.


I don't know actual answer but a workaround would be placing the following snippet on top of your init file to make emacs to exit if X isn't already started.

(when (eq window-system nil)
  • 3
    I know I'm being fussy; but sometimes running emacs -nw is also desirable. I want to have explicit control.
    – ericx
    Commented Feb 12, 2015 at 18:54
  • 1
    You could use the command-line-args variable and only kill emacs if the -nw argument is not in the list
    – Tim X
    Commented Feb 14, 2015 at 7:24

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.