1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 12:50:04 +08:00

Add format_on_save toggle for javascript (#4183)

This commit is contained in:
Goran Mekić 2021-04-10 13:40:18 +02:00 committed by GitHub
parent a74237108a
commit a1909e1b69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -47,7 +47,7 @@
" <
"
let s:format_on_save = 0
function! SpaceVim#layers#lang#javascript#plugins() abort
let plugins = [
@ -86,6 +86,9 @@ let s:enable_flow_syntax = 0
function! SpaceVim#layers#lang#javascript#set_variable(var) abort
let s:auto_fix = get(a:var, 'auto_fix', 0)
let s:enable_flow_syntax = get(a:var, 'enable_flow_syntax', 0)
let s:format_on_save = get(a:var,
\ 'format_on_save',
\ s:format_on_save)
endfunction
function! SpaceVim#layers#lang#javascript#config() abort
@ -136,6 +139,14 @@ function! SpaceVim#layers#lang#javascript#config() abort
" be flushed by sender.
" Use node -i will show the output of repl command.
call SpaceVim#plugins#repl#reg('javascript', ['node', '-i'])
" Format on save
if s:format_on_save
call SpaceVim#layers#format#add_filetype({
\ 'filetype' : 'javascript',
\ 'enable' : 1,
\ })
endif
endfunction
function! s:on_ft() abort

View File

@ -53,6 +53,15 @@ auto_fix = true
enable_flow_syntax = true
```
`format_on_save`: Enable/disable file formatting when saving current javascript file. By default,
it is disabled, to enable it:
```toml
[[layers]]
name = 'lang#javascript'
format_on_save = true
```
## Key bindings
### Import key bindings