4

In my .emacs config file I have a following entry:

(custom-set-variables
  (custom-set-faces
    '(font-lock-comment-face ((((class color)
                                (min-colors 8)
                                (background dark))
                                (:foreground "red"))))))

This fixes the font color when TERM environment variable is set to screen, but breaks it when TERM is set to xterm. Is there a way to read value of TERM variable and execute that code only if TERM's value is screen? I found this questin slightly helpful, but still I don't know how to read values of environment variables in elisp.

Community
  • 1
  • 1
Jan Stolarek
  • 1,409
  • 1
  • 11
  • 21

2 Answers2

7

First I will answer what you asked, below I will answer the question you really should have asked ;)

I get the value of an environment variable you use the function getenv. For example:

(getenv "TERM")   ->  "xterm-color"

However, this is a relatively clumsy way to check if your Emacs run in the terminal. Instead you can use the following:

(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).

An older, deprecated, version is to check the variable window-system.

Lindydancer
  • 25,428
  • 4
  • 49
  • 68
6
(when (string= (getenv "TERM") "screen")
    .... your code
)
Alex Ott
  • 80,552
  • 8
  • 87
  • 132