You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pressing Enter in an Rcpp chunk of an R Markdown document throws and skips auto-indent #18468
RStudio Edition : Desktop
RStudio Version : 2026.08.0-daily (regressed in 2024.12; commit eafc5faf44)
OS Version : all
R Version : all
Steps to reproduce the problem
Open a new R Markdown (or Quarto) document containing a completed chunk followed by an Rcpp chunk, e.g.:
```{r}1 + 1``````{Rcpp}int add(int x) {```
Place the cursor at the end of int add(int x) { and press Enter.
Describe the problem in detail
The new line receives no auto-indent, and an uncaught exception is raised (visible in the devtools console):
TypeError: Cannot read properties of undefined (reading 'width')
at onMatch
at getLineTokens
at $tokenizeUpToRow
at getNextLineIndent
at insert
TokenUtils.$tokenizeUpToRow (used by CppCodeModel for C++ chunk indentation) calls getLineTokens(line, state, row) without threading a tokenizer context, so every onMatch handler receives a fresh empty object. The chunk-end rule installed by Utils.embedRules dereferences context.chunk.width unguarded, so the exception fires as soon as tokenization crosses any completed chunk fence above the cursor. Broken since commit eafc5fa (September 2024), which introduced context-based chunk tracking.
The same unguarded context reads exist in the quarto (#|), YAML multiline string, and Sweave \Sexpr{} rules.
Describe the behavior you expected
Pressing Enter inside a C++ chunk indents the new line, without raising an exception.
Activity
fix C++ chunk indentation in R Markdown documents (#18470)