Scala indentation in Emacs mode

When writing Scala code in Emacs, I notice the following indentation problem:

List(1,2,3).foreach{ x =>

Then press enter.

Then close the bracket and this is what happens:

List(1,2,3).foreach{ x =>
                  }

Although this is one specific example, this problem occurs in various ways when autosaving in Emacs.

The answer to any of these two questions will be appreciated:

  • How can this problem be fixed so that the bracket is inserted in the right place and something inside the curly braces recedes one level to the right?

  • Is it possible to disable this type of auto-indexing (ie "set noautoindent" to vi). I have tried solutions like the ones suggested here: Disabling automatic indentation globally in Emacs without success.

Thanks in advance!

+5
source
2

, scala -mode-indent.el. , .

:

;; (scala-indentation-from-following)

scala --from-previous:

(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
+2

- 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)

(require 'besi) scala -mode.el.

github - besi

+4

All Articles