4

在我的.emacs配置文件中,我有以下条目:

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

TERM这会在环境变量设置为时修复字体颜色,但在设置为screen时会破坏它。有没有办法读取变量的值并仅在其值为时才执行该代码?我发现这个问题有点帮助,但我仍然不知道如何在 elisp 中读取环境变量的值。TERMxtermTERMTERMscreen

4

2 回答 2

7

首先我会回答你问的问题,下面我会回答你真正应该问的问题;)

我得到你使用函数的环境变量的值getenv。例如:

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

但是,这是检查 Emacs 是否在终端中运行的一种相对笨拙的方法。相反,您可以使用以下内容:

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

一个较旧的、已弃用的版本是检查变量window-system.

于 2012-11-04T16:17:10.260 回答
6
(when (string= (getenv "TERM") "screen")
    .... your code
)
于 2012-11-04T16:16:59.620 回答