在Emacs中编写
Scala代码时,我注意到以下缩进问题:
List(1,2,3).foreach{ x =>
然后按Enter键.
然后关闭括号,这就是最终发生的事情:
List(1,3).foreach{ x => }
虽然这是一个特殊示例,但在Emacs中自动缩进时,此问题会以多种方式出现.
对这两个问题中的任何一个问题的答案将不胜感激:
>如何解决这个问题,以便将支架放在适当的位置,并且支架内的任何东西都向右缩进一级?
>是否可以禁用这种类型的自动缩进(即像vi中的’set noautoindent’).我试过像这里建议的解决方案:Disable auto indent globally in Emacs没有成功.
提前致谢!
解决方法
我试图通过编辑scala-mode-indent.el文件来解决这个问题.它在某些其他情况下会缩进缩进,但至少你不会将所有这些缩进半屏向前移动.
注释掉这一行:
;; (scala-indentation-from-following)
并修改前面的scala-indentation:
(defun scala-indentation-from-preceding () ;; Return suggested indentation based on the preceding part of the ;; current expression. Return nil if indentation cannot be guessed. (save-excursion (scala-backward-spaces) (and (not (bobp)) (if (eq (char-Syntax (char-before)) ?\() (scala-block-indentation) (progn (when (eq (char-before) ?\)) (backward-sexp) (scala-backward-spaces)) t ;;(scala-looking-at-backward scala-expr-start-re) )) (if (scala-looking-at-backward scala-expr-start-re) (+ (current-indentation) scala-mode-indent:step) (current-indentation) ))))
正如我所说,在此之后它仍然存在.我计划很快写下更好的支持,也许一两周.
编辑:
如果要完全禁用scala缩进,请在scala-mode.el中注释掉该行
;; indent-line-function 'scala-indent-line