Skip to content

Commit 1b5ee66

Browse files
improve doc
1 parent 0c1318b commit 1b5ee66

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

R/indent.R

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,27 @@ needs_indention <- function(pd,
188188

189189
#' Check whether indention is needed
190190
#'
191+
#' Determine whether the tokens corresponding to `potential_trigger_pos` should
192+
#' cause indention, considering that there might be other potential triggers
193+
#' `other_trigger_tokens` that are going to cause indention.
191194
#' Indention is needed if the two conditions apply:
192195
#'
193196
#' * there is no multi-line token between the trigger and the first line break.
194197
#' * there is no other token between the potential trigger and the first line
195198
#' break that is going to cause indention. Note that such an other trigger
196-
#' only causes indention if there is a line break after that other token, not
197-
#' otherwise. See 'Details' for an example where there is such an other
198-
#' trigger, but since the next token is on the same line as the other trigger,
199-
#' no indention is caused by that other trigger.
199+
#' only causes indention if there is a line break after that other triggering
200+
#' token, not otherwise. If it causes indention, it is said to be an active
201+
#' trigger, if it does not, it is called an inactive trigger.
202+
#' See 'Details' for an example where there is an other trigger token, but
203+
#' since the next token is on the same line as the other trigger,
204+
#' the trigger is passive.
200205
#' @param pd A parse table.
201206
#' @param potential_trigger_pos the index of the token in the parse table
202207
#' for which it should be checked whether it should trigger indention.
203208
#' @return Returns `TRUE` if indention is needed, `FALSE` otherwise.
204209
#' @param other_trigger_tokens Other tokens that are going to cause indention
205-
#' if on the same line as the token corresponding to `potential_trigger`.
210+
#' if on the same line as the token corresponding to `potential_trigger` and
211+
#' directly followed by a line break.
206212
#' @return `TRUE` if indention is needed, `FALSE` otherwise.
207213
#' @importFrom rlang seq2
208214
#' @keywords internal
@@ -227,13 +233,14 @@ needs_indention_one <- function(pd,
227233
other_trigger_on_same_line <- (
228234
pd$token[remaining_row_idx_between_trigger_and_line_break] %in%
229235
other_trigger_tokens
230-
) & (
231-
pd$lag_newlines[remaining_row_idx_between_trigger_and_line_break + 1L] >
232-
0L
233236
)
237+
line_break_after_other_trigger <-
238+
pd$lag_newlines[remaining_row_idx_between_trigger_and_line_break + 1L] > 0L
234239

240+
active_trigger_on_same_line <-
241+
other_trigger_on_same_line & line_break_after_other_trigger
235242

236-
!any(multi_line_token) & !any(other_trigger_on_same_line)
243+
!any(multi_line_token) & !any(active_trigger_on_same_line)
237244
}
238245

239246

man/needs_indention.Rd

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

man/needs_indention_one.Rd

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

0 commit comments

Comments
 (0)