1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 17:40:06 +08:00

feat(format): add silent_format to format layer

This commit is contained in:
Grafcube 2022-02-08 20:41:57 +05:30 committed by GitHub
parent e244e280ac
commit e61e78b0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -17,6 +17,7 @@
" 1. `format_on_save`: disabled by default.
" 2. `format_method`: set the format plugin, default plugin is `neoformat`.
" You can also use `vim-codefmt`.
" 3. `silent_format`: Runs the formatter without any messages.
"
" @subsection key bindings
" >
@ -30,6 +31,7 @@ if exists('s:format_on_save')
else
let s:format_method = 'neoformat'
let s:format_on_save = 0
let s:silent_format = 0
let s:format_ft = []
endif
@ -62,17 +64,22 @@ function! SpaceVim#layers#format#config() abort
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
let s:format_method = get(a:var, 'format_method', s:format_method)
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)
endfunction
function! SpaceVim#layers#format#get_options() abort
return ['format_method', 'format_on_save']
return ['format_method', 'format_on_save', 'silent_format']
endfunction
function! SpaceVim#layers#format#add_filetype(ft) abort

View File

@ -70,6 +70,15 @@ This layer is enabled by default. If you want to disable it, add the following t
format_on_save = false
```
- **`silent_format`**: Setting this to true will run the formatter silently without any messages. Default is
disabled.
```toml
[[layers]]
name = "format"
silent_format = true
```
### Global options
neoformat is a formatting framework, all of it's options can be used in bootstrap function. You can read