gpt4 book ai didi

node.js - Emacs - 加载模块后绑定(bind)键

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:07 26 4
gpt4 key购买 nike

我想为 emacs 设置 Node.js 键绑定(bind) REPL。我看了一下nodejs-repl ,我现在可以打开 REPL 并使用 nodejs-send-region执行代码的命令。

但是我无法弄清楚如何将例如 C-c C-e 绑定(bind)到此命令。我认为我必须使用 comint-mode 来实现 (?) 。我尝试过:

(require 'nodejs-repl)

;; bind shortcuts when in node mode-line
(eval-after-load 'nodejs-repl
(lambda () (local-set-key (kbd "C-c C-e") #'nodejs-repl-send-region)))

最佳答案

加载库后,您将绑定(bind)当前本地键映射中的键。加载库很可能不会打开您真正想要绑定(bind)按键的键盘映射的模式。至少这是典型的,它对应于 GNU Emacs coding conventions ,其中说:

Simply loading a package should not change Emacs’s editing behavior. Include a command or commands to enable and disable the feature, or to invoke it.

This convention is mandatory for any file that includes custom definitions. If fixing such a file to follow this convention requires an incompatible change, go ahead and make the incompatible change; don’t postpone it.

您想要做的是使用 define-key 将键绑定(bind)到正确的键盘映射中,并且您希望在模式 Hook 中执行此操作。

(require 'nodejs-repl)
(define-key nodejs-repl-mode-map (kbd "C-c C-e") #'nodejs-repl-send-region)

关于node.js - Emacs - 加载模块后绑定(bind)键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34840579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com