@@ -188,21 +188,27 @@ needs_indention <- function(pd,
188
188
189
189
# ' Check whether indention is needed
190
190
# '
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.
191
194
# ' Indention is needed if the two conditions apply:
192
195
# '
193
196
# ' * there is no multi-line token between the trigger and the first line break.
194
197
# ' * there is no other token between the potential trigger and the first line
195
198
# ' 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.
200
205
# ' @param pd A parse table.
201
206
# ' @param potential_trigger_pos the index of the token in the parse table
202
207
# ' for which it should be checked whether it should trigger indention.
203
208
# ' @return Returns `TRUE` if indention is needed, `FALSE` otherwise.
204
209
# ' @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.
206
212
# ' @return `TRUE` if indention is needed, `FALSE` otherwise.
207
213
# ' @importFrom rlang seq2
208
214
# ' @keywords internal
@@ -227,13 +233,14 @@ needs_indention_one <- function(pd,
227
233
other_trigger_on_same_line <- (
228
234
pd $ token [remaining_row_idx_between_trigger_and_line_break ] %in%
229
235
other_trigger_tokens
230
- ) & (
231
- pd $ lag_newlines [remaining_row_idx_between_trigger_and_line_break + 1L ] >
232
- 0L
233
236
)
237
+ line_break_after_other_trigger <-
238
+ pd $ lag_newlines [remaining_row_idx_between_trigger_and_line_break + 1L ] > 0L
234
239
240
+ active_trigger_on_same_line <-
241
+ other_trigger_on_same_line & line_break_after_other_trigger
235
242
236
- ! any(multi_line_token ) & ! any(other_trigger_on_same_line )
243
+ ! any(multi_line_token ) & ! any(active_trigger_on_same_line )
237
244
}
238
245
239
246
0 commit comments