mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-23 17:49:57 +08:00
feat(format): add silent_format
to format layer
This commit is contained in:
parent
e244e280ac
commit
e61e78b0bc
@ -17,6 +17,7 @@
|
|||||||
" 1. `format_on_save`: disabled by default.
|
" 1. `format_on_save`: disabled by default.
|
||||||
" 2. `format_method`: set the format plugin, default plugin is `neoformat`.
|
" 2. `format_method`: set the format plugin, default plugin is `neoformat`.
|
||||||
" You can also use `vim-codefmt`.
|
" You can also use `vim-codefmt`.
|
||||||
|
" 3. `silent_format`: Runs the formatter without any messages.
|
||||||
"
|
"
|
||||||
" @subsection key bindings
|
" @subsection key bindings
|
||||||
" >
|
" >
|
||||||
@ -30,6 +31,7 @@ if exists('s:format_on_save')
|
|||||||
else
|
else
|
||||||
let s:format_method = 'neoformat'
|
let s:format_method = 'neoformat'
|
||||||
let s:format_on_save = 0
|
let s:format_on_save = 0
|
||||||
|
let s:silent_format = 0
|
||||||
let s:format_ft = []
|
let s:format_ft = []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -62,17 +64,22 @@ function! SpaceVim#layers#format#config() abort
|
|||||||
endif
|
endif
|
||||||
augroup spacevim_layer_format
|
augroup spacevim_layer_format
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufWritePre * call s:format()
|
if s:silent_format
|
||||||
|
autocmd BufWritePre * silent! call s:format()
|
||||||
|
else
|
||||||
|
autocmd BufWritePre * call s:format()
|
||||||
|
endif
|
||||||
augroup END
|
augroup END
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#layers#format#set_variable(var) abort
|
function! SpaceVim#layers#format#set_variable(var) abort
|
||||||
let s:format_method = get(a:var, 'format_method', s:format_method)
|
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: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
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#layers#format#get_options() abort
|
function! SpaceVim#layers#format#get_options() abort
|
||||||
return ['format_method', 'format_on_save']
|
return ['format_method', 'format_on_save', 'silent_format']
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#layers#format#add_filetype(ft) abort
|
function! SpaceVim#layers#format#add_filetype(ft) abort
|
||||||
|
@ -70,6 +70,15 @@ This layer is enabled by default. If you want to disable it, add the following t
|
|||||||
format_on_save = false
|
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
|
### Global options
|
||||||
|
|
||||||
neoformat is a formatting framework, all of it's options can be used in bootstrap function. You can read
|
neoformat is a formatting framework, all of it's options can be used in bootstrap function. You can read
|
||||||
|
Loading…
x
Reference in New Issue
Block a user