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

Zero-width version of $W #588

Closed
ronshapiro opened this issue Nov 27, 2017 · 5 comments
Closed

Zero-width version of $W #588

ronshapiro opened this issue Nov 27, 2017 · 5 comments

Comments

@ronshapiro
Copy link
Contributor

I'm looking into the possibility of removing google-java-format from Dagger (google/dagger#368) and $W is a useful tool in adding line breaks when necessary, but sometimes I want the option of breaking if necessary, or no space at all.

Consider this example: I want to write the following method invocations without thinking about how many arguments I'm about to pass:

Foo_Factory.create(arg0, arg1, arg2);

Foo_Factory.create(
    arg0,
    arg1,
    arg2,
    arg3,
    arg4,
    arg5,
    ...,
    argN);

$W works for args 1..N but in the first example, adding in a $W between create( and arg0 would create an awkward space.

square/kotlinpoet#281 is a similar attempt that maybe can be applied here as well?

@JakeWharton
Copy link
Member

This is also needed for parameter lists. The first parameter never wraps.

@ronshapiro
Copy link
Contributor Author

ronshapiro commented Jan 5, 2018

What are your thoughts on having $W inspect the previous character for insights on whether it should be zero-width or one-width?

In foo($Warg1,$Warg2) the first can be zero width since it is preceded by a parens. If the line is already too long, it can still break. The second will either reasons in a space or break since it is preceded by a comma

@ronshapiro ronshapiro reopened this Jan 5, 2018
@swankjesse
Copy link
Member

I think that might be too clever. Maybe just like $B for optional-break?

@ronshapiro
Copy link
Contributor Author

Fine by me. Cool if I send a PR?

@swankjesse
Copy link
Member

Please do!

swankjesse pushed a commit that referenced this issue Jan 27, 2018
* Adds `$B` as an optional newline if a line will exceed 100 chars

Closes #588

* Switch from $B to $Z
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

3 participants