3

I code in Erlang, and I dislike the default indentation style that erlang.el provides: it tends to push code way too far to the right for my likings.

I'd like to have a simple automatic indentation scheme: (1) pressing RET creates a newline with the same indentation level as the previous line; (2) pressing TAB moves the indentation level one level up.

I figured out (2) by adding (defalias 'erlang-indent-command 'tab-to-tab-stop) to my init.el, but I can't find a proper command to use for RET to solve (1).

Lindydancer
  • 6,095
  • 1
  • 13
  • 25

2 Answers2

3

Maybe something like this:

(defun newline-and-indent-same-level ()
  "Insert a newline, then indent to the same column as the current line."
  (interactive)
  (let ((col (save-excursion
               (back-to-indentation)
               (current-column))))
    (newline)
    (indent-to-column col)))
glucas
  • 20,175
  • 1
  • 51
  • 83
0

I think you are looking for newline-and-indent:

newline-and-indent is an interactive compiled Lisp function in ‘simple.el’.

(newline-and-indent)

Insert a newline, then indent according to major mode. Indentation is done using the value of ‘indent-line-function’. In programming language modes, this is the same as TAB. In some text modes, where TAB inserts a tab, this command indents to the column specified by the function ‘current-left-margin’.

Tyler
  • 21,719
  • 1
  • 52
  • 92