Skip to content

Commit ae2e48a

Browse files
committed
Merge pull request #34 from Dryvnt/master
Added ClangFormatAutoEnable and ClangFormatAutoDisable functions
2 parents 0c48826 + 881699e commit ae2e48a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ It is more convenient to map `:ClangFormat` to your favorite key mapping in norm
2121
If you install [vim-operator-user](https://github.com/kana/vim-operator-user) in advance, you can also map `<Plug>(operator-clang-format)` to your favorite key bind.
2222

2323
`:ClangFormatAutoToggle` command toggles the auto formatting on buffer write.
24+
`:ClangFormatAutoEnable` command enables the auto formatting on buffer write. Useful for automatically enabling the auto format through a vimrc. `:ClangFormatAutoDisable` turns it off.
2425

2526
### What is the difference from `clang-format.py`?
2627

@@ -111,6 +112,11 @@ autocmd FileType c,cpp,objc map <buffer><Leader>x <Plug>(operator-clang-format)
111112
nmap <Leader>C :ClangFormatAutoToggle<CR>
112113
```
113114

115+
##### Auto-enabling auto-formatting
116+
```vim
117+
au FileType c ClangFormatAutoEnable
118+
```
119+
114120
### For More Information
115121

116122
```

autoload/clang_format.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,17 @@ function! clang_format#toggle_auto_format()
248248
endif
249249
endfunction
250250
" }}}
251+
252+
" enable auto formatting {{{
253+
function! clang_format#enable_auto_format()
254+
let g:clang_format#auto_format = 1
255+
endfunction
256+
" }}}
257+
258+
" disable auto formatting {{{
259+
function! clang_format#disable_auto_format()
260+
let g:clang_format#auto_format = 0
261+
endfunction
262+
" }}}
251263
let &cpo = s:save_cpo
252264
unlet s:save_cpo

plugin/clang_format.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ augroup plugin-clang-format-auto-format
2020
augroup END
2121

2222
command! ClangFormatAutoToggle call clang_format#toggle_auto_format()
23+
command! ClangFormatAutoEnable call clang_format#enable_auto_format()
24+
command! ClangFormatAutoDisable call clang_format#disable_auto_format()
2325

2426
let g:loaded_clang_format = 1

0 commit comments

Comments
 (0)