Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

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
Collaborator

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
Collaborator

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
Collaborator

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants