Skip to content

Pr106 4 raw indention - #116

Merged
lorenzwalthert merged 4 commits into
r-lib:masterfrom
lorenzwalthert:pr106_4_raw_indention
Aug 8, 2017
Merged

lorenzwalthert merged 4 commits into
r-lib:masterfrom
lorenzwalthert:pr106_4_raw_indention

Conversation

@lorenzwalthert

@lorenzwalthert lorenzwalthert commented Aug 7, 2017 •

Copy link
Copy Markdown
Collaborator

This is the third part of #106. Styler can now leave indention as is 😊. A new level of the argument scope is introduced ("indention"). "spaces" will not modify indention anymore (closes #104, closes #105). Note that since we use named transformers in R/transform.R (because depending on what is modified, the transformer needs to be called at a certain point in the process), we can also use values other than functions in the transformers. I think that's a natural extension plus since the parse table is already flattened out, I think this cannot be done well with a transformer function.

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. What do we need to do for a simple roundtrip test of parsing + nesting + serialization?

Comment thread R/modify_pd.R
#' @seealso choose_indention
update_newlines <- function(pd) {
npd <- nrow(pd) - 1
pd$newlines[seq_len(npd)] <- pd$lag_newlines[seq_len(npd) + 1]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use dplyr::lead()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because then we'd lose information since we would end up with lead(lag(newlines)) and the last entry would be NA. Therefore, we do the shift manually and do not replace the last value in newlines (since this one was not modified anyways by our rules). I think this is safe because we anyways only work with lag_newlines in all of the rules, so if someone wants to add blank lines after a token, he'd have to insert it not after the token, but before the next token (this is possible via pd$token_before).

@lorenzwalthert
lorenzwalthert merged commit 82ebd0c into r-lib:master Aug 8, 2017
@lorenzwalthert
lorenzwalthert deleted the pr106_4_raw_indention branch November 21, 2017 09:11
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 this pull request may close these issues.

Allow styling without modifying indention Decide on the usage of the newlines attribute

2 participants