mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 23:50:04 +08:00
feat(toml): add lua toml previewer
This commit is contained in:
parent
bd43325d33
commit
0b2a3e7e4b
11
bundle/vim-toml/autoload/toml.vim
vendored
11
bundle/vim-toml/autoload/toml.vim
vendored
@ -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
|
||||
|
||||
|
38
lua/spacevim/plugin/tomlprew.lua
Normal file
38
lua/spacevim/plugin/tomlprew.lua
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user