2012-04-17 61 views
2

如果当前emacs帧是X窗口还是终端,是否可以从elisp函数内检查?检查当前帧是否为X窗口的函数

我有一个最大化窗口的函数,它被设置为在创建新框架时运行。但是,当我打开仅终端会话时,每当创建新框架时都会收到错误消息。

我希望函数检查它是否是X窗口,否则不做任何事情。那可能吗?

为了记录在案,这里是当前功能:

(defun fullscreen (&optional f)  
    (interactive)      ;if called interactively, use current frame 
    (if f (select-frame f))   ;if called as hook, use new frame 
    (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 
        '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0)) 
    (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 
        '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0)) 
) 

回答

3

您可能看window-system功能。它接受一个帧可选参数(默认为当前帧)。或者,display-graphic-p更新(根据文档),并允许检查包含多个帧的整个显示。在你的榜样,你可以这样写:

(if (display-graphic-p) ...) 
0

您还可以使用framep' since its return value is defined (according to C-H˚Fframep`)为:

Return non-nil if OBJECT is a frame. 
Value is: 
    t for a termcap frame (a character-only terminal), 
'x' for an Emacs frame that is really an X window, 
'w32' for an Emacs frame that is a window on MS-Windows display, 
'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, 
'pc' for a direct-write MS-DOS frame. 
See also `frame-live-p'.