C-h f keyboard-translate
RET说:
这个变量对每个终端都有一个单独的绑定。参见信息节点`(elisp)Multiple display'。
这为我们指明了正确的方向,尽管该文档中存在错误,因为引用的信息节点不存在。搜索表明该节点实际上已重命名(elisp)Multiple terminals
,您也可以在此处阅读:http ://www.gnu.org/s/emacs/manual/html_node/elisp/Multiple-Terminals.html
在 GNU 和 Unix 系统上,每个 X 显示器都是一个单独的图形终端 [...] Emacs 甚至可以通过与 emacsclient 程序交互连接到其他纯文本终端。
因此,当您将 emacs 作为守护程序启动时,您还没有连接到终端(或者至少没有连接到对您有用的终端),因此您的命令不会为您最终使用的终端生成绑定使用。
该after-make-frame-functions
变量提供了一种解决此问题的方法。
(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)
用来帮助解决这个问题)。