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

How to define a dependent layout #79

Open
oovm opened this issue May 31, 2023 · 1 comment
Open

How to define a dependent layout #79

oovm opened this issue May 31, 2023 · 1 comment

Comments

@oovm
Copy link

oovm commented May 31, 2023

I want to define a layout that has two forms, depending on whether the other layout is single-line or multi-line

For example, for the statement while cond body

If cond is single line, then body use layout 1

while true {
    layout1
}

If cond is multiline, then use body layout 2

while
     cond_a 
     && cond_b
     || cond_c
{
     layout2
}

flat_alt seems to only depend on whether itself is single-line or multi-line, is there a way to depend on other units

@Marwes
Copy link
Owner

Marwes commented May 31, 2023

This is a really tricky thing to get right with this kind of formatter in my experience. My best effort so far is using union which you could try under block::BlockDoc which I think should work for this case (though some choices around whitespace might not exactly match what you want).

If that doesn't work you will need to hack something yourself using union or choose a different formatter I am afraid.

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

2 participants