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

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

问题描述

在我的 .emacs 文件中,我有命令只有在图形模式下才有意义(如(set-frame-size )166 100))。我如何在图形模式下运行它们,而不是在终端模式下运行(即 emacs -nw )。



解决方案

窗口系统变量告诉Lisp程序什么窗口系统Emacs正在运行。可能的值为




x
Emacs正在使用X显示框架。 / dd>
w32

Emacs正在使用本机MS-Windows GUI显示框架。

< dt> ns
Emacs使用Nextstep接口显示帧(用于GNUstep和Mac OS X)。

pc

Emacs正在使用MS-DOS直接屏幕写入显示框架。

nil <


从< a href =http://www.gnu.org/software/emacs/manual/html_node/elisp/Window-Systems.html>文档。



编辑:似乎窗口系统已弃用,赞成 display-graphic-p on emacs 23.3.1)。

 (display-graphic-p& optional DISPLAY)

如果DISPLAY是图形显示,则返回非零。
图形显示器是能够同时显示多个
帧和几种不同字体的显示器。这对于使用诸如X的窗口系统的显示
是正确的,对于纯文本终端是false。
DISPLAY可以是显示名称,框架或nil(表示所选
框架的显示)。

所以你想做的是:

 (if(display-graphic-p)
(progn
;; if graphic
(your)
(code))
;; else(可选)
(您的)
(代码))

如果您没有else子句,则可以:

  ;;更易读:) 
(when(display-graphic-p)
(your)
(code))

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天全站免登陆