[英]Cannot get to bind Enter to 'newline-and-indent in Emacs !!! Very annoying
无法在Emacs中将Enter绑定到newline-and-indent
!!! 很烦人。
通过将'mode'更改为ruby并且仍然没有,我已经尝试了以下线程中的所有内容:
我知道问题是RETURN键,因为如果我绑定其他东西,工作正常。 我试过[enter]
, (kbd "enter")
, (read-kbd-macro "enter")
, (kbd "RET")
后续行动1。
这是我从Ch k RET得到的
RET运行命令newline,这是一个交互式编译的Lisp函数。
它与RET绑定。
(换行和可选的ARG)
插入换行符,如果换行,则移动到新行的左边距。 如果
use-hard-newlines' is non-nil, the newline is marked with the text-property
hard'。 使用ARG,插入许多换行符。auto-fill-function' if the current column number is greater than the value of
fill-column'并且ARG为nil,auto-fill-function' if the current column number is greater than the value of
调用auto-fill-function' if the current column number is greater than the value of
。
我不知道该怎么做或如何弄清楚它是否是一个全局或局部绑定阻碍了它。 试图重新映射Cj也不起作用。
正如先前的评论所说,使用Ch k (describe-key)来查看当键没有按照你想要的那样被绑定时。 对于foo
describe-key引用它, (kbd "foo")
语法将是正确的。
您可能无法在相应的键盘映射中定义该键。
请注意,主要和次要模式键盘映射优先于全局键映射,因此如果覆盖全局绑定,则不一定会感到惊讶。
编辑:
我自己,我有一个钩子函数用于我使用的所有编程模式的常见行为,它包括你正在重新映射的那种。 相关部分如下所示:
(defun my-coding-config ()
(local-set-key (kbd "RET") (key-binding (kbd "M-j")))
(local-set-key (kbd "<S-return>") 'newline)
)
(mapc
(lambda (language-mode-hook)
(add-hook language-mode-hook 'my-coding-config))
'(cperl-mode-hook
css-mode-hook
emacs-lisp-mode-hook
;; etc...
))
请参阅Daimrod的答案,解释为什么我将RET重新绑定到Mj的当前绑定 - 尽管我使用的是comment-indent-new-line
(或类似)而不是newline-and-indent
(或类似) ,在评论和非评论中做我想要的。
在Emacs 24中,编程模式似乎来自prog-mode
,因此您可能 (未经测试)将该列表减少为prog-mode-hook
以及尚未执行此操作的第三方模式的任何异常。
如前所述,使用Ch k Cj,因为Cj是执行newline-and-indent
的标准键。
如果您打开一个新文件,请激活ruby-mode
并尝试上一个命令,您将看到它为什么不起作用。 因为ruby-mode
没有newline-and-indent
而是reindent-then-newline-and-indent
。 是的,这是愚蠢的,但你可以要求维护者改变它,或接受它。
但是我建议你使用Cj来做,因为ruby-mode
不是唯一这样做paredit-mode
,比如使用paredit-newline
paredit-mode
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.