mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-13 02:05:40 +08:00
Format on save with clang-format (#4195)
This commit is contained in:
parent
c95b610ac5
commit
7b0743077a
@ -101,6 +101,8 @@ else
|
||||
endif
|
||||
" }}}
|
||||
|
||||
let s:format_on_save = 0
|
||||
|
||||
" Load the APIs{{{
|
||||
let s:SYSTEM = SpaceVim#api#import('system')
|
||||
let s:CPT = SpaceVim#api#import('vim#compatible')
|
||||
@ -200,6 +202,26 @@ function! SpaceVim#layers#lang#c#config() abort
|
||||
else
|
||||
let s:highlight_cmd = 'ClighterEnable'
|
||||
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
|
||||
" }}}
|
||||
|
||||
@ -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:format_on_save = get(a:var,
|
||||
\ 'format_on_save',
|
||||
\ s:format_on_save)
|
||||
|
||||
call extend(s:clang_std, get(a:var, 'clang_std', {}))
|
||||
endfunction
|
||||
" }}}
|
||||
|
@ -92,6 +92,14 @@ defined in `.clang` file. For example:
|
||||
Note: If `.clang` file contains std configuration, it will override
|
||||
`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 | Descriptions |
|
||||
|
Loading…
x
Reference in New Issue
Block a user