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

After linebreaks following =, indentation is off #39

Closed
lmshk opened this issue Aug 7, 2024 · 5 comments · Fixed by #42
Closed

After linebreaks following =, indentation is off #39

lmshk opened this issue Aug 7, 2024 · 5 comments · Fixed by #42

Comments

@lmshk
Copy link

lmshk commented Aug 7, 2024

For example, Runic reformats

y =
    if x
      1
    else
      2
    end

to

y =
    if x
    1
else
    2
end

which is likely not intended.

(This also applies to short-form function definitions with linebreaks after the =.)

@fredrikekre
Copy link
Owner

fredrikekre commented Aug 7, 2024

Given the existing rules I would have guessed the result would be

y = if x
        1
    else
        2
    end

but that doesn't look very good either. Probably proper blocks like if-end should have some more "inertia" for changes like this because code like

y = if x
    1
else
    2
end

is pretty common. The style you have with a line break before the if I haven't seen much actually. Would you expect

y =
if x
    1
else
    2
end

?

@lmshk
Copy link
Author

lmshk commented Aug 7, 2024

I would expect my original form, because the expression as continued on the second line is just indented once. (I usually do this if ?/: does not fit on the first line.)

I'd be fine with your second example as well. (If I write it like that, Runic leaves it as it is.)

@adienes
Copy link

adienes commented Aug 10, 2024

I think it should be

y = if x
    1
else
    2
end

the other options present look off to me (including the original example, no offense intended @lmshk 😅)

@lmshk
Copy link
Author

lmshk commented Aug 11, 2024

That implies that for long conditions, breaking the line then would indent the continuation at the same level as the body. (Similarly for short-form function definitions).

Also, my understanding is that Runic is supposed to leave linebreaks intact; if you prefer y = if x, you can already write it like that and it will not be broken up.

fredrikekre added a commit that referenced this issue Aug 12, 2024
This patch reworks the indentation after assignment. For "blocklike"
(try/if/triple strings) right hand sides the indentation is disabled.
Superfluous newlines are removed. For example

```julia
x =
if a
    x
else
    y
end
```

will become

```julia
x = if a
    x
else
    y
end
```

A valid alternative is

```julia
x = if a
        x
    else
        y
    end
```

This highlights the start/end of the right hand side of the assignment
in a better way, but it doesn't look very nice and this style is never
really seen in the wild. For triple strings I think it is OK though,
e.g.

```julia
x = """
    foo
    bar
    """
```

vs the current (and seen more in the wild)

```julia
x = """
foo
bar
"""
```

Closes #39.
fredrikekre added a commit that referenced this issue Aug 12, 2024
This patch reworks the indentation after assignment. For "blocklike"
(try/if/triple strings) right hand sides the indentation is disabled.
Superfluous newlines are removed. For example

```julia
x =
if a
    x
else
    y
end
```

will become

```julia
x = if a
    x
else
    y
end
```

A valid alternative is

```julia
x = if a
        x
    else
        y
    end
```

This highlights the start/end of the right hand side of the assignment
in a better way, but it doesn't look very nice and this style is never
really seen in the wild. For triple strings I think it is OK though,
e.g.

```julia
x = """
    foo
    bar
    """
```

vs the current (and seen more in the wild)

```julia
x = """
foo
bar
"""
```

Closes #39.
@fredrikekre
Copy link
Owner

See #42.

fredrikekre added a commit that referenced this issue Aug 15, 2024
This patch reworks the indentation after assignment. For "blocklike"
(try/if/triple-strings) right hand sides the indentation is disabled.

Closes #39.
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

Successfully merging a pull request may close this issue.

3 participants