当我在终端模拟器中运行 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 连接到服务器并创建一个新框架,但由于服务器在图形环境中运行,它报告窗口系统为“ns”,而在终端环境中则为 nil。因此,当我emacsclient -t
在终端中运行时,鼠标报告启用功能不会运行。一旦 emacsclient 运行,如果我创建一个带有 的新框架C-x 5 2
,则鼠标报告启用功能将运行,因为该框架中的窗口系统将为零。
似乎在终端和窗口系统之间混合帧时, 的值window-system
将始终是 Emacs 服务器的值。
有没有一种方法可以让我以图形方式运行 Emacs 并在文本模式下运行 emacsclient 并让鼠标功能在那里运行?换句话说,是否有可能检测到正在创建的框架最终会出现在图形或文本环境中?
也许我应该在创建框架时始终运行这些函数,而不管window-system
?