Skip to content

[audit] fix: foldmethod "indent" → "expr" to activate treesitter folding#153

Merged
stanfish06 merged 1 commit into
masterfrom
audit/fold-method-expr
Jun 6, 2026
Merged

[audit] fix: foldmethod "indent" → "expr" to activate treesitter folding#153
stanfish06 merged 1 commit into
masterfrom
audit/fold-method-expr

Conversation

@stanfish06
Copy link
Copy Markdown
Owner

What

lua/config/options.lua:100 sets foldmethod = "indent" but the very next line configures a treesitter foldexpr. Because Neovim only evaluates foldexpr when foldmethod = "expr", the treesitter fold expression has been silently dead — folding was indent-based all along.

-- before
vim.o.foldmethod = "indent"
vim.o.foldexpr   = "v:lua.vim.treesitter.foldexpr()"  -- never evaluated

-- after
vim.o.foldmethod = "expr"
vim.o.foldexpr   = "v:lua.vim.treesitter.foldexpr()"  -- now active

Where

lua/config/options.lua:100

Why it matters

With foldmethod = "indent", folds are purely whitespace-based and have no awareness of language syntax — mismatched indentation (e.g. Python docstrings, closing braces) creates wrong fold boundaries. foldmethod = "expr" with vim.treesitter.foldexpr() uses the AST for correct, language-aware fold boundaries.

foldlevel = 10 is already set, so switching to "expr" will not collapse any currently-open folds — behaviour is identical on startup, but :set foldmethod? will now report expr and zc/za will fold on correct AST boundaries.

Note on foldnestmax

foldnestmax only applies to indent and syntax methods; it is silently ignored by expr. The existing vim.o.foldnestmax = 10 line becomes a harmless no-op after this change.

Recommended action

Merge. One-line change, zero risk of breaking existing open-fold behaviour.


Generated by Claude Code

…expr

foldexpr was set to vim.treesitter.foldexpr() but foldmethod was still
"indent", so the treesitter fold expression was never evaluated.
@stanfish06 stanfish06 merged commit ff6b06c into master Jun 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants