diff options
| author | Adam Stankiewicz <sheerun@sher.pl> | 2016-07-26 13:50:28 +0200 | 
|---|---|---|
| committer | Adam Stankiewicz <sheerun@sher.pl> | 2016-07-26 13:52:30 +0200 | 
| commit | acd25ccf95f25ce2d93c92a45c9229531539249d (patch) | |
| tree | 074d27c8f77c40c4f91c7fdc8db6ad9b0e91e4f1 | |
| parent | 7dd62806a06af3cf2410cd8a4f83205269f279de (diff) | |
| download | vim-polyglot-acd25ccf95f25ce2d93c92a45c9229531539249d.tar.gz vim-polyglot-acd25ccf95f25ce2d93c92a45c9229531539249d.zip | |
Switch to elzr for json syntax, and disable conceal by default
Diffstat (limited to '')
| -rw-r--r-- | README.md | 2 | ||||
| -rwxr-xr-x | build | 2 | ||||
| -rw-r--r-- | config.vim | 5 | ||||
| -rw-r--r-- | ftdetect/polyglot.vim | 10 | ||||
| -rw-r--r-- | ftplugin/json.vim | 42 | ||||
| -rw-r--r-- | indent/json.vim | 14 | ||||
| -rw-r--r-- | syntax/json.vim | 80 | 
7 files changed, 117 insertions, 38 deletions
| @@ -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)  - [jasmine](https://github.com/glanotte/vim-jasmine) (syntax, 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)  - [jsx](https://github.com/mxw/vim-jsx) (ftdetect, after)  - [julia](https://github.com/dcjones/julia-minimalist-vim) (syntax, indent, ftdetect) @@ -130,7 +130,7 @@ PACKS="    html5:othree/html5.vim    jasmine:glanotte/vim-jasmine    javascript:pangloss/vim-javascript -  json:sheerun/vim-json +  json:elzr/vim-json    jst:briancollins/vim-jst    jsx:mxw/vim-jsx:_ALL    julia:dcjones/julia-minimalist-vim @@ -2,3 +2,8 @@  if !exists('g:jsx_ext_required')    let g:jsx_ext_required = 0  endif + +" Disable json concealing by default +if !exists('g:vim_json_syntax_conceal') +  let g:vim_json_syntax_conceal = 0 +endif diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index c6e16496..6e032523 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -2,6 +2,11 @@  if !exists('g:jsx_ext_required')    let g:jsx_ext_required = 0  endif + +" Disable json concealing by default +if !exists('g:vim_json_syntax_conceal') +  let g:vim_json_syntax_conceal = 0 +endif  " ftdetect/ansible.vim  if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1 @@ -404,8 +409,9 @@ endif  " ftdetect/json.vim  if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'json') == -1 -autocmd BufNewFile,BufRead *.json set filetype=json -autocmd BufNewFile,BufRead *.jsonp set filetype=json +autocmd BufNewFile,BufRead *.json setlocal filetype=json +autocmd BufNewFile,BufRead *.jsonp setlocal filetype=json +autocmd BufNewFile,BufRead *.geojson setlocal filetype=json  endif diff --git a/ftplugin/json.vim b/ftplugin/json.vim new file mode 100644 index 00000000..3f4adccd --- /dev/null +++ b/ftplugin/json.vim @@ -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 diff --git a/indent/json.vim b/indent/json.vim index 912bbfcf..7db3586e 100644 --- a/indent/json.vim +++ b/indent/json.vim @@ -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.  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  " 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 s:Match(lnum, s:block_regex) -    " return indent(lnum) + shiftwidth() +  "   if exists('*shiftwidth') +  "     return indent(lnum) + shiftwidth() +  "   else +  "     return indent(lnum) + &sw +  "   endif    " endif    " If the previous line contained an opening bracket, and we are still in it, @@ -151,7 +155,11 @@ function GetJSONIndent()    if line =~ '[[({]'      let counts = s:LineHasOpeningBrackets(lnum)      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        call cursor(v:lnum, vcol)      end diff --git a/syntax/json.vim b/syntax/json.vim index 25989ead..48bc18e1 100644 --- a/syntax/json.vim +++ b/syntax/json.vim @@ -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  " 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 version < 600      syntax clear @@ -16,10 +20,16 @@ endif  syntax match   jsonNoise           /\%(:\|,\)/ +" NOTE that for the concealing to work your conceallevel should be set to 2 +  " Syntax: Strings  " Separated into a match and region because a region by itself is always greedy  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.  syn region  jsonStringSQError oneline  start=+'+  skip=+\\\\\|\\"+  end=+'+ @@ -27,7 +37,11 @@ syn region  jsonStringSQError oneline  start=+'+  skip=+\\\\\|\\"+  end=+'+  " Syntax: JSON Keywords  " Separated into a match and region because a region by itself is always greedy  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  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]*[,}\]]"  " ERROR WARNINGS ********************************************** -" Syntax: Strings should always be enclosed with quotes. -syn match   jsonNoQuotesError  "\<[[:alpha:]][[:alnum:]]*\>" -syn match   jsonTripleQuotesError  /"""/ +if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) +	" Syntax: Strings should always be enclosed with quotes. +	syn match   jsonNoQuotesError  "\<[[:alpha:]][[:alnum:]]*\>" +	syn match   jsonTripleQuotesError  /"""/ -" Syntax: An integer part of 0 followed by other digits is not allowed. -syn match   jsonNumError  "-\=\<0\d\.\d*\>" +	" Syntax: An integer part of 0 followed by other digits is not allowed. +	syn match   jsonNumError  "-\=\<0\d\.\d*\>" -" Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1). -syn match   jsonNumError  "\:\@<=[[:blank:]\r\n]*\zs\.\d\+" +	" Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1). +	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 -syn match   jsonCommentError  "//.*" -syn match   jsonCommentError  "\(/\*\)\|\(\*/\)" +	" Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file +	syn match   jsonCommentError  "//.*" +	syn match   jsonCommentError  "\(/\*\)\|\(\*/\)" -" Syntax: No semicolons in JSON -syn match   jsonSemicolonError  ";" +	" Syntax: No semicolons in JSON +	syn match   jsonSemicolonError  ";" -" Syntax: No trailing comma after the last element of arrays or objects -syn match   jsonTrailingCommaError  ",\_s*[}\]]" +	" Syntax: No trailing comma after the last element of arrays or objects +	syn match   jsonTrailingCommaError  ",\_s*[}\]]" -" Syntax: Watch out for missing commas between elements -syn match   jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/ -syn match   jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values -syn match   jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array -syn match   jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value +	" Syntax: Watch out for missing commas between elements +	syn match   jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/ +	syn match   jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values +	syn match   jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array +	syn match   jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value +endif  " ********************************************** END OF ERROR WARNINGS  " 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 jsonTest			Label    hi def link jsonEscape		Special -  hi def link jsonNumber		Number +  hi def link jsonNumber		Delimiter    hi def link jsonBraces		Delimiter    hi def link jsonNull			Function -  hi def link jsonBoolean		Boolean +  hi def link jsonBoolean		Delimiter    hi def link jsonKeyword		Label -  hi def link jsonNumError					Error -  hi def link jsonCommentError				Error -  hi def link jsonSemicolonError			Error -  hi def link jsonTrailingCommaError		Error -  hi def link jsonMissingCommaError		Error -  hi def link jsonStringSQError				Error -  hi def link jsonNoQuotesError				Error -  hi def link jsonTripleQuotesError		Error +	if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) +		hi def link jsonNumError					Error +		hi def link jsonCommentError				Error +		hi def link jsonSemicolonError			Error +		hi def link jsonTrailingCommaError		Error +		hi def link jsonMissingCommaError		Error +		hi def link jsonStringSQError				Error +		hi def link jsonNoQuotesError				Error +		hi def link jsonTripleQuotesError		Error +  endif    hi def link jsonQuote			Quote    hi def link jsonNoise			Noise  endif | 
