mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-08 11:33:52 -05:00
Switch to elzr for json syntax, and disable conceal by default
This commit is contained in:
@@ -57,7 +57,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
|
|||||||
- [html5](https://github.com/othree/html5.vim) (syntax, indent, autoload, ftplugin)
|
- [html5](https://github.com/othree/html5.vim) (syntax, indent, autoload, ftplugin)
|
||||||
- [jasmine](https://github.com/glanotte/vim-jasmine) (syntax, ftdetect)
|
- [jasmine](https://github.com/glanotte/vim-jasmine) (syntax, ftdetect)
|
||||||
- [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, ftplugin, ftdetect)
|
- [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [json](https://github.com/sheerun/vim-json) (syntax, indent, ftdetect)
|
- [json](https://github.com/elzr/vim-json) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent, ftdetect)
|
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent, ftdetect)
|
||||||
- [jsx](https://github.com/mxw/vim-jsx) (ftdetect, after)
|
- [jsx](https://github.com/mxw/vim-jsx) (ftdetect, after)
|
||||||
- [julia](https://github.com/dcjones/julia-minimalist-vim) (syntax, indent, ftdetect)
|
- [julia](https://github.com/dcjones/julia-minimalist-vim) (syntax, indent, ftdetect)
|
||||||
|
|||||||
2
build
2
build
@@ -130,7 +130,7 @@ PACKS="
|
|||||||
html5:othree/html5.vim
|
html5:othree/html5.vim
|
||||||
jasmine:glanotte/vim-jasmine
|
jasmine:glanotte/vim-jasmine
|
||||||
javascript:pangloss/vim-javascript
|
javascript:pangloss/vim-javascript
|
||||||
json:sheerun/vim-json
|
json:elzr/vim-json
|
||||||
jst:briancollins/vim-jst
|
jst:briancollins/vim-jst
|
||||||
jsx:mxw/vim-jsx:_ALL
|
jsx:mxw/vim-jsx:_ALL
|
||||||
julia:dcjones/julia-minimalist-vim
|
julia:dcjones/julia-minimalist-vim
|
||||||
|
|||||||
@@ -2,3 +2,8 @@
|
|||||||
if !exists('g:jsx_ext_required')
|
if !exists('g:jsx_ext_required')
|
||||||
let g:jsx_ext_required = 0
|
let g:jsx_ext_required = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Disable json concealing by default
|
||||||
|
if !exists('g:vim_json_syntax_conceal')
|
||||||
|
let g:vim_json_syntax_conceal = 0
|
||||||
|
endif
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
if !exists('g:jsx_ext_required')
|
if !exists('g:jsx_ext_required')
|
||||||
let g:jsx_ext_required = 0
|
let g:jsx_ext_required = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Disable json concealing by default
|
||||||
|
if !exists('g:vim_json_syntax_conceal')
|
||||||
|
let g:vim_json_syntax_conceal = 0
|
||||||
|
endif
|
||||||
" ftdetect/ansible.vim
|
" ftdetect/ansible.vim
|
||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1
|
||||||
|
|
||||||
@@ -404,8 +409,9 @@ endif
|
|||||||
" ftdetect/json.vim
|
" ftdetect/json.vim
|
||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'json') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'json') == -1
|
||||||
|
|
||||||
autocmd BufNewFile,BufRead *.json set filetype=json
|
autocmd BufNewFile,BufRead *.json setlocal filetype=json
|
||||||
autocmd BufNewFile,BufRead *.jsonp set filetype=json
|
autocmd BufNewFile,BufRead *.jsonp setlocal filetype=json
|
||||||
|
autocmd BufNewFile,BufRead *.geojson setlocal filetype=json
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
42
ftplugin/json.vim
Normal file
42
ftplugin/json.vim
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'json') == -1
|
||||||
|
|
||||||
|
" Vim syntax file
|
||||||
|
" Language: JSON
|
||||||
|
" Maintainer: Eli Parra <eli@elzr.com> https://github.com/elzr/vim-json
|
||||||
|
" Last Change: 2014-05-20 added warning toggle
|
||||||
|
|
||||||
|
"uncomment to enable folding of `{...}` and `[...]` blocks
|
||||||
|
"setlocal foldmethod=syntax
|
||||||
|
|
||||||
|
"conceal by default
|
||||||
|
if !exists("g:vim_json_syntax_conceal")
|
||||||
|
let g:vim_json_syntax_conceal = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
"have warnings by default
|
||||||
|
if !exists("g:vim_json_warnings")
|
||||||
|
let g:vim_json_warnings = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
"set concealcursor blank by default
|
||||||
|
"this should turn off the concealing in the current line (where the cursor is at),
|
||||||
|
"on all modes (normal, visual, insert)
|
||||||
|
if !exists("g:vim_json_syntax_concealcursor")
|
||||||
|
let g:vim_json_syntax_concealcursor = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
if has('conceal')
|
||||||
|
if (g:vim_json_syntax_conceal == 1)
|
||||||
|
"level 2 means concealed text gets completely hidden unless a
|
||||||
|
"replacement is defined (none is defined by us)
|
||||||
|
setlocal conceallevel=2
|
||||||
|
let &l:concealcursor = g:vim_json_syntax_concealcursor
|
||||||
|
else
|
||||||
|
"level 0 means text is shown normally = no concealing
|
||||||
|
setlocal conceallevel=0
|
||||||
|
endif
|
||||||
|
"maybe g:vim_json_syntax_conceal could be settable to 0,1,2 to map
|
||||||
|
"directly to vim's conceallevels? unsure if anyone cares
|
||||||
|
endif
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -44,7 +44,7 @@ let s:block_regex = '\%({\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)
|
|||||||
|
|
||||||
" Check if the character at lnum:col is inside a string.
|
" Check if the character at lnum:col is inside a string.
|
||||||
function s:IsInString(lnum, col)
|
function s:IsInString(lnum, col)
|
||||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') == jsonString
|
return synIDattr(synID(a:lnum, a:col, 1), 'name') == "jsonString"
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Find line above 'lnum' that isn't empty, or in a string.
|
" Find line above 'lnum' that isn't empty, or in a string.
|
||||||
@@ -143,7 +143,11 @@ function GetJSONIndent()
|
|||||||
|
|
||||||
" If the previous line ended with a block opening, add a level of indent.
|
" If the previous line ended with a block opening, add a level of indent.
|
||||||
" if s:Match(lnum, s:block_regex)
|
" if s:Match(lnum, s:block_regex)
|
||||||
" return indent(lnum) + shiftwidth()
|
" if exists('*shiftwidth')
|
||||||
|
" return indent(lnum) + shiftwidth()
|
||||||
|
" else
|
||||||
|
" return indent(lnum) + &sw
|
||||||
|
" endif
|
||||||
" endif
|
" endif
|
||||||
|
|
||||||
" If the previous line contained an opening bracket, and we are still in it,
|
" If the previous line contained an opening bracket, and we are still in it,
|
||||||
@@ -151,7 +155,11 @@ function GetJSONIndent()
|
|||||||
if line =~ '[[({]'
|
if line =~ '[[({]'
|
||||||
let counts = s:LineHasOpeningBrackets(lnum)
|
let counts = s:LineHasOpeningBrackets(lnum)
|
||||||
if counts[0] == '1' || counts[1] == '1' || counts[2] == '1'
|
if counts[0] == '1' || counts[1] == '1' || counts[2] == '1'
|
||||||
return ind + shiftwidth()
|
if exists('*shiftwidth')
|
||||||
|
return ind + shiftwidth()
|
||||||
|
else
|
||||||
|
return ind + &sw
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
call cursor(v:lnum, vcol)
|
call cursor(v:lnum, vcol)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'json') == -1
|
|||||||
" Maintainer: Eli Parra <eli@elzr.com> https://github.com/elzr/vim-json
|
" Maintainer: Eli Parra <eli@elzr.com> https://github.com/elzr/vim-json
|
||||||
" Last Change: 2014-12-20 Load ftplugin/json.vim
|
" Last Change: 2014-12-20 Load ftplugin/json.vim
|
||||||
|
|
||||||
|
" Reload the definition of g:vim_json_syntax_conceal
|
||||||
|
" see https://github.com/elzr/vim-json/issues/42
|
||||||
|
runtime! ftplugin/json.vim
|
||||||
|
|
||||||
if !exists("main_syntax")
|
if !exists("main_syntax")
|
||||||
if version < 600
|
if version < 600
|
||||||
syntax clear
|
syntax clear
|
||||||
@@ -16,10 +20,16 @@ endif
|
|||||||
|
|
||||||
syntax match jsonNoise /\%(:\|,\)/
|
syntax match jsonNoise /\%(:\|,\)/
|
||||||
|
|
||||||
|
" NOTE that for the concealing to work your conceallevel should be set to 2
|
||||||
|
|
||||||
" Syntax: Strings
|
" Syntax: Strings
|
||||||
" Separated into a match and region because a region by itself is always greedy
|
" Separated into a match and region because a region by itself is always greedy
|
||||||
syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze[[:blank:]\r\n]*[,}\]]/ contains=jsonString
|
syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze[[:blank:]\r\n]*[,}\]]/ contains=jsonString
|
||||||
syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained
|
if has('conceal') && g:vim_json_syntax_conceal == 1
|
||||||
|
syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained
|
||||||
|
else
|
||||||
|
syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained
|
||||||
|
endif
|
||||||
|
|
||||||
" Syntax: JSON does not allow strings with single quotes, unlike JavaScript.
|
" Syntax: JSON does not allow strings with single quotes, unlike JavaScript.
|
||||||
syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
|
syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
|
||||||
@@ -27,7 +37,11 @@ syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
|
|||||||
" Syntax: JSON Keywords
|
" Syntax: JSON Keywords
|
||||||
" Separated into a match and region because a region by itself is always greedy
|
" Separated into a match and region because a region by itself is always greedy
|
||||||
syn match jsonKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword
|
syn match jsonKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword
|
||||||
syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contains=jsonEscape contained
|
if has('conceal') && g:vim_json_syntax_conceal == 1
|
||||||
|
syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contains=jsonEscape contained
|
||||||
|
else
|
||||||
|
syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contains=jsonEscape contained
|
||||||
|
endif
|
||||||
|
|
||||||
" Syntax: Escape sequences
|
" Syntax: Escape sequences
|
||||||
syn match jsonEscape "\\["\\/bfnrt]" contained
|
syn match jsonEscape "\\["\\/bfnrt]" contained
|
||||||
@@ -37,31 +51,33 @@ syn match jsonEscape "\\u\x\{4}" contained
|
|||||||
syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>\ze[[:blank:]\r\n]*[,}\]]"
|
syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>\ze[[:blank:]\r\n]*[,}\]]"
|
||||||
|
|
||||||
" ERROR WARNINGS **********************************************
|
" ERROR WARNINGS **********************************************
|
||||||
" Syntax: Strings should always be enclosed with quotes.
|
if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1)
|
||||||
syn match jsonNoQuotesError "\<[[:alpha:]][[:alnum:]]*\>"
|
" Syntax: Strings should always be enclosed with quotes.
|
||||||
syn match jsonTripleQuotesError /"""/
|
syn match jsonNoQuotesError "\<[[:alpha:]][[:alnum:]]*\>"
|
||||||
|
syn match jsonTripleQuotesError /"""/
|
||||||
|
|
||||||
" Syntax: An integer part of 0 followed by other digits is not allowed.
|
" Syntax: An integer part of 0 followed by other digits is not allowed.
|
||||||
syn match jsonNumError "-\=\<0\d\.\d*\>"
|
syn match jsonNumError "-\=\<0\d\.\d*\>"
|
||||||
|
|
||||||
" Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1).
|
" Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1).
|
||||||
syn match jsonNumError "\:\@<=[[:blank:]\r\n]*\zs\.\d\+"
|
syn match jsonNumError "\:\@<=[[:blank:]\r\n]*\zs\.\d\+"
|
||||||
|
|
||||||
" Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file
|
" Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file
|
||||||
syn match jsonCommentError "//.*"
|
syn match jsonCommentError "//.*"
|
||||||
syn match jsonCommentError "\(/\*\)\|\(\*/\)"
|
syn match jsonCommentError "\(/\*\)\|\(\*/\)"
|
||||||
|
|
||||||
" Syntax: No semicolons in JSON
|
" Syntax: No semicolons in JSON
|
||||||
syn match jsonSemicolonError ";"
|
syn match jsonSemicolonError ";"
|
||||||
|
|
||||||
" Syntax: No trailing comma after the last element of arrays or objects
|
" Syntax: No trailing comma after the last element of arrays or objects
|
||||||
syn match jsonTrailingCommaError ",\_s*[}\]]"
|
syn match jsonTrailingCommaError ",\_s*[}\]]"
|
||||||
|
|
||||||
" Syntax: Watch out for missing commas between elements
|
" Syntax: Watch out for missing commas between elements
|
||||||
syn match jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/
|
syn match jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/
|
||||||
syn match jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values
|
syn match jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values
|
||||||
syn match jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array
|
syn match jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array
|
||||||
syn match jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value
|
syn match jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value
|
||||||
|
endif
|
||||||
|
|
||||||
" ********************************************** END OF ERROR WARNINGS
|
" ********************************************** END OF ERROR WARNINGS
|
||||||
" Allowances for JSONP: function call at the beginning of the file,
|
" Allowances for JSONP: function call at the beginning of the file,
|
||||||
@@ -87,20 +103,22 @@ if version >= 508 || !exists("did_json_syn_inits")
|
|||||||
hi def link jsonString String
|
hi def link jsonString String
|
||||||
hi def link jsonTest Label
|
hi def link jsonTest Label
|
||||||
hi def link jsonEscape Special
|
hi def link jsonEscape Special
|
||||||
hi def link jsonNumber Number
|
hi def link jsonNumber Delimiter
|
||||||
hi def link jsonBraces Delimiter
|
hi def link jsonBraces Delimiter
|
||||||
hi def link jsonNull Function
|
hi def link jsonNull Function
|
||||||
hi def link jsonBoolean Boolean
|
hi def link jsonBoolean Delimiter
|
||||||
hi def link jsonKeyword Label
|
hi def link jsonKeyword Label
|
||||||
|
|
||||||
hi def link jsonNumError Error
|
if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1)
|
||||||
hi def link jsonCommentError Error
|
hi def link jsonNumError Error
|
||||||
hi def link jsonSemicolonError Error
|
hi def link jsonCommentError Error
|
||||||
hi def link jsonTrailingCommaError Error
|
hi def link jsonSemicolonError Error
|
||||||
hi def link jsonMissingCommaError Error
|
hi def link jsonTrailingCommaError Error
|
||||||
hi def link jsonStringSQError Error
|
hi def link jsonMissingCommaError Error
|
||||||
hi def link jsonNoQuotesError Error
|
hi def link jsonStringSQError Error
|
||||||
hi def link jsonTripleQuotesError Error
|
hi def link jsonNoQuotesError Error
|
||||||
|
hi def link jsonTripleQuotesError Error
|
||||||
|
endif
|
||||||
hi def link jsonQuote Quote
|
hi def link jsonQuote Quote
|
||||||
hi def link jsonNoise Noise
|
hi def link jsonNoise Noise
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user