如何检测 emacs 处于终端模式? [英] How to detect that emacs is in terminal-mode?

查看:40
本文介绍了如何检测 emacs 处于终端模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 .emacs 文件中,我有一些只在图形模式下有意义的命令(比如 (set-frame-size (selected-frame) 166 100)).如何仅在图形模式而不是终端模式下运行这些(即 emacs -nw).

谢谢!

解决方案

window-system 变量告诉 Lisp 程序 Emacs 在什么窗口系统下运行.可能的值是

x
Emacs 正在使用 X 显示框架.
w32
Emacs 使用本机 MS-Windows GUI 显示框架.
ns
Emacs 使用 Nextstep 界面(在 GNUstep 和 Mac OS X 上使用)显示框架.
电脑
Emacs 正在使用 MS-DOS 直接屏幕写入显示框架.
Emacs 正在基于字符的终端上显示框架.

来自文档.>

编辑:似乎不推荐使用窗口系统,取而代之的是 display-graphic-p(来源:emacs 23.3.1 上的 Ch f 窗口系统 RET).

(display-graphic-p &optional DISPLAY)如果 DISPLAY 是图形显示,则返回非零值.图形显示是那些能够显示多个框架和几种不同的字体一次.这适用于显示器使用诸如 X 之类的窗口系统,而对于纯文本终端则使用 false.DISPLAY 可以是显示名称、框架或 nil(表示选定的帧的显示).

所以你想做的是:

(if (display-graphic-p)(程序;;如果图形(你的)(代码));;其他(可选)(你的)(代码))

如果你没有 else 子句,你可以:

<代码>;;更具可读性:)(当(显示图形-p)(你的)(代码))

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

x
Emacs is displaying the frame using X.
w32
Emacs is displaying the frame using native MS-Windows GUI.
ns
Emacs is displaying the frame using the Nextstep interface (used on GNUstep and Mac OS X).
pc
Emacs is displaying the frame using MS-DOS direct screen writes.
nil
Emacs is displaying the frame on a character-based terminal.

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

这篇关于如何检测 emacs 处于终端模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆