@@ -15,14 +15,14 @@ indent_braces <- function(pd, indent_by) {
15
15
# '
16
16
# ' Necessary for consistent indention of the function declaration header.
17
17
# ' @param pd A parse table.
18
- # ' @inheritParams is_double_indent_function_declaration
18
+ # ' @inheritParams is_single_indent_function_declaration
19
19
# ' @seealso set_unindention_child update_indention_ref_fun_dec
20
20
# ' @keywords internal
21
21
unindent_fun_dec <- function (pd , indent_by = 2L ) {
22
22
if (is_function_declaration(pd )) {
23
23
idx_closing_brace <- which(pd $ token == " ')'" )
24
24
fun_dec_head <- seq2(2L , idx_closing_brace )
25
- if (is_double_indent_function_declaration (pd , indent_by = indent_by )) {
25
+ if (is_single_indent_function_declaration (pd , indent_by = indent_by )) {
26
26
pd $ indent [fun_dec_head ] <- indent_by
27
27
pd $ indent [idx_closing_brace ] <- 0L
28
28
} else {
@@ -32,20 +32,21 @@ unindent_fun_dec <- function(pd, indent_by = 2L) {
32
32
pd
33
33
}
34
34
35
- # ' Is the function declaration double indented?
35
+ # ' Is the function declaration single indented?
36
36
# '
37
37
# ' Assumes you already checked if it's a function with
38
- # ' `is_function_declaration`. It is double indented if the first token
38
+ # ' `is_function_declaration`. It is single indented if the first token
39
39
# ' after the first line break that is a `"SYMBOL_FORMALS"`.
40
40
# ' @param pd A parse table.
41
41
# ' @inheritParams tidyverse_style
42
42
# ' @keywords internal
43
- is_double_indent_function_declaration <- function (pd , indent_by = 2L ) {
43
+ is_single_indent_function_declaration <- function (pd , indent_by = 2L ) {
44
44
head_pd <- vec_slice(pd , - nrow(pd ))
45
45
line_break_in_header <- which(head_pd $ lag_newlines > 0L & head_pd $ token == " SYMBOL_FORMALS" )
46
46
if (length(line_break_in_header ) > 0L ) {
47
47
# indent results from applying the rules, spaces is the initial spaces
48
48
# (which is indention if a newline is ahead)
49
+ # The 2L factor is kept to convert double indent to single indent
49
50
pd $ spaces [line_break_in_header [1L ] - 1L ] < = 2L * indent_by
50
51
} else {
51
52
FALSE
133
134
# '
134
135
# ' @keywords internal
135
136
update_indention_ref_fun_dec <- function (pd_nested ) {
136
- if (is_function_declaration(pd_nested ) && ! is_double_indent_function_declaration (pd_nested )) {
137
+ if (is_function_declaration(pd_nested ) && ! is_single_indent_function_declaration (pd_nested )) {
137
138
seq <- seq2(3L , nrow(pd_nested ) - 2L )
138
139
pd_nested $ indention_ref_pos_id [seq ] <- pd_nested $ pos_id [2L ]
139
140
}
0 commit comments