不能绑定输入到Emacs中的newline-and-indent!很烦人 [英] Cannot get to bind Enter to 'newline-and-indent in Emacs !!! Very annoying

查看:130
本文介绍了不能绑定输入到Emacs中的newline-and-indent!很烦人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Emacs中无法绑定到 newline-and-indent 中的输入!非常烦人。



我已经尝试通过将模式更改为红宝石,仍然没有任何内容的以下内容:



如何使Emacs自动缩进我的C代码?



我知道问题是 RETURN 键,因为如果我绑定到别的东西,工作正常。
我试过 [enter] (kbdenter) read-kbd-macroenter)(kbdRET)






跟进1。



这是我从 Ch k RET


RET运行命令换行符,它是一个交互式编译的Lisp
功能。



必须是RET。



(换行和可选ARG)



插入换行符,如果为空,则移动到新行的左边距。
如果 use-hard-newlines'不为零,则换行符标有
text-property
hard'。
用ARG插入许多换行符。
如果当前列号比$ / code> fill-column的值更大
,则调用 auto-fill-function',而ARG为nil。 p>

我不知道该怎么做,或者如何弄清楚它是一个全局的
或本地绑定, 。尝试重新映射 Cj
也无效。

解决方案

使用 Ch k (describe-key)来查看当它不做你想要的时候键被绑定到什么。 (kbdfoo)语法对于 foo describe-key指定为

可能您根本没有在适当的键盘映射中定义该键。



请注意,主要和次要模式键盘映射优先于全局键盘映射,所以如果覆盖全局绑定,您不一定会感到惊讶。



编辑:



我自己,我有一个钩子功能,用于我使用的所有编程模式的常见行为,它包括您重新映射的类型。相关部分如下所示:

 (defun my-coding-config()
(本地设置键(kbdRET)(key-binding(kbdMj)))
(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 ...
))
/ pre>

请参阅Daimrod的回答,说明为什么我将 RET 重新绑定到当前绑定的 Mj < kbd> - 虽然我使用 comment-indent-new-line (或类似的)而不是 newline-and-indent (或类似的),这在我的意见和非评论中都是这样做的。



在Emacs 24中,编程模式似乎来源于 prog-mode ,所以你可以可能(未经测试)将该列表减少到 prog-mode-hook 加上第三方的任何例外尚未这样做的模式。


Cannot get to bind Enter to newline-and-indent in Emacs !!! Very annoying.

I already tried everything on the following thread by changing 'mode' to ruby and still nothing:

How do I make Emacs auto-indent my C code?

I know that the problem is the RETURN key, since if I bind to something else, works fine. I tried [enter], (kbd "enter"), (read-kbd-macro "enter"), (kbd "RET")


Follow-up 1.

This is what I get from C-hkRET

RET runs the command newline, which is an interactive compiled Lisp function.

It is bound to RET.

(newline &optional ARG)

Insert a newline, and move to left margin of the new line if it's blank. If use-hard-newlines' is non-nil, the newline is marked with the text-propertyhard'. With ARG, insert that many newlines. Call auto-fill-function' if the current column number is greater than the value offill-column' and ARG is nil.

I dont know what to make of it or how to figure out if it's a global or local binding that gets in the way. trying to remap C-j also doesnt work.

解决方案

As a previous comment says, use C-h k (describe-key) to see what the key is bound to at the point when it's not doing what you want. The (kbd "foo") syntax will be correct for whichever foo describe-key refers to it as.

Chances are that you are simply not defining that key in the appropriate keymap.

Note that major and minor mode keymaps take precedence over the global keymap, so you shouldn't necessarily be surprised if a global binding is overridden.

edit:

Myself, I have a hook function for common behaviours for all the programming modes I use, and it includes the sort of remapping you're after. The relevant part looks like this:

(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...
   ))

See Daimrod's answer for the explanation of why I'm re-binding RET to the current binding of M-j -- although I'm using comment-indent-new-line (or similar) instead of newline-and-indent (or similar), which does what I want in both comments and non-comments.

In Emacs 24, programming modes seem to derive from prog-mode, so you could probably (un-tested) reduce that list to prog-mode-hook plus any exceptions for third-party modes which don't yet do that.

这篇关于不能绑定输入到Emacs中的newline-and-indent!很烦人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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