简体   繁体   English

在scala模式下使用Emacs换行符和缩进符

[英]Emacs newline-and-indent in scala-mode

I have (global-set-key (kbd "RET") 'newline-and-indent) in my .emacs which works fine in all modes but scala-mode(the newest, revision 19295 from svn). 我的.emacs中有(global-set-key (kbd "RET") 'newline-and-indent)符号(global-set-key (kbd "RET") 'newline-and-indent) ,它在所有模式下工作正常,但scala-mode(最新版本,修订版19295来自svn)。

What do I need to change to get it working? 我需要做些什么才能让它发挥作用?

(add-hook 'scala-mode-hook
      (lambda () (local-set-key (kbd "RET") 'reindent-then-newline-and-indent)))

The above somewhat fixes the problem. 以上有点解决了这个问题。 It now indents the line correctly after pressing Enter once, but still doesn't work if there is a blank line above the newline. 它现在按Enter键后正确缩进行,但如果换行符上方有一个空行仍然无效。

In scala-mode, "RET" is bound to scala-newline by default, and this overrides the global key binding set with global-set-key , hence the need for the hook specific to scala-mode. 在scala-mode中,默认情况下“RET”绑定到scala-newline,这将覆盖使用global-set-key的全局键绑定集,因此需要特定于scala-mode的挂钩。 Consider using: 考虑使用:

(add-hook 'scala-mode-hook
      (lambda () (local-set-key (kbd "RET") 'newline-and-indent)))

instead of: 代替:

(add-hook 'scala-mode-hook
      (lambda () (local-set-key (kbd "RET") 'reindent-then-newline-and-indent)))

If you don't want Emacs to change your indentation after leaving a line. 如果您不希望Emacs在离开线后更改缩进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM