mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-24 06:40:05 +08:00
34 lines
1.1 KiB
VimL
34 lines
1.1 KiB
VimL
"=============================================================================
|
|
" toml.vim --- toml autoload plugin
|
|
" Copyright (c) 2016-2019 Wang Shidong & Contributors
|
|
" Author: Wang Shidong < wsdjeg@outlook.com >
|
|
" URL: https://spacevim.org
|
|
" License: GPLv3
|
|
"=============================================================================
|
|
|
|
|
|
let s:preview_bufnr = -1
|
|
let s:toml_bufnr = -1
|
|
|
|
let s:TOML = SpaceVim#api#import('data#toml')
|
|
let s:JSON = SpaceVim#api#import('data#json')
|
|
|
|
function! toml#preview() abort
|
|
let s:toml_bufnr = bufnr()
|
|
let context = join(getbufline(s:toml_bufnr, 1, "$"), "\n")
|
|
let json_obj = s:TOML.parse(context)
|
|
let json = s:JSON.json_encode(json_obj)
|
|
" close other windows
|
|
silent only
|
|
" open preview windows
|
|
rightbelow vsplit __toml_json_preview__.json
|
|
set ft=SpaceVimTomlViewer
|
|
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber winfixwidth
|
|
let s:preview_bufnr = bufnr()
|
|
setlocal modifiable
|
|
call setline(1, json)
|
|
silent Neoformat! json
|
|
setlocal nomodifiable
|
|
set syntax=json
|
|
endfunction
|