即使在终端中启动emacsclient,窗口系统也不是零 [英] even when emacsclient is started in a terminal, window-system is non-nil

查看:252
本文介绍了即使在终端中启动emacsclient,窗口系统也不是零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在终端仿真器中运行emacsclient时调用某些功能。当Emacs在纯文本终端中启动时,我的代码工作。当我以图形模式启动Emacs并在终端中运行 emacsclient -t 时,这些功能不会运行,所以我无法在终端模拟器中使用鼠标。



以下代码有问题:

 (defun my-terminal-config(& ;可选框)
为当前终端设置
(消息(格式%swindow-system)));;ns(Mac OS X)当Emacs以图形方式启动
(消息(格式%s(display-graphic-p)));;当Emacs以图形形式启动时为零
(除非(display-graphic-p)
;;启用鼠标报告对于终端仿真器
(xterm-mouse-mode 1)
(全局设置键[mouse-4]'(lambda()
(interactive)
(向下滚动1)))
(全局设置键[mouse-5]'(lambda()
(interactive)
(scroll-up 1)))))
add-hook'after-make-fr ame-functions'my-terminal-config)

这是一个奇怪的情况。 Emacsclient连接到服务器并创建一个新的框架,但是由于服务器在图形环境中运行,所以它将窗口系统报告为ns,而在终端环境中它将为零。因此,当我在终端中运行 emacsclient -t 时,鼠标报告启用功能不会运行。一旦emacsclient正在运行,如果我创建一个新的框架,使用 Cx 5 2 ,那么鼠标报告启用功能将会运行,因为窗口系统将在该帧中为零。 p>

似乎当在终端和窗口系统之间混合帧时, window-system 的值将始终为Emacs服务器。



有没有办法可以在文本模式下以图形和emacsclient方式运行Emacs,并将鼠标功能运行在那里?换句话说,是否可以检测到正在创建的框架将以图形或文本环境结束?



也许我应该总是在框架时运行这些功能无论 window-system 的值是否被创建?

解决方案

诀窍在于现在的框架是特定于 window-system display-graphic-p 。你需要在你的钩子功能的框架(似乎应该已经是这种情况,但我不认为)。我不得不在我的 after-make-frame-functions hook(使窗口系统和display-graphic-p的行为正确)的开头添加它:

 (选择框架)


I want to call some functions when I run emacsclient in a terminal emulator. The code I have works when Emacs is started in a text-only terminal. When I start Emacs in graphical mode and run emacsclient -t in a terminal, the functions do not run so I cannot use the mouse in the terminal emulator.

Here is the code in question:

(defun my-terminal-config (&optional frame)
  "Establish settings for the current terminal."
  (message (format "%s" window-system)) ;; "ns" (Mac OS X) when Emacs is started graphically
  (message (format "%s" (display-graphic-p))) ;; nil when Emacs is started graphically
  (unless (display-graphic-p)
    ;; enable mouse reporting for terminal emulators
    (xterm-mouse-mode 1)
    (global-set-key [mouse-4] '(lambda ()
                                 (interactive)
                                 (scroll-down 1)))
    (global-set-key [mouse-5] '(lambda ()
                                 (interactive)
                                 (scroll-up 1)))))
(add-hook 'after-make-frame-functions 'my-terminal-config)

This is a weird situation. Emacsclient connects to the server and creates a new frame, but because the server is running in a graphical environment, it reports window-system to be "ns" whereas in a terminal environment it would be nil. Therefore when I run emacsclient -t in a terminal, the mouse reporting enabling functions do not run. Once emacsclient is running, if I create a new frame with C-x 5 2, then the mouse reporting enabling functions will run because window-system will be nil in that frame.

It seems that when mixing frames between terminals and window systems, the value of window-system will always be that of the Emacs server.

Is there a way that I can run Emacs graphically and emacsclient in text mode and have the mouse functions run there? In other words, is it possible to detect that a frame being created will end up in a graphical or text environment?

Maybe I should simply always run those functions when a frame is created regardless of the value of window-system?

解决方案

the trick is that window-system and display-graphic-p are now frame specific. you need to be in that frame inside your hook function (seems like it should already be the case, but i don't think it is). i had to add this at the beginning of my after-make-frame-functions hook (to make window-system and display-graphic-p behave correctly):

(select-frame frame)

这篇关于即使在终端中启动emacsclient,窗口系统也不是零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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