基于环境变量值的条件执行elisp代码

Jan*_*rek 2 emacs terminal elisp

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

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

这可以在TERM环境变量设置为时修复字体颜色screen,但在TERM设置为时将其中断xterm.有没有办法阅读的价值TERM变量和执行的代码只有当TERM的值screen?我发现这个questin略有帮助,但我仍然不知道如何在elisp中读取环境变量的值.

Lin*_*cer 7

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

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

(getenv "TERM")   ->  "xterm-color"
Run Code Online (Sandbox Code Playgroud)

但是,这是检查您的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).
Run Code Online (Sandbox Code Playgroud)

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


Ale*_*Ott 5

(when (string= (getenv "TERM") "screen")
    .... your code
)
Run Code Online (Sandbox Code Playgroud)