14

I have some items in my .emacs that I don't want to run if I ran emacs -nw. How can I tell in elisp if that is the case?

(edited to change -nox to -nw --- where was my brain?)

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
JasonFruit
  • 7,764
  • 5
  • 46
  • 61

3 Answers3

15

Your answer above is correct, although if you want to differentiate between other window systems and only want to run the code if you are actually using X, you'd have to go

(if (eq window-system 'X) (foo))
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Nathaniel Flath
  • 15,477
  • 19
  • 69
  • 94
  • Though I don't need that kind of specificity, that's a better answer than mine. Thanks! – JasonFruit May 28 '09 at 21:09
  • 2
    When I was trying to figure out how to disable theming in window only mode, I ended up going with JasonFruit's initial answer, but they're really getting at the same thing. `(if (eq window-system 'X) (foo))` or `(if window-system (foo))` or `(when window-system (foo))` it doesn't really make a difference. For those interested in the details, just let me tell you "C-h a" is your friend. Using it I searched "variable" and found 'describe-variable and using that plus tab-completion i found the window-system variable. Then I just typed `window-system` into the scratch buffer and then tested it – Jeremy Grozavescu May 29 '09 at 00:19
  • 3
    They will work the same if all you care about is if the window system is X or not, but window-system's value can be a value other than 'X. – Nathaniel Flath May 29 '09 at 04:27
14

I think I found my own answer:

(when window-system
    (foo))

will only foo when I'm running in X.

JasonFruit
  • 7,764
  • 5
  • 46
  • 61
  • Please stop voting up my own answer to my question --- the one I accepted above is essentially the same, but more complete! – JasonFruit Sep 11 '09 at 13:19
  • @JasonFruit it's probably people looking for a more general windowing system detection solution. However, per the docs: "Use of this variable [window-system] as a boolean is deprecated. Instead, use `display-graphic-p` or any of the other `display-*-p` predicates which report frame's specific UI-related capabilities." – Nick Frezynski Jul 26 '15 at 07:11
3

Note that the question is somewhat ill-conceived: Emacs can run with both tty frames and GUI frames at the very same time.

The window-system variable is "terminal-local" which means that its value will depend on whether the currently selected frame is a tty frame or GUI frame.

Stefan
  • 27,908
  • 4
  • 53
  • 82