mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:40:06 +08:00
feat(lang#toml): add SPC l j
to preview toml
This commit is contained in:
parent
fcb9f0785a
commit
0e9127e4dc
@ -545,6 +545,8 @@ function! SpaceVim#layers#core#statusline#get(...) abort
|
||||
return '%#SpaceVim_statusline_a# Transient State %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
||||
elseif &filetype ==# 'SpaceVimLog'
|
||||
return '%#SpaceVim_statusline_a# SpaceVim Runtime log %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
||||
elseif &filetype ==# 'SpaceVimTomlViewer'
|
||||
return '%#SpaceVim_statusline_a# Toml Json Viewer %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
||||
elseif &filetype ==# 'vimcalc'
|
||||
return '%#SpaceVim_statusline_a#' . s:winnr() . ' VimCalc %#SpaceVim_statusline_a_SpaceVim_statusline_b#'
|
||||
elseif &filetype ==# 'HelpDescribe'
|
||||
|
@ -17,10 +17,18 @@
|
||||
|
||||
function! SpaceVim#layers#lang#toml#plugins() abort
|
||||
let plugins = []
|
||||
call add(plugins, ['cespare/vim-toml', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-toml', {'merged' : 0}])
|
||||
return plugins
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#lang#toml#config() abort
|
||||
call SpaceVim#mapping#space#regesit_lang_mappings('toml', function('s:toml_lang_mappings'))
|
||||
endfunction
|
||||
|
||||
function! s:toml_lang_mappings() abort
|
||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','j'], 'call toml#preview()', 'toml-to-json', 1)
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#lang#toml#health() abort
|
||||
call SpaceVim#layers#lang#toml#plugins()
|
||||
return 1
|
||||
|
@ -6,6 +6,7 @@ In `bundle/` directory, there are two kinds of plugins: forked plugins without c
|
||||
|
||||
- `vim-bookmarks`: based on [`MattesGroeger/vim-bookmarks@3adeae1`](https://github.com/MattesGroeger/vim-bookmarks/commit/3adeae10639edcba29ea80dafa1c58cf545cb80e)
|
||||
- `delimitMate`: based on [`Raimondi/delimitMate@537a1da`](https://github.com/Raimondi/delimitMate/tree/537a1da0fa5eeb88640425c37e545af933c56e1b)
|
||||
- `vim-toml`: based on [cespare/vim-toml@717bd87ef9](https://github.com/cespare/vim-toml/tree/717bd87ef928293e0cc6cfc12ebf2e007cb25311)
|
||||
|
||||
### No changed plugins
|
||||
|
||||
|
22
bundle/vim-toml/LICENSE
Normal file
22
bundle/vim-toml/LICENSE
Normal file
@ -0,0 +1,22 @@
|
||||
Copyright (c) 2013 Caleb Spare
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
40
bundle/vim-toml/README.md
Normal file
40
bundle/vim-toml/README.md
Normal file
@ -0,0 +1,40 @@
|
||||
# vim-toml
|
||||
|
||||
Vim syntax for [TOML](https://github.com/toml-lang/toml).
|
||||
|
||||
## Installation
|
||||
|
||||
### Vim packages (recommended; Vim 8+ only)
|
||||
|
||||
Clone or submodule this repo into your Vim packages location. Example:
|
||||
|
||||
```
|
||||
mkdir -p ~/.vim/pack/plugins/start
|
||||
cd ~/.vim/pack/plugins/start
|
||||
git clone https://github.com/cespare/vim-toml.git
|
||||
```
|
||||
|
||||
### Pathogen
|
||||
|
||||
Set up [Pathogen](https://github.com/tpope/vim-pathogen) then clone/submodule
|
||||
this repo into `~/.vim/bundle/toml`, or wherever you've pointed your Pathogen.
|
||||
|
||||
### Vundle
|
||||
|
||||
Set up [Vundle](https://github.com/VundleVim/Vundle.vim) then add `Plugin
|
||||
'cespare/vim-toml'` to your vimrc and run `:PluginInstall` from a fresh vim.
|
||||
|
||||
### vim-plug
|
||||
|
||||
Set up [vim-plug](https://github.com/junegunn/vim-plug). In your .vimrc, between
|
||||
the lines for `call plug#begin()` and `call plug#end()`, add the line `Plug
|
||||
'cespare/vim-toml', { 'branch': 'main' }`. Reload your .vimrc and then run `:PlugInstall`.
|
||||
|
||||
### Janus
|
||||
|
||||
Set up [Janus](https://github.com/carlhuda/janus) and then clone/submodule this
|
||||
repo into `~/.janus` and restart vim.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are very welcome! Just open a PR.
|
33
bundle/vim-toml/autoload/toml.vim
Normal file
33
bundle/vim-toml/autoload/toml.vim
Normal file
@ -0,0 +1,33 @@
|
||||
"=============================================================================
|
||||
" 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__
|
||||
set ft=SpaceVimTomlViewer
|
||||
set syntax=json
|
||||
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)
|
||||
Neoformat! json
|
||||
setlocal nomodifiable
|
||||
endfunction
|
2
bundle/vim-toml/ftdetect/toml.vim
Normal file
2
bundle/vim-toml/ftdetect/toml.vim
Normal file
@ -0,0 +1,2 @@
|
||||
" Go dep and Rust use several TOML config files that are not named with .toml.
|
||||
autocmd BufNewFile,BufRead *.toml,Gopkg.lock,Cargo.lock,*/.cargo/config,*/.cargo/credentials,Pipfile set filetype=toml
|
23
bundle/vim-toml/ftplugin/toml.vim
Normal file
23
bundle/vim-toml/ftplugin/toml.vim
Normal file
@ -0,0 +1,23 @@
|
||||
" Vim filetype plugin
|
||||
" Language: TOML
|
||||
" Homepage: https://github.com/cespare/vim-toml
|
||||
" Maintainer: Aman Verma
|
||||
" Author: Kevin Ballard <kevin@sb.org>
|
||||
" Last Change: Sep 21, 2021
|
||||
|
||||
if exists('b:did_ftplugin')
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
let b:undo_ftplugin = 'setlocal commentstring< comments<'
|
||||
|
||||
setlocal commentstring=#\ %s
|
||||
setlocal comments=:#
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim: et sw=2 sts=2
|
81
bundle/vim-toml/syntax/toml.vim
Normal file
81
bundle/vim-toml/syntax/toml.vim
Normal file
@ -0,0 +1,81 @@
|
||||
" Vim syntax file
|
||||
" Language: TOML
|
||||
" Homepage: https://github.com/cespare/vim-toml
|
||||
" Maintainer: Aman Verma
|
||||
" Previous Maintainer: Caleb Spare <cespare@gmail.com>
|
||||
" Last Change: Oct 8, 2021
|
||||
|
||||
if exists('b:current_syntax')
|
||||
finish
|
||||
endif
|
||||
|
||||
syn match tomlEscape /\\[btnfr"/\\]/ display contained
|
||||
syn match tomlEscape /\\u\x\{4}/ contained
|
||||
syn match tomlEscape /\\U\x\{8}/ contained
|
||||
syn match tomlLineEscape /\\$/ contained
|
||||
|
||||
" Basic strings
|
||||
syn region tomlString oneline start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=tomlEscape
|
||||
" Multi-line basic strings
|
||||
syn region tomlString start=/"""/ end=/"""/ contains=tomlEscape,tomlLineEscape
|
||||
" Literal strings
|
||||
syn region tomlString oneline start=/'/ end=/'/
|
||||
" Multi-line literal strings
|
||||
syn region tomlString start=/'''/ end=/'''/
|
||||
|
||||
syn match tomlInteger /[+-]\=\<[1-9]\(_\=\d\)*\>/ display
|
||||
syn match tomlInteger /[+-]\=\<0\>/ display
|
||||
syn match tomlInteger /[+-]\=\<0x[[:xdigit:]]\(_\=[[:xdigit:]]\)*\>/ display
|
||||
syn match tomlInteger /[+-]\=\<0o[0-7]\(_\=[0-7]\)*\>/ display
|
||||
syn match tomlInteger /[+-]\=\<0b[01]\(_\=[01]\)*\>/ display
|
||||
syn match tomlInteger /[+-]\=\<\(inf\|nan\)\>/ display
|
||||
|
||||
syn match tomlFloat /[+-]\=\<\d\(_\=\d\)*\.\d\+\>/ display
|
||||
syn match tomlFloat /[+-]\=\<\d\(_\=\d\)*\(\.\d\(_\=\d\)*\)\=[eE][+-]\=\d\(_\=\d\)*\>/ display
|
||||
|
||||
syn match tomlBoolean /\<\%(true\|false\)\>/ display
|
||||
|
||||
" https://tools.ietf.org/html/rfc3339
|
||||
syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}/ display
|
||||
syn match tomlDate /\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?/ display
|
||||
syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}[T ]\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?\%(Z\|[+-]\d\{2\}:\d\{2\}\)\?/ display
|
||||
|
||||
syn match tomlDotInKey /\v[^.]+\zs\./ contained display
|
||||
syn match tomlKey /\v(^|[{,])\s*\zs[[:alnum:]._-]+\ze\s*\=/ contains=tomlDotInKey display
|
||||
syn region tomlKeyDq oneline start=/\v(^|[{,])\s*\zs"/ end=/"\ze\s*=/ contains=tomlEscape
|
||||
syn region tomlKeySq oneline start=/\v(^|[{,])\s*\zs'/ end=/'\ze\s*=/
|
||||
|
||||
syn region tomlTable oneline start=/^\s*\[[^\[]/ end=/\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey
|
||||
|
||||
syn region tomlTableArray oneline start=/^\s*\[\[/ end=/\]\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey
|
||||
|
||||
syn region tomlKeyValueArray start=/=\s*\[\zs/ end=/\]/ contains=@tomlValue
|
||||
|
||||
syn region tomlArray start=/\[/ end=/\]/ contains=@tomlValue contained
|
||||
|
||||
syn cluster tomlValue contains=tomlArray,tomlString,tomlInteger,tomlFloat,tomlBoolean,tomlDate,tomlComment
|
||||
|
||||
syn keyword tomlTodo TODO FIXME XXX BUG contained
|
||||
|
||||
syn match tomlComment /#.*/ contains=@Spell,tomlTodo
|
||||
|
||||
hi def link tomlComment Comment
|
||||
hi def link tomlTodo Todo
|
||||
hi def link tomlTableArray Title
|
||||
hi def link tomlTable Title
|
||||
hi def link tomlDotInKey Normal
|
||||
hi def link tomlKeySq Identifier
|
||||
hi def link tomlKeyDq Identifier
|
||||
hi def link tomlKey Identifier
|
||||
hi def link tomlDate Constant
|
||||
hi def link tomlBoolean Boolean
|
||||
hi def link tomlFloat Float
|
||||
hi def link tomlInteger Number
|
||||
hi def link tomlString String
|
||||
hi def link tomlLineEscape SpecialChar
|
||||
hi def link tomlEscape SpecialChar
|
||||
|
||||
syn sync minlines=500
|
||||
let b:current_syntax = 'toml'
|
||||
|
||||
" vim: et sw=2 sts=2
|
35
bundle/vim-toml/test/test.toml
Normal file
35
bundle/vim-toml/test/test.toml
Normal file
@ -0,0 +1,35 @@
|
||||
# Visual test file.
|
||||
# You can run
|
||||
#
|
||||
# nnoremap <F10> <cmd>echo synIDattr(synID(line('.'), col('.'), 1), 'name')<CR>
|
||||
#
|
||||
# and then press F10 to get the highlight group under the cursor.
|
||||
|
||||
# https://github.com/cespare/vim-toml/issues/9
|
||||
issue9 = [
|
||||
["a", "b", "c"]
|
||||
]
|
||||
|
||||
# https://github.com/cespare/vim-toml/issues/10
|
||||
issue10_1 = -12
|
||||
issue10_2 = +200.3
|
||||
|
||||
# https://github.com/cespare/vim-toml/issues/11
|
||||
issue11 = -210_000.0
|
||||
|
||||
# https://github.com/cespare/vim-toml/issues/13
|
||||
issue13 = { version="1.0", features=["derive"] }
|
||||
|
||||
# https://github.com/cespare/vim-toml/pull/52
|
||||
[foo.baz]
|
||||
apple.type = "fruit"
|
||||
3.14159 = "pi"
|
||||
"127.0.0.1" = "value"
|
||||
|
||||
[[foo.quux]]
|
||||
e = 2
|
||||
|
||||
# https://github.com/cespare/vim-toml/issues/58
|
||||
site."google.com" = true
|
||||
|
||||
# vim: et sw=2 sts=2
|
Loading…
Reference in New Issue
Block a user