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

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

问题描述

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



谢谢

解决方案

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




x
Emacs正在使用X. / dd>
w32

Emacs使用本机MS-Windows GUI显示帧。

< Emacs使用Nextstep界面(在GNUstep和Mac OS X上使用)显示框架。

> pc
Emacs使用MS-DOS直接屏幕写入显示帧。

b>

Emacs在基于字符的终端上显示框架。



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



编辑:似乎窗口系统已被弃用,有利于 display-graphic-p (source:Ch f窗口系统RET在emacs 23.3.1上)

 (display-graphic-p&可选DISPLAY)

如果DISPLAY是graphi,则返回非零c显示。
图形显示是能够一次显示几个
框架和几种不同字体的显示器。对于使用窗口系统(如X)的显示器
,对于纯文本终端则为false。
DISPLAY可以是显示名称,框架或nil(意味着所选的
框架的显示)。

所以你想做的是:

 (if(display-graphic-p)
(progn
;;如果图形
(您的)
(代码))$



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

  ;;更可读:) 
(when(display-graphic-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天全站免登陆