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

查看:17
本文介绍了在 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(反之亦然)从长远来看真的很方便,并使用以下内容进行翻译:

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.什么?

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)Multiple terminal,您也可以在这里阅读: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 显示器都是一个单独的图形终端 [...] 通过与 emacsclient 程序交互,Emacs 甚至可以连接到其他纯文本终端.

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-frame-functions 变量提供了一种解决方法.

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."
  (with-selected-frame (or frame (selected-frame))
    (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天全站免登陆