In my .emacs
file, I have commands that only makes sense in graphical mode (like (set-frame-size (selected-frame) 166 100)
). How do I run these only in graphical mode and not in terminal mode (i.e. emacs -nw
).
Thanks!
The window-system
variable tells Lisp programs what window system Emacs is running under. The possible values are
From the doc.
Edit: it seems that window-system is deprecated in favor of display-graphic-p
(source: C-h f window-system RET on emacs 23.3.1).
(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).
So what you want to do is :
(if (display-graphic-p)
(progn
;; if graphic
(your)
(code))
;; else (optional)
(your)
(code))
And if you don't have an else clause, you can just:
;; more readable :)
(when (display-graphic-p)
(your)
(code))