Skip to content

Commit 2cf9143

Browse files
use unindent_fun_dec() for proper token-dependent indention of function calls.
1 parent 5e1cd4f commit 2cf9143

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

R/indent.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ indent_op <- function(pd,
3636
pd
3737
}
3838

39+
#' Revert the indention of function declaration heads
40+
#'
41+
#' Necessary for consistent indention of the function declaration head.
42+
#' @param pd A parse table.
43+
#' @seealso set_unindention_child update_indention_ref_fun_dec
44+
unindent_fun_dec <- function(pd) {
45+
if (is_function_dec(pd)) {
46+
idx_closing_brace <- which(pd$token %in% "')'")
47+
fun_dec_head <- seq2(2L, idx_closing_brace)
48+
pd$indent[fun_dec_head] <- 0L
49+
50+
}
51+
pd
52+
}
53+
3954
#' @describeIn update_indention Updates indention for token EQ_SUB. Only differs
4055
#' from [indent_op()] in the sense that not all subsequent tokens in the parse
4156
#' table are necessarily indented, as `EQ_SUB` and `EQ_FORMALS` can occur

R/reindent.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ apply_ref_indention_one <- function(flattened_pd, target_token) {
9696
# udate spaces
9797
copied_spaces <- flattened_pd$col2[target_token]
9898
old_spaces <- flattened_pd$lag_spaces[token_to_update[1]]
99-
if (length(token_to_update) < 1) return(flattened_pd)
100-
zero_ref <- min(flattened_pd$lag_spaces[token_to_update])
101-
shift <- copied_spaces - zero_ref
99+
shift <- copied_spaces
102100
flattened_pd$lag_spaces[token_to_update] <-
103101
flattened_pd$lag_spaces[token_to_update] + shift
104102

@@ -115,8 +113,6 @@ apply_ref_indention_one <- function(flattened_pd, target_token) {
115113
#' spacing information needs to be updated are computed. Since indention is
116114
#' already embeded in the column `lag_spaces`, only tokens at the beginning of
117115
#' a line are of concern.
118-
#' This function is currently tailored targeted at
119-
#' re-indention of function delcaration.
120116
#' @param flattened_pd A flattened parse table.
121117
#' @param token_to_update An integer vector with positions of tokens to update.
122118
#' @seealso apply_ref_indention_one()

R/style_guides.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ tidyverse_style <- function(scope = "tokens",
6565
space_manipulators <- if (scope >= "spaces") {
6666
lst(
6767
partial(indent_braces, indent_by = indent_by),
68+
unindent_fun_dec,
6869
partial(indent_op, indent_by = indent_by),
6970
partial(indent_eq_sub, indent_by = indent_by),
7071
partial(indent_without_paren, indent_by = indent_by),

man/find_tokens_to_update.Rd

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/unindent_fun_dec.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)