Skip to content

Have only a single space character between elements and their separators? #901

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

Closed
IndrajeetPatil opened this issue Jan 14, 2022 · 2 comments · Fixed by #903
Closed

Have only a single space character between elements and their separators? #901

IndrajeetPatil opened this issue Jan 14, 2022 · 2 comments · Fixed by #903

Comments

@IndrajeetPatil
Copy link
Collaborator

IndrajeetPatil commented Jan 14, 2022

For example, here I've deliberately added two spaces before "m" and "o" elements, but they are not converted to a single space by {styler}, which is what I would expect. Does that make sense?

observed

styler::style_text(
'c(
  "x", "y", "z",  "m", "n",  "o", "p",
  "c", "d"
)'
)
#> c(
#>   "x", "y", "z",  "m", "n",  "o", "p",
#>   "c", "d"
#> )

Created on 2022-01-14 by the reprex package (v2.0.1.9000)

expected

styler::style_text(
'c(
  "x", "y", "z",  "m", "n",  "o", "p",
  "c", "d"
)'
)
#> c(
#>   "x", "y", "z", "m", "n", "o", "p",
#>   "c", "d"
#> )
@IndrajeetPatil IndrajeetPatil changed the title Have only a single space character between vector and list elements? Have only a single space character between elements and their separators? Jan 14, 2022
@lorenzwalthert
Copy link
Collaborator

Thanks @IndrajeetPatil for your perseverance regarding alignment 😄. The reason for the behavior is that the current implementation requires all columns to be aligned for taking code as aligned, and that is the case in your example. Column 1 and 2 are aligned, and for the remainder of the columns, there is always just one instance, and an instance is always aligned with itself. For example for column 3, there is one line in the set we check, and all elements in this set (just one) match by comma. We need to adapt the rules that

For code to be aligned, columns that have only one row must have only one space after the most right comma from the previous column.

Like in the below example, the first column that has one row is column 2. So the previous column is column 1, and for this column, row 3 has the most right comma, so from that position, we add one space and then, column 2 must start.

c(
  "x",     "z",
  "cgjhg",  
)        ^ most right comma

This should also work when things are right-aligned:

c(
  "x",       "z",
  "cgjhg", "thi", "z"
)               ^ most right comma

If you can't follow, it's ok, took me a while to figure out, and I mainly wrote it down for future reference. :D

@IndrajeetPatil
Copy link
Collaborator Author

Wow, thank you so much for resolving this so quickly!

I can only imagine how complex it must be getting to cover all these edge cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants