Emacs scala-mode newline-and-indent weirdness
我在
scala-mode下的Emacs中有以下代码(来自
Scala 2.8包):
object t1 { def main (args: List[String]) = { println("Hello") } } 我还将我的返回键设置为换行符.当我在最后一个括号后反复点击返回时,它会转到最左边的一列空行.当我再次按下返回时,它会缩进两个空格.然后它停留在这个缩进处.显然它不应该这样做. 但是,当我通过M-x反复运行newline-and-indent并输入newline-and-indent时,我没有得到两个空格的缩进.同样适用于reindent-then-newline-and-indent. 为什么会出现这种差异? 解决方法
你的问题源于你反弹进入换行和缩进的事实,这在使用scala-mode时似乎不是惯用的. newline-and-indent最终调用indent-to-to-mode,它检查一些不需要的设置,必要时绕过它们,如果一切正常,最后调用indent-line-function,这是一个缓冲局部变量.
由于这是模式特定的,因此模式定义了它们自己的缩进线功能.大多数都有相当一致的行为,但Scala的功能是scala-indent-line,如下所示: (defun scala-indent-line () "Indent current line as smartly as possible. When called repeatedly,indent each time one stop further on the right." (interactive) (if (or (eq last-command this-command) (eq last-command 'scala-undent-line)) (scala-indent-line-to (+ (current-indentation) scala-mode-indent:step)) (let ((indentation (scala-indentation))) (scala-indent-line-to indentation)))) 有趣的是,它每次都会检测到重复的调用和缩进.使用M-x时,last-command不是scala-indent-line,而是execute-extended-command.因此,当使用M-x时,它会继续缩进到正确的缩进级别.但是,当绑定到某个键时,它会注意到它之前已立即执行并缩进了一个额外的级别. 效果不是累积的…我认为这是因为函数末尾的奇数命令设置,最初缩进该行,但随后用(scala-indentation)检查正确的缩进并相应地缩进. 我不是百分之百,但初看起来似乎正在发生的事情. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |