Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run certain Emacs init commands only in GUI mode

Tags:

emacs

Is there a way to run certain commands (from init.el) only when I am in GUI mode and not in terminal mode. I want to set a certain color scheme when I run the GUI version, but that scheme screws up the terminal window's colors pretty badly. I'm looking for some variable/function which would look something like this:

(if gui-mode (color-scheme-blah))

or:

(unless terminal-mode (color-scheme-blah))
like image 426
auramo Avatar asked Jul 20 '10 14:07

auramo


3 Answers

You want something like

(if window-system (color-scheme-blah))

window-system can be 'x or 'mswindows or possibly even other values, but it's always nil when you are on a terminal.

like image 88
Kilian Foth Avatar answered Nov 05 '22 17:11

Kilian Foth


To generally test for a graphic display you want to use the following:

(display-graphic-p &optional DISPLAY)

It returns non-nil if DISPLAY is a graphic display. Using for example the window-system variable also works, but requires you to refer to a specific environment (such as X or Microsoft Windows).

like image 4
Markus Miller Avatar answered Nov 05 '22 19:11

Markus Miller


When using emacsclient and frames GUI or terminal mode is not necessarily a global concept. See the very useful answer to my question at https://superuser.com/questions/165335/how-can-i-show-the-emacs-menu-in-gui-emacs-frames-but-not-in-tty-frames-when-usin .

like image 1
Mike Crowe Avatar answered Nov 05 '22 18:11

Mike Crowe