Caveat: I'm not a Haskell user, so take this with a grain of salt.
When you press RET after the Hello
, Emacs doesn't know you're going to add a |
(quick search shows you can have other symbols). The Haskell folks have deemed the proper indentation to be lined up directly below the H
in Hello
. If the indentation were to automatically line up with the |
on the line above, then all the cases where you don't type a |
will result in improper indentation. Damned if you do, damned if you don't...
Other programming modes (C/C++, Lisp, Tcl, ...) have the same problem - they cannot know ahead of time what you're going to put on the next line, so the indentation my not be what you'd hoped for.
One solution is to use "electric" keys, which is to say that they insert characters and also force re-indentation. You could easily define | to be electric with the following code:
(defun haskell-electric-| ()
"it's electric! (insert | and indent as long as the | follows whitespace)"
(interactive)
(insert "|")
(if (string-match-p "^\\s-*|" (buffer-substring (line-beginning-position)
(point)))
(haskell-indentation-indent-line)))
(define-key haskell-mode-map "|" 'haskell-electric-|)
I added a check to ensure that the |
inserted is preceded by only whitespace, you can customize that however you want or remove the check altogether.
I presume there might also be other symbols in Haskell that would be worth making electric.
case
case is correct behavior. - jrockway|
yet, it doesn't. So I have to type something in the line before pressing tab - Valentin Golev