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

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

Open
Javran opened this issue Oct 2, 2014 · 6 comments
Open

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

Javran opened this issue Oct 2, 2014 · 6 comments

Comments

@Javran
Copy link

Javran commented Oct 2, 2014

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
Copy link
Member

klao commented Oct 4, 2014

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
Copy link
Author

Javran commented Oct 6, 2014

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
Copy link

Ailrun commented Mar 22, 2018

@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
Copy link

kuribas commented Mar 23, 2018

@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
Copy link

Ailrun commented Mar 23, 2018

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

@kuribas
Copy link

kuribas commented Mar 24, 2018

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

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

4 participants