From 8b9a4a088800d50c16daf0eb7c1823aed8d3c199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 19 Oct 2024 20:10:42 +0200 Subject: [PATCH] double -> single --- R/rules-indention.R | 13 +++++++------ R/rules-line-breaks.R | 2 +- ....Rd => is_single_indent_function_declaration.Rd} | 10 +++++----- 3 files changed, 13 insertions(+), 12 deletions(-) rename man/{is_double_indent_function_declaration.Rd => is_single_indent_function_declaration.Rd} (60%) diff --git a/R/rules-indention.R b/R/rules-indention.R index 178cc319f..3e953d76e 100644 --- a/R/rules-indention.R +++ b/R/rules-indention.R @@ -15,14 +15,14 @@ indent_braces <- function(pd, indent_by) { #' #' Necessary for consistent indention of the function declaration header. #' @param pd A parse table. -#' @inheritParams is_double_indent_function_declaration +#' @inheritParams is_single_indent_function_declaration #' @seealso set_unindention_child update_indention_ref_fun_dec #' @keywords internal unindent_fun_dec <- function(pd, indent_by = 2L) { if (is_function_declaration(pd)) { idx_closing_brace <- which(pd$token == "')'") fun_dec_head <- seq2(2L, idx_closing_brace) - if (is_double_indent_function_declaration(pd, indent_by = indent_by)) { + if (is_single_indent_function_declaration(pd, indent_by = indent_by)) { pd$indent[fun_dec_head] <- indent_by pd$indent[idx_closing_brace] <- 0L } else { @@ -32,20 +32,21 @@ unindent_fun_dec <- function(pd, indent_by = 2L) { pd } -#' Is the function declaration double indented? +#' Is the function declaration single indented? #' #' Assumes you already checked if it's a function with -#' `is_function_declaration`. It is double indented if the first token +#' `is_function_declaration`. It is single indented if the first token #' after the first line break that is a `"SYMBOL_FORMALS"`. #' @param pd A parse table. #' @inheritParams tidyverse_style #' @keywords internal -is_double_indent_function_declaration <- function(pd, indent_by = 2L) { +is_single_indent_function_declaration <- function(pd, indent_by = 2L) { head_pd <- vec_slice(pd, -nrow(pd)) line_break_in_header <- which(head_pd$lag_newlines > 0L & head_pd$token == "SYMBOL_FORMALS") if (length(line_break_in_header) > 0L) { # indent results from applying the rules, spaces is the initial spaces # (which is indention if a newline is ahead) + # The 2L factor is kept to convert double indent to single indent pd$spaces[line_break_in_header[1L] - 1L] <= 2L * indent_by } else { FALSE @@ -133,7 +134,7 @@ NULL #' #' @keywords internal update_indention_ref_fun_dec <- function(pd_nested) { - if (is_function_declaration(pd_nested) && !is_double_indent_function_declaration(pd_nested)) { + if (is_function_declaration(pd_nested) && !is_single_indent_function_declaration(pd_nested)) { seq <- seq2(3L, nrow(pd_nested) - 2L) pd_nested$indention_ref_pos_id[seq] <- pd_nested$pos_id[2L] } diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 319929d6d..0afc8e45d 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -236,7 +236,7 @@ remove_line_break_before_round_closing_after_curly <- function(pd) { remove_line_breaks_in_fun_dec <- function(pd) { if (is_function_declaration(pd)) { - is_double_indention <- is_double_indent_function_declaration(pd) + is_double_indention <- is_single_indent_function_declaration(pd) round_after <- ( pd$token == "')'" | pd$token_before == "'('" ) & diff --git a/man/is_double_indent_function_declaration.Rd b/man/is_single_indent_function_declaration.Rd similarity index 60% rename from man/is_double_indent_function_declaration.Rd rename to man/is_single_indent_function_declaration.Rd index d9a36a367..b186ec201 100644 --- a/man/is_double_indent_function_declaration.Rd +++ b/man/is_single_indent_function_declaration.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/rules-indention.R -\name{is_double_indent_function_declaration} -\alias{is_double_indent_function_declaration} -\title{Is the function declaration double indented?} +\name{is_single_indent_function_declaration} +\alias{is_single_indent_function_declaration} +\title{Is the function declaration single indented?} \usage{ -is_double_indent_function_declaration(pd, indent_by = 2L) +is_single_indent_function_declaration(pd, indent_by = 2L) } \arguments{ \item{pd}{A parse table.} @@ -14,7 +14,7 @@ operators such as '('.} } \description{ Assumes you already checked if it's a function with -\code{is_function_declaration}. It is double indented if the first token +\code{is_function_declaration}. It is single indented if the first token after the first line break that is a \code{"SYMBOL_FORMALS"}. } \keyword{internal}