[英]Scala mode indentation in Emacs
在Emacs中编写Scala代码时,我注意到以下缩进问题:
List(1,2,3).foreach{ x =>
然后按Enter。
然后合上支架,结果就是这样:
List(1,2,3).foreach{ x =>
}
尽管这是一个特定的示例,但是在Emacs中自动缩进时,会以多种方式出现此问题。
对于以下两个问题之一的回答将不胜感激:
如何解决此问题,以使支架放置在正确的位置,并且支架内的所有东西都向右缩进一层?
是否可以禁用这种类型的自动缩进(如vi中的'set noautoindent')。 我尝试了以下建议的解决方案: 在Emacs中全局禁用自动缩进,但没有成功。
提前致谢!
我已经编写了一段简单的代码-它使emacs在大多数时间都保持缩进级别,并在前一个非空行以“ {”,“(”,“>”,“ =“。
将文件besi.el添加到您的加载路径。
(provide 'besi)
(defun besi-indent-line ()
"Indent current line"
(interactive)
(scala-indent-line-to (besi-indent)))
(defun besi-indent ()
(save-excursion
(forward-comment -100000)
(backward-char 1)
(if (or (looking-at "{") (looking-at "=") (looking-at ">") (looking-at "("))
(+ (current-indentation) 2)
(current-indentation))))
(defun besi-newline ()
(interactive)
(newline-and-indent))
在scala-mode.el中编辑行
indent-line-function 'besi-indent-line
并在scala-mode-ui.el中行
("\r" 'besi-newline)
还要在scala-mode.el的开头添加一行(require 'besi)
。
将其上传到github以便于参考-besi
我试图通过编辑scala-mode-indent.el文件来解决此问题。 在某些其他情况下,它会打破缩进,但至少您不会让所有缩进都进入半屏显示状态。
注释掉这一行:
;; (scala-indentation-from-following)
并从前面修改scala缩进:
(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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.