Skip to content

Add fold regions to Tables and TableArrays #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tpikonen
Copy link

Tables and TableArrays are folded when foldmethod=syntax is set.

The folds are implemented by a single regex which matches the table and table array headers. This has to replicate a large part of the syntax for TOML keys, so the regex becomes a bit involved. Fold levels are limited to 1 for a table and 0 for the part before the first table. This is because dictionary depth cannot be parsed from the header with a regex and cannot be communicated to vim by syntax statements anyway.

There is an edge case where a valid inline array looks like a table header, and is detected as such. This is hopefully rare enough in practice to not matter. A demonstration of this is added to test.toml.

This perhaps could have been implemented with a clever use of contains, containedin etc., but that would require a larger refactoring and maybe fixing of other bugs such as #58.

Fixes #63.

Teemu Ikonen added 2 commits April 13, 2025 11:53
Tables and TableArrays are folded when foldmethod=syntax is set.
A single element array without a trailing comma on a line on its own
cannot be distinguished from a table header.
@A4-Tacks
Copy link
Contributor

A4-Tacks commented May 2, 2025

Working on large files using syntaxfold may result in performance issues
Or it may be due to syn-sync causing abnormal folding

Considering foldexpr?
:set foldmethod=expr
:set foldexpr=getline(nextnonblank(v:lnum+1))=~'^['?'<1':1

Screenshot_20250502_151757
Screenshot_20250502_151804

@A4-Tacks A4-Tacks mentioned this pull request May 2, 2025
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.

Add folding support for tables
2 participants