Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annoying indentation behaviour when declaring data types #1081

Closed
jstolarek opened this issue Jan 14, 2016 · 5 comments
Closed

Annoying indentation behaviour when declaring data types #1081

jstolarek opened this issue Jan 14, 2016 · 5 comments

Comments

@jstolarek
Copy link

Say I have this code:

foo = undefinedX

where X is the cursor position. If I press Enter twice the cursor ends up at the beginning of a new line:

foo = undefined

X

This is all fine. Now consider a similar situation with data type declaration:

data Foo = Bar
         | BazX

Now pressing Enter twice yields:

data Foo = Bar
         | Baz

           X

This is mostly annoying. If I press Enter twice after a data constructor declaration then I almost certainly want to start some new declaration and thus expect the cursor to be placed at the beginning of a new line. So the rule should be: when pressing enter on a line that contains only whitespace characters place the cursor at the beginning of a new line. Note also that current behaviour is inconsistent:

data Foo = BarX

Pressing Enter here will place the cursor at the beginning of a new line, but I would really expect it to be placed under =:

data Foo = Bar
         X

Only when I press enter for the second time I want the cursor to be placed at the beginning of a new line.

@gracjan
Copy link
Contributor

gracjan commented Jan 14, 2016

I'm really grateful for these reports. Keep those coming. We will fix as soon as possible. Thanks again.

@jstolarek
Copy link
Author

I thought a bit more about this and I think that pressing Enter in this situation:

data Foo = BarX

should yield:

data Foo = Bar
               X

that is assume by default that I will be writing arguments of Bar. In this example this doesn't look good, but it seems to make sense in general. For example:

data Foo = Bar Int Char
               X

It would be nice if entering a vertical bar in the setting above was detected and indentation corrected automatically to:

data Foo = Bar Int Char
         | X

Note the space already inserted after the |. Also, in this setting:

data Foo = Bar Int Char
               X

I would expect that repeatedly pressing Tab will cycle me between four indentations:

data Foo = Bar Int Char
X        Y Z   Q

Currently I am cycled only between X and Z.

@gracjan
Copy link
Contributor

gracjan commented Jan 15, 2016

Electric behavior for bar comma semicolon is in the plans. Hard to say when we will have energy to do this.

@gracjan
Copy link
Contributor

gracjan commented Jan 23, 2016

Note that haskell-indent behaves the same when electric-indent-mode is enabled. Logic what should happen after ENTER is pressed is here:

https://github.com/haskell/haskell-mode/blob/master/haskell-indentation.el#L188

@gracjan
Copy link
Contributor

gracjan commented Jan 27, 2016

This is a duplicate of #747.

@gracjan gracjan closed this as completed Jan 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants