aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/ftplugin/spajson.vim14
-rw-r--r--runtime/indent/spajson.vim6
-rw-r--r--runtime/lua/vim/filetype.lua2
-rw-r--r--runtime/syntax/spajson.vim50
-rw-r--r--test/old/testdir/test_filetype.vim2
5 files changed, 74 insertions, 0 deletions
diff --git a/runtime/ftplugin/spajson.vim b/runtime/ftplugin/spajson.vim
new file mode 100644
index 0000000000..d03d1d5070
--- /dev/null
+++ b/runtime/ftplugin/spajson.vim
@@ -0,0 +1,14 @@
+" Vim filetype plugin
+" Language: SPA JSON
+" Maintainer: David Mandelberg <david@mandelberg.org>
+" Last Change: 2025 Mar 22
+
+if exists('b:did_ftplugin')
+ finish
+endif
+let b:did_ftplugin = 1
+
+setlocal comments=:###,:##,:#
+setlocal commentstring=#\ %s
+
+let b:undo_ftplugin = "setlocal comments< commentstring<"
diff --git a/runtime/indent/spajson.vim b/runtime/indent/spajson.vim
new file mode 100644
index 0000000000..e644a5ee60
--- /dev/null
+++ b/runtime/indent/spajson.vim
@@ -0,0 +1,6 @@
+" Vim indent file
+" Language: SPA JSON
+" Maintainer: David Mandelberg <david@mandelberg.org>
+" Last Change: 2025 Mar 22
+
+runtime! indent/json.vim
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 30dde915ed..a35a1a32b3 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -2263,6 +2263,8 @@ local pattern = {
['^named.*%.conf$'] = 'named',
['^rndc.*%.conf$'] = 'named',
['/openvpn/.*/.*%.conf$'] = 'openvpn',
+ ['/pipewire/.*%.conf$'] = 'spajson',
+ ['/wireplumber/.*%.conf$'] = 'spajson',
['/%.ssh/.*%.conf$'] = 'sshconfig',
['^%.?tmux.*%.conf$'] = 'tmux',
['^%.?tmux.*%.conf'] = { 'tmux', { priority = -1 } },
diff --git a/runtime/syntax/spajson.vim b/runtime/syntax/spajson.vim
new file mode 100644
index 0000000000..78ade5f929
--- /dev/null
+++ b/runtime/syntax/spajson.vim
@@ -0,0 +1,50 @@
+" Vim syntax file
+" Language: SPA JSON
+" Maintainer: David Mandelberg <david@mandelberg.org>
+" Last Change: 2025 Mar 22
+"
+" Based on parser code:
+" https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/spa/include/spa/utils/json-core.h
+
+if exists("b:current_syntax")
+ finish
+endif
+let b:current_syntax = "spajson"
+
+syn sync minlines=500
+
+" Treat the __BARE parser state as a keyword, to make it easier to match
+" keywords and numbers only when they're not part of a larger __BARE section.
+" E.g., v4l2 and pipewire-0 probably shouldn't highlight anything as
+" spajsonInt.
+syn iskeyword 32-126,^ ,^",^#,^:,^,,^=,^],^},^\
+
+syn match spajsonEscape "\\["\\/bfnrt]" contained
+syn match spajsonEscape "\\u[0-9A-Fa-f]\{4}" contained
+
+syn match spajsonError "."
+syn match spajsonBare "\k\+"
+syn match spajsonComment "#.*$" contains=@Spell
+syn region spajsonString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=spajsonEscape
+syn match spajsonKeyDelimiter "[:=]"
+syn region spajsonArray matchgroup=spajsonBracket start="\[" end="]" contains=ALLBUT,spajsonKeyDelimiter fold
+syn region spajsonObject matchgroup=spajsonBrace start="{" end="}" contains=ALL fold
+syn match spajsonFloat "\<[+-]\?[0-9]\+\(\.[0-9]*\)\?\([Ee][+-]\?[0-9]\+\)\?\>"
+syn match spajsonFloat "\<[+-]\?\.[0-9]\+\([Ee][+-]\?[0-9]\+\)\?\>"
+syn match spajsonInt "\<[+-]\?0[Xx][0-9A-Fa-f]\+\>"
+syn match spajsonInt "\<[+-]\?[1-9][0-9]*\>"
+syn match spajsonInt "\<[+-]\?0[0-7]*\>"
+syn keyword spajsonBoolean true false
+syn keyword spajsonNull null
+syn match spajsonWhitespace "[\x00\t \r\n,]"
+
+hi def link spajsonBoolean Boolean
+hi def link spajsonBrace Delimiter
+hi def link spajsonBracket Delimiter
+hi def link spajsonComment Comment
+hi def link spajsonError Error
+hi def link spajsonEscape SpecialChar
+hi def link spajsonFloat Float
+hi def link spajsonInt Number
+hi def link spajsonNull Constant
+hi def link spajsonString String
diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim
index 7a0ce47948..4e54ff598f 100644
--- a/test/old/testdir/test_filetype.vim
+++ b/test/old/testdir/test_filetype.vim
@@ -719,6 +719,8 @@ func s:GetFilenameChecks() abort
\ 'snobol4': ['file.sno', 'file.spt'],
\ 'solidity': ['file.sol'],
\ 'solution': ['file.sln'],
+ \ 'spajson': ['any/pipewire/file.conf', 'any/pipewire/file.conf.d/other.conf',
+ \ 'any/wireplumber/file.conf', 'any/wireplumber/file.conf.d/other.conf'],
\ 'sparql': ['file.rq', 'file.sparql'],
\ 'spec': ['file.spec'],
\ 'spice': ['file.sp', 'file.spice'],