Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
143 lines
4.5 KiB
VimL
143 lines
4.5 KiB
VimL
"=============================================================================
|
|
" format.vim --- format Layer file for SpaceVim
|
|
" Copyright (c) 2012-2022 Shidong Wang & Contributors
|
|
" Author: Shidong Wang < wsdjeg@outlook.com >
|
|
" URL: https://spacevim.org
|
|
" License: GPLv3
|
|
"=============================================================================
|
|
|
|
""
|
|
" @section format, layers-format
|
|
" @parentsection layers
|
|
" `format` layer provides code formation for SpaceVim, the default formatting
|
|
" plugin is `neoformat`, and you can also use `vim-codefmt`.
|
|
"
|
|
" @subsection layer options
|
|
"
|
|
" 1. `format_on_save`: disabled by default.
|
|
" 2. `format_method`: set the format plugin, default plugin is `neoformat`.
|
|
" You can also use `vim-codefmt` or `format.nvim`, `format.nvim` requires
|
|
" neovim 0.9.0+.
|
|
" 3. `silent_format`: Runs the formatter without any messages.
|
|
" 4. `format_notify_width`: set the neoformat notify window width.
|
|
" 5. `format_notify_timeout`: set the neoformat notify clear timeout. default
|
|
" is 5000 milliseconds.
|
|
"
|
|
" @subsection key bindings
|
|
" >
|
|
" Key binding Description
|
|
" SPC b f format current buffer or selection lines
|
|
" <
|
|
"
|
|
|
|
if exists('s:format_on_save')
|
|
finish
|
|
else
|
|
let s:format_method = 'neoformat'
|
|
let s:format_on_save = 0
|
|
let s:silent_format = 0
|
|
let s:format_ft = []
|
|
let s:format_notify_timeout = 5000
|
|
let s:format_notify_width = &columns * 0.50
|
|
endif
|
|
|
|
function! SpaceVim#layers#format#health() abort
|
|
call SpaceVim#layers#format#plugins()
|
|
call SpaceVim#layers#format#config()
|
|
return 1
|
|
endfunction
|
|
|
|
function! SpaceVim#layers#format#plugins() abort
|
|
if s:format_method ==# 'neoformat'
|
|
return [
|
|
\ [g:_spacevim_root_dir . 'bundle/neoformat', {'merged' : 0, 'loadconf' : 1, 'loadconf_before' : 1}],
|
|
\ ]
|
|
elseif s:format_method ==# 'codefmt'
|
|
return [
|
|
\ ['google/vim-maktaba', {'merged' : 0}],
|
|
\ ['google/vim-glaive', {'merged' : 0, 'loadconf' : 1}],
|
|
\ ['google/vim-codefmt', {'merged' : 0}],
|
|
\ ]
|
|
elseif s:format_method ==# 'format.nvim'
|
|
return [
|
|
\ [g:_spacevim_root_dir . 'bundle/format.nvim', {'merged' : 0, 'loadconf' : 1, 'loadconf_before' : 1}],
|
|
\ ]
|
|
endif
|
|
endfunction
|
|
|
|
function! SpaceVim#layers#format#config() abort
|
|
|
|
if s:format_method ==# 'neoformat'
|
|
call SpaceVim#mapping#space#def('nnoremap', ['b', 'f'], ":Neoformat\<Cr>", 'format-code', 0, 1)
|
|
elseif s:format_method ==# 'codefmt'
|
|
call SpaceVim#mapping#space#def('nnoremap', ['b', 'f'], 'FormatCode', 'format-code', 1)
|
|
elseif s:format_method ==# 'format.nvim'
|
|
call SpaceVim#mapping#space#def('nnoremap', ['b', 'f'], ":Format\<Cr>", 'format-code', 0, 1)
|
|
endif
|
|
augroup spacevim_layer_format
|
|
autocmd!
|
|
if s:silent_format
|
|
autocmd BufWritePre * silent! call s:format()
|
|
else
|
|
autocmd BufWritePre * call s:format()
|
|
endif
|
|
augroup END
|
|
endfunction
|
|
|
|
function! SpaceVim#layers#format#set_variable(var) abort
|
|
if has_key(a:var, 'format_method') && a:var.format_method ==# 'format.nvim' && !has('nvim-0.9.0')
|
|
call SpaceVim#logger#info('format.nvim requires neovim 0.9.0+')
|
|
else
|
|
let s:format_method = get(a:var, 'format_method', s:format_method)
|
|
endif
|
|
let s:format_on_save = get(a:var, 'format_on_save', s:format_on_save)
|
|
let s:silent_format = get(a:var, 'silent_format', s:silent_format)
|
|
let s:format_notify_width = get(a:var, 'format_notify_width', s:format_notify_width)
|
|
let s:format_notify_timeout = get(a:var, 'format_notify_timeout', s:format_notify_timeout)
|
|
endfunction
|
|
|
|
function! SpaceVim#layers#format#get_format_option() abort
|
|
|
|
return {
|
|
\ 'format_notify_width' : s:format_notify_width,
|
|
\ 'format_notify_timeout' : s:format_notify_timeout,
|
|
\ }
|
|
|
|
endfunction
|
|
|
|
function! SpaceVim#layers#format#get_options() abort
|
|
return ['format_method', 'format_on_save', 'silent_format']
|
|
endfunction
|
|
|
|
function! SpaceVim#layers#format#add_filetype(ft) abort
|
|
if get(a:ft, 'enable', 0)
|
|
if index(s:format_ft, a:ft.filetype) ==# -1
|
|
call add(s:format_ft, a:ft.filetype)
|
|
endif
|
|
else
|
|
if index(s:format_ft, a:ft.filetype) !=# -1
|
|
call remove(s:format_ft, a:ft.filetype)
|
|
endif
|
|
endif
|
|
endfunction
|
|
|
|
function! s:format() abort
|
|
if !empty(&ft) &&
|
|
\ ( index(s:format_ft, &ft) !=# -1 || s:format_on_save ==# 1)
|
|
|
|
if s:format_method ==# 'neoformat'
|
|
undojoin | Neoformat
|
|
elseif s:format_method ==# 'codefmt'
|
|
undojoin | FormatCode
|
|
elseif s:format_method ==# 'format.nvim'
|
|
undojoin | Format
|
|
endif
|
|
endif
|
|
endfunction
|
|
|
|
function! SpaceVim#layers#format#loadable() abort
|
|
|
|
return 1
|
|
|
|
endfunction
|