开发者

Emacs newline-and-indent in scala-mode

开发者 https://www.devze.com 2022-12-09 06:26 出处:网络
I have (global-set-key (kbd \"RET\") \'newline-and-indent) in my .emacs which works fi开发者_开发知识库ne in all modes but scala-mode(the newest, revision 19295 from svn).

I have (global-set-key (kbd "RET") 'newline-and-indent) in my .emacs which works fi开发者_开发知识库ne in all modes but scala-mode(the newest, revision 19295 from 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消