mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-15 19:45:46 +08:00
Format on save with clang-format (#4195)
This commit is contained in:
parent
c95b610ac5
commit
7b0743077a
@ -101,6 +101,8 @@ else
|
|||||||
endif
|
endif
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
|
let s:format_on_save = 0
|
||||||
|
|
||||||
" Load the APIs{{{
|
" Load the APIs{{{
|
||||||
let s:SYSTEM = SpaceVim#api#import('system')
|
let s:SYSTEM = SpaceVim#api#import('system')
|
||||||
let s:CPT = SpaceVim#api#import('vim#compatible')
|
let s:CPT = SpaceVim#api#import('vim#compatible')
|
||||||
@ -200,6 +202,26 @@ function! SpaceVim#layers#lang#c#config() abort
|
|||||||
else
|
else
|
||||||
let s:highlight_cmd = 'ClighterEnable'
|
let s:highlight_cmd = 'ClighterEnable'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Format on save
|
||||||
|
if s:format_on_save
|
||||||
|
call SpaceVim#layers#format#add_filetype({
|
||||||
|
\ 'filetype' : 'c',
|
||||||
|
\ 'enable' : 1,
|
||||||
|
\ })
|
||||||
|
call SpaceVim#layers#format#add_filetype({
|
||||||
|
\ 'filetype' : 'cpp',
|
||||||
|
\ 'enable' : 1,
|
||||||
|
\ })
|
||||||
|
call SpaceVim#layers#format#add_filetype({
|
||||||
|
\ 'filetype' : 'objc',
|
||||||
|
\ 'enable' : 1,
|
||||||
|
\ })
|
||||||
|
call SpaceVim#layers#format#add_filetype({
|
||||||
|
\ 'filetype' : 'objcpp',
|
||||||
|
\ 'enable' : 1,
|
||||||
|
\ })
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
@ -246,6 +268,10 @@ function! SpaceVim#layers#lang#c#set_variable(var) abort
|
|||||||
|
|
||||||
let s:enable_clang_syntax = get(a:var, 'enable_clang_syntax_highlight', s:enable_clang_syntax)
|
let s:enable_clang_syntax = get(a:var, 'enable_clang_syntax_highlight', s:enable_clang_syntax)
|
||||||
|
|
||||||
|
let s:format_on_save = get(a:var,
|
||||||
|
\ 'format_on_save',
|
||||||
|
\ s:format_on_save)
|
||||||
|
|
||||||
call extend(s:clang_std, get(a:var, 'clang_std', {}))
|
call extend(s:clang_std, get(a:var, 'clang_std', {}))
|
||||||
endfunction
|
endfunction
|
||||||
" }}}
|
" }}}
|
||||||
|
@ -92,6 +92,14 @@ defined in `.clang` file. For example:
|
|||||||
Note: If `.clang` file contains std configuration, it will override
|
Note: If `.clang` file contains std configuration, it will override
|
||||||
`clang_std` layer option.
|
`clang_std` layer option.
|
||||||
|
|
||||||
|
`format_on_save`: Enable/disable file formatting when saving current file. By default,
|
||||||
|
it is disabled, to enable it:
|
||||||
|
```toml
|
||||||
|
[[layers]]
|
||||||
|
name = 'lang#c'
|
||||||
|
format_on_save = true
|
||||||
|
```
|
||||||
|
|
||||||
## Key bindings
|
## Key bindings
|
||||||
|
|
||||||
| key bindings | Descriptions |
|
| key bindings | Descriptions |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user