Emacs中的Scala模式缩进

neq*_*ans 5 emacs scala indentation auto-indent

在Emacs中编写Scala代码时,我注意到以下缩进问题:

List(1,2,3).foreach{ x =>
Run Code Online (Sandbox Code Playgroud)

然后按Enter键.

然后关闭括号,这就是最终发生的事情:

List(1,2,3).foreach{ x =>
                  }
Run Code Online (Sandbox Code Playgroud)

虽然这是一个特殊示例,但在Emacs中自动缩进时,此问题会以多种方式出现.

对这两个问题中的任何一个问题的答案将不胜感激:

  1. 如何解决这个问题,以便将支架放在适当的位置,并且支架内的任何东西都向右缩进一级?

  2. 是否可以禁用这种类型的自动缩进(即像vi中的'set noautoindent').我尝试了像这里建议的解决方案:在Emacs中全局禁用自动缩进而没有成功.

提前致谢!

Rog*_*ach 2

尝试通过编辑 scala-mode-indent.el 文件来解决这个问题。在其他一些情况下,它会破坏缩进,但至少您不会将所有这些缩进半屏向前。

注释掉这一行:

;; (scala-indentation-from-following)
Run Code Online (Sandbox Code Playgroud)

并修改 scala-indentation-from-preceding:

(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)
    ))))
Run Code Online (Sandbox Code Playgroud)

正如我所说,在那之后它仍然是破碎的。我计划很快写一个更好的支持,也许在一两周内。

编辑:

如果你想完全禁用 scala 缩进,请注释掉 scala-mode.el 中的行

;; indent-line-function          'scala-indent-line
Run Code Online (Sandbox Code Playgroud)