nilcons / hi2

haskell-indentation 2nd try
GNU General Public License v3.0
33 stars 3 forks source link

What does hi2-ifte-offset exactly mean? #9

Open Javran opened 10 years ago

Javran commented 10 years ago

I don't understand what does this option means. Saying I want to write an if expression and have it aligned in the following way:

main :: IO ()
main = if undefined
         then undefined
         else undefined

To be more specific, what I want is: the line right after if to be 2 extra spaces, and then and else line up with each other. So I set hi2-ifte-offset to be 2. If I type in the expression without a tab, I end up with this identation:

main = if undefined
          then undefined
               else undefined

If I hit <tab> every time after I type in then or else, I end up with this:

main = if undefined
       then undefined
       else undefined

And hi2-ifte-offset dosen't seem to affect this behavior.

Maybe I've totally misunderstood those options, so I open this issue hoping to clean up my confusion.

klao commented 10 years ago

Thank you for your report! You are right, this variable doesn't seem to do anything.

At first, I thought that it controls if/then/else indentation within do notation. That is, in code like this:

main = do
  if undefined
    then undefined
    else undefined

You can see that here then and else are indented more than the if. But, the variable doesn't change the behavior in that case either. :)

We have some plans to do a major clean-up and revision of hi2. Unfortunately, it's unlikely that it will happen very soon.

But, I also want to say that in modern Haskell it is customary to indent then and else always below the if (like hi2 does in your description). Even within do notation. So I am not sure that this would be a good feature if it worked, maybe it just have to be removed...

Javran commented 10 years ago

Thanks for your explanation! Looking forward to the revision, and I think maintaining some wiki pages to be more detailed about these options might help others out, sometimes option descriptions are just not enough for people don't have knowledge of the underlying implementation.

However, It's a little off topic but can you provide me some pointer about code style on if-exprs? Since I don't think customary Haskell code indent then and else right below the if.

For one thing we all know that the following code don't work as expect unless some pragma is on:

main = do
    if undefined
    then undefined
    else undefined

And I think this indirectly deprecates indenting if, then and else the same.

For another, in many other languages then and else indents more than if to make it easier to read. In haskell if ... then ... else ... is considered an expression, and if an expression takes two lines, we don't usually indent them the same.

But these are all my personal opinions, I'm happy to following common practice if they sounds more reasonable than my current habit.

Ailrun commented 6 years ago

@klao Is there any progress? I really want to format then and else at the same level with if... However, haskell-indent-mode from haskell-mode have module ... where indent problem, haskell-indentation-mode doesn't support various indentations, and this one does not support same level of indentation for if then else....

kuribas commented 6 years ago

@Ailrun this mode is the same as haskell-indentation from haskell-mode. If you have feature requests or issues it's best to send them to haskell-mode.

Ailrun commented 6 years ago

@kuribas Oh... but haskell-indentation-mode does not support various indentations, right? What was happened while porting?

kuribas commented 6 years ago

I don't know what you mean with various indentations. AFAIK all changes have been merged into haskell-indentation-mode