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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions syntax/toml.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ syn match tomlKey /\v(^|[{,])\s*\zs[[:alnum:]._-]+\ze\s*\=/ contains=tomlDotInKe
syn region tomlKeyDq oneline start=/\v(^|[{,])\s*\zs"/ end=/"\ze\s*=/ contains=tomlEscape
syn region tomlKeySq oneline start=/\v(^|[{,])\s*\zs'/ end=/'\ze\s*=/

syn region tomlTable oneline start=/^\s*\[[^\[]/ end=/\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey
" Match table and table array headers. Distinguish from inline arrays by
" allowing commas only inside single or double quotes.
let s:HEADER_RE = '^\s*\[\[=%(([''"])%(\1@!.|\\"){-}\1|[^,''"]{-1,}){-1,}\]\]=\s*%(#|$)'
exe 'syn region tomlFold start=/\v' . s:HEADER_RE . '/ end=/\v%(' . s:HEADER_RE . ')@=/ fold transparent'

syn region tomlTableArray oneline start=/^\s*\[\[/ end=/\]\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey
syn region tomlTable oneline start=/^\s*\[[^\[]/ end=/\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey containedin=tomlFold contained

syn region tomlTableArray oneline start=/^\s*\[\[/ end=/\]\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey containedin=tomlFold contained

syn region tomlKeyValueArray start=/=\s*\[\zs/ end=/\]/ contains=@tomlValue

Expand Down
6 changes: 6 additions & 0 deletions test/test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ apple.type = "fruit"
3.14159 = "pi"
"127.0.0.1" = "value"

[foo."".'bar, actually'] # Empty string as key, key with a comma
foldbug = [
["a"] , # BUG: Remove comma to trigger folding bug
]
'' = "empty"

[[foo.quux]]
e = 2

Expand Down