当我在终端模拟器中运行emacsclient时,我想调用一些函数。当Emacs在纯文本终端中启动时,我拥有的代码可以正常工作。当我在图形模式下启动Emacs并在终端中运行emacsclient -t时,这些函数不会运行,因此我不能在终端仿真器中使用鼠标。
下面是有问题的代码:
(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)这是一种奇怪的情况。Emacsclient连接到服务器并创建一个新框架,但是因为服务器在图形环境中运行,所以它报告window-system为"ns“,而在终端环境中报告为nil。因此,当我在终端中运行emacsclient -t时,鼠标报告启用功能无法运行。一旦emacsclient正在运行,如果我用C-x 5 2创建了一个新的框架,那么鼠标报告启用功能将会运行,因为窗口系统在该框架中将为零。
似乎在终端和窗口系统之间混帧时,window-system的值始终是Emacs服务器的值。
有没有一种方法可以在文本模式下以图形方式运行Emacs和emacsclient,并在那里运行鼠标功能?换句话说,有没有可能检测到正在创建的框架将在图形或文本环境中结束?
也许我应该在创建框架时始终运行这些函数,而不管window-system的值是什么
发布于 2011-10-02 07:16:14
诀窍是window-system和display-graphic-p现在是帧特定的。你需要在钩子函数中的那个框架中(看起来应该已经是这样了,但我不这么认为)。我必须在我的after-make-frame-functions钩子的开头添加这个(为了使窗口系统和显示图形-p行为正确):
(select-frame frame)https://stackoverflow.com/questions/7616761
复制相似问题