Emacs 中的 Scala 模式缩进
在 Emacs 中编写 Scala 代码时,我注意到以下缩进问题:
List(1,2,3).foreach{ x =>
然后按 Enter。
然后关闭括号,这就是最终发生的情况:
List(1,2,3).foreach{ x =>
}
虽然这是一个特定的示例,但在 Emacs 中自动缩进时,此问题会以多种方式出现。
回答这两个问题中的任何一个,我们将不胜感激:
如何解决此问题,以便将大括号放在正确的位置,并且大括号内的任何内容都向右缩进一层?
是否可以禁用这种类型的自动缩进(即像 vi 中的“set noautoindent”)。我尝试了像这里建议的解决方案: Disable auto indent global in Emacs without成功。
提前致谢!
When writing Scala code in Emacs, I notice the following indentation issue:
List(1,2,3).foreach{ x =>
Then press enter.
Then close the bracket, and this is what ends up happening:
List(1,2,3).foreach{ x =>
}
Although this is one particular example, this issue appears in a variety of ways when auto-indenting in Emacs.
An answer to either of these two questions would be appreciated:
How can this issue be fixed so that the brace gets put in the proper place and anything within the braces is indented one level to the right?
Is it possible to disable this type of auto-indentation (i.e. like 'set noautoindent' in vi). I tried solutions like the ones suggested here: Disable auto indent globally in Emacs without success.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我编写了一段简单的代码 - 它使 emacs 在大多数情况下保持缩进级别,并在前一个非空行以“{”、“(”、“>”结束时向右缩进两个空格, 同时添加
将文件 besi.el 添加到您的加载路径。
编辑 scala-mode.el 中的行
和 scala-mode-ui.el 中的行。
一行
(require 'besi)
到开始scala-mode.el。将其上传到 github 以方便参考 - besi
I've coded up a simple piece of code - it makes emacs keep indent level for most time, and indents two spaces to the right when the previous non-empty line ends with "{", "(", ">", "=".
Add file besi.el to your load path.
Edit line in scala-mode.el
and line in scala-mode-ui.el
Also add a line
(require 'besi)
to the start of scala-mode.el.Uploaded it to github for easy reference - besi
我尝试通过编辑 scala-mode-indent.el 文件来解决这个问题。在其他一些情况下,它会破坏缩进,但至少您不会将所有这些缩进半屏向前。
注释掉这一行:
并修改 scala-indentation-from-preceding:
正如我所说,此后它仍然损坏。我计划很快写一个更好的支持,也许在一两周内。
编辑:
如果你想完全禁用 scala 缩进,请注释掉 scala-mode.el 中的行
I tried to solve this by editing scala-mode-indent.el file. It breaks indent in some of the other situations, but at least you will not have all those indents half-screen forward.
Comment out this line:
And modify scala-indentation-from-preceding:
As I said, it still remains broken after that. I plan to write a better support shortly, maybe in a week or two.
EDIT:
If you want to disable scala indentation completely, comment out the line in scala-mode.el