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

Support for curly-curly syntactic sugar #528

Merged
merged 7 commits into from Jun 30, 2019

refactor, restyle, document

  • Loading branch information...
lorenzwalthert committed Jun 29, 2019
commit 8f4abb961e8679714665e85ea36a6fe4e4482a7d
@@ -162,20 +162,21 @@ add_space_after_for_if_while <- function(pd_flat) {
#' @keywords internal
set_space_in_curly_curly <- function(pd) {
if (is_curly_expr(pd)) {

after_inner_opening <- pd$token == "'{'" & pd$token_before == "'{'"
before_inner_closing <- lead(pd$token == "'}'" & pd$token_after == "'}'")
if (
any(after_inner_opening, na.rm = TRUE) &&
is_curly_curly_inner <- any(after_inner_opening, na.rm = TRUE) &&
any(before_inner_closing, na.rm = TRUE)
) {
if (is_curly_curly_inner) {
pd$spaces[after_inner_opening] <- 1L
pd$spaces[before_inner_closing] <- 1L
}

after_outer_opening <- pd$token == "'{'" & pd$token_after == "'{'"
before_outer_closing <- lead(pd$token == "'}'" & pd$token_before == "'}'")
if (
any(after_outer_opening, na.rm = TRUE) &&
any(before_outer_closing, nna.rm = TRUE)) {
is_curly_curly_outer <- any(after_outer_opening, na.rm = TRUE) &&
any(before_outer_closing, nna.rm = TRUE)
if (is_curly_curly_outer) {
pd$spaces[after_outer_opening] <- 0L
pd$spaces[before_outer_closing] <- 0L
}
@@ -4,9 +4,9 @@
#' rules for the curly-curly syntactic sugar (introduced in rlang 0.4).
#' This function (`style_text_without_curly_curly()`) is needed for testing
#' only, namely to test indention
#' with multiple curly braces in a sequence. It is important to maintain test
#' for indention rules even as `\{\{` is always kept on the same line (if
#' followed) by `\}\}` without interruption, e.g. `{{1} + 2}` because we should
#' with multiple curly braces in a sequence. It is important to maintain testing
#' for indention rules even as the curly-curly expression is always kept on the
#' same line in the tidyverse style guide because we should
#' ensure the underlaying mechanics for indention work correctly. When
#' indention mechanisms are changed later, e.g. by simplifying
#' [compute_indent_indices()], we must have

Some generated files are not rendered by default. Learn more.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.