I want a single .emacs but one that branches depending on whether -nw was in the argument list. (open in terminal [no window mode])

I.e, in gui mode I'd like all my usual features. In terminal I want it to load only the bare necessities for fast loading.

I looked at the command-line-args variable, but that var doesn't have flags.

Alternativley I've been considering not loading my regular init and load a custom terminal instead:
emacs -q -l "terminal_Config.el"
But if possible, I'd prefer to be able to tell if -nw was specified.


Check the variable window-system or the function display-graphic-p. Either will give you nil if you run Emacs with -nw.


window-system is a variable defined in `C source code'. Its value is x It is a terminal-local variable; global value is the same.

Documentation: Name of window system through which the selected frame is displayed. The value is a symbol: nil for a termcap frame (a character-only terminal), 'x' for an Emacs frame that is really an X window, 'w32' for an Emacs frame that is a window on MS-Windows display, 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, 'pc' for a direct-write MS-DOS frame.

Use of this variable as a boolean is deprecated. Instead, use display-graphic-p' or any of the otherdisplay-*-p' predicates which report frame's specific UI-related capabilities.


(display-graphic-p &optional DISPLAY)

Return non-nil if DISPLAY is a graphic display. Graphical displays are those which are capable of displaying several frames and several different fonts at once. This is true for displays that use a window system such as X, and false for text-only terminals. DISPLAY can be a display name, a frame, or nil (meaning the selected frame's display).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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