19

I am running emacs (24.5.1) on Mac osx and using the solarized theme. For the gui version, the theme works well. If I run the application with the -nw flag:

/Applications/Emacs.app/Contents/MacOS/Emacs -nw

the colors for the theme get all wonky. I assume this is because:

TERM=xterm-256color

What would I need to put in my .emacs to give the following conditional behavior:

if (gui)
  theme=solarized
if (-nw)
  theme=wheatgrass

??

3
  • I was tempted to tell you to write something like: (if (window-system) ...) Then, I read the documentation: > window-system is a variable defined in `C source code'. > Its value is nil 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
    – Nsukami _
    Jun 9, 2015 at 23:18
  • 1
    If you only need to know how to check if emacs is running in a gui or terminal then I believe this is a duplicate or this: emacs.stackexchange.com/questions/7151/… If you also need to know how to enable themes from elisp then I think it stands as it's own question nicely. If you need to know how to programmatically enable themes from elisp I would add that specifically to the body of your question. Jun 9, 2015 at 23:33
  • 2
    There are themes out there that look nice in both graphical and non-graphical environments. A alternative solution would be to use one such theme. Jun 9, 2015 at 23:34

1 Answer 1

31

Use display-graphic-p to determine if Emacs is in a GUI or not.

Assuming solarized is installed and loaded:

(if (display-graphic-p) 
    (enable-theme 'solarized) 
  (enable-theme 'wheatgrass))

See also: Is there a way to detect that emacs is running in a terminal?

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.