When using haskell-mode (the Haskell layer) with evil-mode keybindings in spacemacs, the indentation created by pressing the o key is often incorrect.

For instance, imagine I want to write the following Haskell file:

module Foo where

foo :: Int
foo = 3

However, I've only written the following. I haven't yet created the function body for the foo function:

module Foo where

foo :: Int

If I am in insert mode and have my cursor after the "t" in Int and press Enter, the cursor goes to the next line in the first column, directly under the "f" in "foo". Using an underscore (_) for the cursor position, it looks like this:

module Foo where

foo :: Int

This is correct.

However, if I am in normal mode and have my cursor anywhere in the line with "foo" and press o, the cursor goes to then next line in the third column. It looks like this:

module Foo where

foo :: Int

This is incorrect. I have to press Backspace twice to put the cursor in the first column before I can start writing the definition of foo.

It seems like indentation rules are getting messed up. Why is the indentation different depending on whether Enter is pressed in insert mode, or o is pressed in normal mode?

How can I get o to indent the same as Enter in insert mode?

Here is my current .spacemacs config file. To my knowledge, I don't have any settings set that effect indentation.

edit: Just so my intentions are clear, I do want indentation to be happening when I press either Enter or o. But I want it to be the appropriate indentation. Currently, pressing o results in incorrect indentation.

  • Evil's o key inserts a newline and reindents, so the reason your Enter key doesn't behave the same way is either because you've disabled auto-indent or Spacemacs does weird things. I'm personally leaning towards the latter. Repro this without Spacemacs, then we'll talk. – wasamasa Sep 11 '17 at 7:05
  • @wasamasa What is it that you want to talk about? I'm a beginner with Spacemacs (and Emacs in general), and I'm not sure how to go about trying to reproduce this without Spacemacs. However, if someone sees this question and is already using haskell-mode with evil-mode, I'd be very interested in hearing whether the problem persists. I imagine you are probably right that it is a problem with Spacemacs. In this question, I'm asking about how I can fix this problem. – illabout Sep 11 '17 at 8:00
  • Why not running describe-key on your Enter and o keys, and seeing what commands are being run? In Spacemacs that would be SPC h k Enter and SPC h k o. You can then modify o so that it runs the same function as Enter. I don't know why you wouldn't want your code indented, though. – dangom Sep 11 '17 at 10:29
  • @dangom, sorry for the confusion about indentation. I do want my code indented when it is appropriate to do so. However, in my example, indenting two spaces after the type of foo is not appropriate. I've updated the question to make this more clear. – illabout Sep 11 '17 at 10:59
  • 1
    Try opening an issue at the Spacemacs GitHub issue tracker. – dangom Sep 11 '17 at 12:24

This appears to be a problem with the interaction between evil and haskell-mode.

Here are some relavent issues on the spacemacs and haskell-mode bug trackers:

Per a comment on the issue in the haskell-mode repository, here is a temporary fix for the "o" key. Put the following code into your ~/.spacemacs file:

(defun dotspacemacs/user-config ()
 (with-eval-after-load "haskell-mode"
    ;; This changes the evil "O" and "o" keys for haskell-mode to make sure that
    ;; indentation is done correctly. See
    ;; https://github.com/haskell/haskell-mode/issues/1265#issuecomment-252492026.
    (defun haskell-evil-open-above ()
      (evil-append-line nil))

    (defun haskell-evil-open-below ()
      (evil-append-line nil)

    (evil-define-key 'normal haskell-mode-map
      "o" 'haskell-evil-open-below
      "O" 'haskell-evil-open-above)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.