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

Bad indentation on space #73

Open
osa1 opened this issue Aug 5, 2016 · 21 comments
Open

Bad indentation on space #73

osa1 opened this issue Aug 5, 2016 · 21 comments

Comments

@osa1
Copy link
Member

osa1 commented Aug 5, 2016

I'm collecting some problems with the indentation here, with examples.


  • Enter a comment. Make sure the comment ends with character .. E.g. something like -- | This is a function.
  • Move the the next line. -- will be automatically added. Remove those.
  • Type a symbol and then space. E.g. fun. The line will be indented. Final code will look like:
-- | This is a function.
  fun  -- this shouldn't be indented

In this code:

data Test = Test
  { x :: {-# UNPACK #-} !Int
  , y :: Int
  }

I want to unpack y too, so I move the cursor right before Int and type {-#. At this point when I add a space the line gets indented like this:

data Test = Test
  { x :: {-# UNPACK #-} !Int
         , y :: {-# _Int
  }

(_ indicates the cursor)

The line isn't indented back after the pragma is completely added:

data Test = Test
  { x :: {-# UNPACK #-} !Int
         , y :: {-# UNPACK #-} !Int
  }

Suppose I have this:

main :: IO ()
main = do
      -- blah blah blah
    line1
    line2
    line3

I want to comment-out line1 and line2, so I move my cursor to the beginning of line1 and switch to vertical insert mode, selecting the l column of line1 and line2, switching to insert mode with I and typing --. Once I insert that last space, things get indented and I get this:

main :: IO ()
main = do
      -- blah blah blah
      -- line1
    li-- line2
    line3

This is a bit hard to explain, so I recorded it here https://asciinema.org/a/5h44shozwdzmla82t6a8nqvn2


(more will come here)

@osa1 osa1 changed the title Indentation is completely broken Bad indentation on space Aug 5, 2016
raichoo added a commit that referenced this issue Aug 5, 2016
@raichoo
Copy link
Member

raichoo commented Aug 5, 2016

I'm planning to collect examples where the indenter does things one does not expect in this thread. Additionally I'm going to push fixes to the branch indentation. Indenting is hard and very brittle, I'm thankful for edge cases where things fall apart since I can only check if it's behaving correctly for the code I write.

@osa1
Copy link
Member Author

osa1 commented Aug 6, 2016

(I haven't tried the indentation branch yet, but I added one more example here because it looked quite different than the first example)

EDIT: Added one more example.

@raichoo
Copy link
Member

raichoo commented Aug 11, 2016

Thanks a lot, it looks like I didn't handle the pragmas and block comments correctly when checking for nesting. I've pushed another fix on the indentation branch that should deal with these. Please give them a try and tell me if that fixes the issue for this case.

@raichoo
Copy link
Member

raichoo commented Aug 11, 2016

I'm afraid I don't understand the comment indentation example. You start with a somewhat unusual example:

main :: IO ()
main = do
      -- blah blah blah <- why is this indented at all?
      -- line1
    li-- line2
    line3

The indenter aligns by looking at the previous line is you indent that it will use that line to do the indentation. Can you describe what kind of effect you would like the have under which circumstances?

@osa1
Copy link
Member Author

osa1 commented Aug 11, 2016

I just tried indentation branch and it works great, thanks!

About the unusual example: In the code base I'm working on we have all kinds of crazy coding styles and things are very inconsistent. We don't have exactly that function, but we have similarly indented comment blocks followed by de-indented code blocks and haskell-vim tries to indent the code blocks in these cases.

But I agree that it's unusual and maybe we can just ignore that.

@raichoo
Copy link
Member

raichoo commented Aug 11, 2016

No problem. Thanks for bringing these issues to my attention. If you find anything or have an idea how we can support more unusual indentation styles without breaking things and without diminishing convenience just let me know. I will leave this issue open for a while just in case you find something else that bothers you :)

@raichoo
Copy link
Member

raichoo commented Aug 11, 2016

By the way, these changes are now on master.

@mitchellwrosen
Copy link

mitchellwrosen commented Aug 22, 2016

I ran into a similar case:

foo =
  { field = bar "("
  }

... insert a comma directly below the {...

foo =
  { field = bar "("
                 ,
  }

... and it jumps forward, beneath the (.

Is this also covered by the changes you made in indendation?

raichoo added a commit that referenced this issue Aug 23, 2016
@raichoo
Copy link
Member

raichoo commented Aug 23, 2016

I have pushed a change onto the indentation branch that should deal with this. Can you check if this fixes your problem and maybe take a shallow look if something else breaks because of this?

@mitchellwrosen
Copy link

Sure, but I'm (embarrassingly) not exactly sure how to test the changes. I use vundle to manage my vim packages and I don't believe there's any support for pointing at a particular branch/commit hash. It just downloads master/HEAD.

@raichoo
Copy link
Member

raichoo commented Aug 23, 2016

Doesn't vundle keep git repos of the plugins? If so you could simply fetch the branch and check it out manually.

@mitchellwrosen
Copy link

Ah, it does. Looks good, thanks! I'll report any other weird behavior I come across.

@raichoo
Copy link
Member

raichoo commented Aug 26, 2016

I have merged this into master.

@mitchellwrosen
Copy link

Another annoying one:

foobarlongname = [
    blah
  , what
  ,
   ^
   Cursor here

Press space...

foobarlongname = [
    blah
  , what
                 , 
                   ^
                   Cursor here

Also, it doesn't seem to go away with g:haskell_indent_disable=1. Is that intended?

@mitchellwrosen
Copy link

Oh, that's weird... I manually went into my plugin folder and git pull'd, now it works fine. Not sure why :PlugInstall wasn't updating properly.

@raichoo
Copy link
Member

raichoo commented Feb 2, 2017

This is intended behavior since I'm using comma-first and align them with the enclosing delimiter.

@xintron
Copy link

xintron commented Feb 15, 2017

I'm having issues with indentation as well. Given the following code block:

    [ (NS spotify spotify (className =? "Spotify") doFullFloat ) ]

If I go to the position before the closing ] and do a linebreak and insert a comma I end up with the following code (_ is the cursor):

    [ (NS spotify spotify (className =? "Spotify") doFullFloat )
    ,_]

Adding a space would now result in the following code:

    [ (NS spotify spotify (className =? "Spotify") doFullFloat ) 
      , ]

Any spaces added anywhere on the line would try and match up the comma with the opening parenthesis on the first line and not the opening bracket which (in my opinion) is the correct and expected behavior.

@raichoo
Copy link
Member

raichoo commented Feb 15, 2017

This is indeed an interesting specimen… I have to take a closer look at that.

@raichoo
Copy link
Member

raichoo commented Feb 15, 2017

@xintron I have pushed a fix with 4001113 but I'm not quite sure why this happens, there seems to be some odd edge case regarding synstack() which I somewhat fail to wrap my head around.

@raichoo
Copy link
Member

raichoo commented Feb 26, 2017

I'm currently building a test suite for these cases so hopefully this will make the indentation more robust.

@cdepillabout
Copy link

Issue #97 has an additional case where indentation doesn't seem to be working quite right.

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

5 participants