簡體   English   中英

Emacs Scala模式換行和縮進怪異

[英]Emacs scala-mode newline-and-indent weirdness

我在Scala模式下(來自Scala 2.8軟件包)在Emacs中具有以下代碼:

object t1 {
  def main (args: List[String]) = {
    println("Hello")
  }
}

我還將返回鍵設置為newline-and-indent 當我在最后一個花括號之后反復按回車鍵時,它會轉到最左邊的空白行。 當我再次按回車鍵時,它會縮進兩個空格。 然后,此后它將保持此縮進狀態。 顯然,它不應該這樣做。

但是,當我反復通過Mx運行newline-and-indent並鍵入newline-and-indent ,我沒有得到兩個空格的縮進。 reindent-then-newline-and-indent

為什么會有這種差異?

您的問題源於您反彈enter newline-and-indent的事實,當使用scala-mode時,這似乎並不是慣用的。 newline-and-indent最終調用indent-according-to-mode ,它檢查一些不需要的設置,並在必要時解決它們,如果一切正常,最終調用indent-line-function ,它是一個緩沖區局部變量。

由於這是特定於模式的,因此模式定義了自己的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))))

有趣的是,它每次都檢測到重復的調用和縮進。 使用Mx時, last-command不是scala-indent-line ,而是execute-extended-command 因此,當使用Mx時,它將繼續以正確的縮進級別縮進。 但是,當綁定到某個鍵時,它會注意到它是在先前立即執行的,並且縮進了一個額外的級別。

效果不是累積的...我認為這是由於在函數末尾設置了奇數命令,該命令最初使行縮進,但隨后使用(scala-indentation)檢查正確的縮進並相應地縮進。

我不是100%對此,但是乍一看似乎就是這樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM