在Emacs中,使用守护程序/客户机在新框架上运行命令 [英] Run command on new frame with daemon/client in Emacs

查看:98
本文介绍了在Emacs中,使用守护程序/客户机在新框架上运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能很简单,但是我在谷歌搜索时没有发现任何有用的东西。所以这里是:)

This is perhaps quite simple, but I haven't found anything useful when googling. So here it goes :)

我在守护进程模式下使用Emacs( emacs --daemon ),它真的很方便。我也使用dvorak,并发现重新映射 Cj Cc (反之亦然)从长远来看非常方便,并使用以下内容进行翻译: p>

I use Emacs in daemon mode (emacs --daemon) and it's really handy. I also use dvorak and have found that remapping C-j to C-c (and vice versa) is really handy in the long run, and use the following for making that translation:

(keyboard-translate ?\C-j ?\C-c)
(keyboard-translate ?\C-c ?\C-j)

当使用Emacs作为守护进程当我启动一个新客户端(cli / gui)时,C-j 不再绑定到 C-c 。 Whaaat?

This works great when not using Emacs as a daemon. When I start a new client (cli/gui) C-j is no longer bound to C-c. Whaaat?

所以我想在创建一个新的客户端框架后,我需要运行 keyboard-translate 但我不知道该怎么做。我尝试过一个 defadvice 我发现某处,但无法使其工作,所以我放弃了并删除它。

So I guess I'll need to run the keyboard-translate after creating a new client frame, but I have no idea how to do it. I've tried with a defadvice I found somewhere, but couldn't make it work so I gave up and removed it.

推荐答案

Ch f keyboard-translate RET 说:


此变量对每个终端都有一个单独的绑定。请参阅信息节点
`(elisp)多个显示'。

This variable has a separate binding for each terminal. See Info node `(elisp)Multiple displays'.

这些指示我们正确的方向,虽然有一个错误在该文档中,引用的信息节点不存在。搜索表明节点实际上被重命名为(elisp)多个终端,您也可以在这里阅读: http://www.gnu.org/s/emacs/manual/html_node/elisp/Multiple-Terminals.html

which points us in the right direction, although there's an error in that documentation, as the referenced info node doesn't exist. A search suggests that the node is actually renamed (elisp)Multiple terminals, which you can also read here: http://www.gnu.org/s/emacs/manual/html_node/elisp/Multiple-Terminals.html


在GNU和Unix系统上,每个X显示都是一个单独的图形终端[...] Emacs甚至可以连接到其他文本 - 只有终端,通过与emacsclient程序交互。

On GNU and Unix systems, each X display is a separate graphical terminal [...] Emacs can even connect to other text-only terminals, by interacting with the emacsclient program.

所以当您启动emacs作为守护进程时,您尚未连接到终端(或至少不连接到终端对您有用),因此您的命令不会为您最终使用的终端生成绑定。

So when you start emacs as a daemon, you have not yet connected to a terminal (or at least, not to one that is useful to you), and so your commands do not generate bindings for the terminal(s) that you end up using.

after-make框架函数变量提供了一种解决方法。

The after-make-frame-functions variable provides one way to resolve this.

(defun my-dvorak-translations (&optional frame)
  "Re-map keys in the current terminal."
  (keyboard-translate ?\C-j ?\C-c)
  (keyboard-translate ?\C-c ?\C-j))
;; Evaluate both now (for non-daemon emacs) and upon frame creation
;; (for new terminals via emacsclient).
(my-dvorak-translations)
(add-hook 'after-make-frame-functions 'my-dvorak-translations)

在实验上,重复你的命令是安全的,所以我们不需要担心每个终端只执行一次(但是如果我们这样做,我们可以使用(get-device-terminal FRAME)来帮助)。

Experimentally it appears safe to repeat your commands, so we don't need to worry about only executing this once per terminal (but if we did, we could use (get-device-terminal FRAME) to help with that).

这篇关于在Emacs中,使用守护程序/客户机在新框架上运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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