1
0
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:
Goran Mekić 2021-04-11 11:51:03 +02:00 committed by GitHub
parent c95b610ac5
commit 7b0743077a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -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
" }}}

View File

@ -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 |