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

4-space indent in nested parentheses? #1143

Open
drathier opened this issue Nov 13, 2024 · 2 comments
Open

4-space indent in nested parentheses? #1143

drathier opened this issue Nov 13, 2024 · 2 comments
Labels
style Nitpicking and things related to purely visual aspect for formatting.

Comments

@drathier
Copy link

Describe the bug
I get what I percieve as 4-space indentation whenever I have many nested parentheses. I'd like 2-space indentation here as well.

To Reproduce

f =
 (a (b 
 c))

gives

f =
  ( a
      ( b
          c
      )
  )

Expected behavior

f =
  ( a
    ( b
      c
    )
  )

Environment
0.7.7.0 and https://ormolu-live.tweag.io/

Additional context
I guess ormolu thinks that the parenthesis is one indentation, and the inner function call is another, so 2+2 space indentation?

FWIW, elm-format (which uses 4-space indentation) handles this close to what I'd expect:

f =
    a
        (b
            c
        )

(modulo space after paren)

@amesgen amesgen added the style Nitpicking and things related to purely visual aspect for formatting. label Nov 13, 2024
@amesgen
Copy link
Member

amesgen commented Nov 13, 2024

Thanks for the report! In general, when a function f is applied to an argument x in multi-line layout, we indent x by one more step than f (that's where the impression that there are 4 spaces of indentation comes from):

test =
  f
    x

In your suggested formatting output however

f =
  ( a
    ( b
      c
    )
  )

functions and their arguments are on the same level of indentation, i.e.

test =
  f
  x

which seems a bit unexpected.

A variant of formatting multi-line code in parentheses is given in #891, seems related to this issue.

@drathier
Copy link
Author

drathier commented Nov 13, 2024

I'm following how we ended up where we are, and it matches what you're describing. It's not what I'd expect however, so I'm wondering what my mental rule is. Perhaps "the first non-space character on each line is what the indentation level is"? #891 comes to the same conclusion, but for different reasons.

I'd expect this formatting, just like you:

test =
  f
    x

but also this:

test =
  (f
    x
  )

or possibly this, but the f-x alignment feels wrong:

test =
  ( f
    x
  )

I guess that unwanted f-x function-argument alignment why elm-format doesn't add a space between ( and f. I too expect function arguments to be indented further than the function they're applied to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style Nitpicking and things related to purely visual aspect for formatting.
Projects
None yet
Development

No branches or pull requests

2 participants