Skip to content

Commit 5c146c4

Browse files
committed
fix: don't set conceallevel from syntax plugin
I noticed that when I load a markdown file in vim, the `vim-json` file automatically runs `set conceallevel=2`. There's a few configs which are necessary to reproduce this: 1. vimrc should have `let g:markdown_fenced_languages = [ 'json', ... ]` 2. Install `elzr/vim-json` plugin 3. Load any markdown file When these conditions are met, the markdown plugin will load the `vim-json/syntax/json.vim` script. The problem is that this script does something unusual by also loading the corresponding `ftplugin` script. Since loading the `ftplugin` script is the root cause, the fix is to stop loading this script. Because the `g:vim_json_syntax_conceal` plugin might be uninitialized now, this guards the references with `exists()` expressions. This is the same pattern as used in the builtin json syntax plugin (`vim/runtime/syntax/json.vim`). I tested this with: * `set conceallevel=2 | let g:vim_json_syntax_conceal = 0` * `set conceallevel=0 | let g:vim_json_syntax_conceal = 1` * and also with default settings Fixes elzr#104
1 parent 3727f08 commit 5c146c4

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

syntax/json.vim

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
" Maintainer: Eli Parra <eli@elzr.com> https://github.com/elzr/vim-json
44
" Last Change: 2014-12-20 Load ftplugin/json.vim
55

6-
" Reload the definition of g:vim_json_syntax_conceal
7-
" see https://github.com/elzr/vim-json/issues/42
8-
runtime! ftplugin/json.vim
9-
106
if !exists("main_syntax")
117
if version < 600
128
syntax clear
@@ -23,7 +19,7 @@ syntax match jsonNoise /\%(:\|,\)/
2319
" Syntax: Strings
2420
" Separated into a match and region because a region by itself is always greedy
2521
syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze[[:blank:]\r\n]*[,}\]]/ contains=jsonString
26-
if has('conceal') && g:vim_json_syntax_conceal == 1
22+
if has('conceal') && (!exists('g:vim_json_syntax_conceal') || g:vim_json_syntax_conceal == 1)
2723
syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained
2824
else
2925
syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained
@@ -35,7 +31,7 @@ syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
3531
" Syntax: JSON Keywords
3632
" Separated into a match and region because a region by itself is always greedy
3733
syn match jsonKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword
38-
if has('conceal') && g:vim_json_syntax_conceal == 1
34+
if has('conceal') && (!exists('g:vim_json_syntax_conceal') || g:vim_json_syntax_conceal == 1)
3935
syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contains=jsonEscape contained
4036
else
4137
syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contains=jsonEscape contained

0 commit comments

Comments
 (0)