Skip to content
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

Bad initialization: "set conceallevel" #104

Open
lervag opened this issue Jan 18, 2021 · 2 comments · May be fixed by #108
Open

Bad initialization: "set conceallevel" #104

lervag opened this issue Jan 18, 2021 · 2 comments · May be fixed by #108

Comments

@lervag
Copy link

lervag commented Jan 18, 2021

Loading syntax/json.vim currently loads ftplugin/json.vim, which sets conceallevel. This is IMHO bad practise. For instance, if you load nested syntax in Markdown, LaTeX or similar, it should not affect the current filetype settings.

I noticed this:

" Reload the definition of g:vim_json_syntax_conceal
" see https://github.com/elzr/vim-json/issues/42
runtime! ftplugin/json.vim

Thus, #42 concluded that runtime! ftplugin/json.vim is necessary, but I propose it is not. Instead, you should replace the use of the option g:vim_json_syntax_conceal with get(g:, 'vim_json_syntax_conceal', 1) (or 0, if that's the default). Or, use a plugin/json.vim to set default values for the options. Or an autoload function. Whatever, but don't load ftplugin/json.vim.


I notice that the repo seems relatively unmaintained, but I hope it might be possible to fix this regardless.

@pjfalbe
Copy link

pjfalbe commented Apr 28, 2021

I'm looking to try this module. What did you put in your .vimrc to load this plugin?

nfischer added a commit to nfischer/vim-json that referenced this issue May 19, 2024
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
@nfischer nfischer linked a pull request May 19, 2024 that will close this issue
@nfischer
Copy link

I ran into this same issue today. I sent PR #108 to hopefully fix this properly, which guards with exists() expressions based on how vim's builtin json plugin works:

https://github.com/vim/vim/blob/5f1b115afd92544ce64d563da0d8ee9844abb10a/runtime/syntax/json.vim#L34


In case the PR doesn't merge, here are some workarounds I figured out today:

  1. In my case, the bug only repros if I have let g:markdown_fenced_languages = [ 'json', ... ] in my vimrc. Removing json from the list fixes the issue and lets markdown files render properly again. json files will still have conceallevel=2, as configured by the ftplugin script in this plugin.
  2. If you can't live without g:markdown_fenced_languages, then an autocmd seems to also do the trick: autocmd BufNewfile,BufReadPost *.md setlocal conceallevel=0
  3. If that doesn't work, you can explicitly set let g:vim_json_syntax_conceal = 0 but then you won't get concealing in json files anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants