diff --git a/bundle/vim-toml/autoload/toml.vim b/bundle/vim-toml/autoload/toml.vim index 749e78a90..5675ed91f 100644 --- a/bundle/vim-toml/autoload/toml.vim +++ b/bundle/vim-toml/autoload/toml.vim @@ -6,6 +6,17 @@ " License: GPLv3 "============================================================================= +if has('nvim-0.9.0') + function! toml#preview() abort + + lua require('spacevim.plugin.tomlprew').preview() + + endfunction + + finish +endif + + let s:preview_bufnr = -1 let s:toml_bufnr = -1 diff --git a/lua/spacevim/plugin/tomlprew.lua b/lua/spacevim/plugin/tomlprew.lua new file mode 100644 index 000000000..5da077a5b --- /dev/null +++ b/lua/spacevim/plugin/tomlprew.lua @@ -0,0 +1,38 @@ +--============================================================================= +-- tomlprew.lua --- toml to json +-- Copyright (c) 2016-2022 Wang Shidong & Contributors +-- Author: Wang Shidong < wsdjeg@outlook.com > +-- URL: https://spacevim.org +-- License: GPLv3 +--============================================================================= + +local toml = require('spacevim.api.data.toml') + +local M = {} + + +function M.preview() + + local bufnr = vim.fn.bufnr() + local context = table.concat(vim.api.nvim_buf_get_lines(bufnr, 0, -1, false), '\n') + local js = toml.parse(context) + vim.cmd([[ + silent only + rightbelow vsplit __toml_json_preview__.json + set ft=SpaceVimTomlViewer + setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber winfixwidth + setlocal modifiable + ]]) + bufnr = vim.fn.bufnr() + vim.api.nvim_buf_set_lines(bufnr, 1, -1, false, vim.split(vim.json.encode(js), '\n')) + vim.cmd([[ + silent Neoformat! json + setlocal nomodifiable + set syntax=json + ]]) + + +end + + +return M