diff options
author | Peter Renström <renstrom.peter@gmail.com> | 2017-08-24 23:49:43 +0200 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2017-08-24 22:49:43 +0100 |
commit | 4bea50b82f53a351d218cc3af120b460b9d1639f (patch) | |
tree | c14ac460c270d0415fea5fa6ec2988ee4cbbf76e /autoload | |
parent | 623fdf212cd70131df4d3c52de26d9d1faa5d90e (diff) | |
download | ale-4bea50b82f53a351d218cc3af120b460b9d1639f.zip |
Add clang-format fixer for C/C++ (#873)
* Add clang-format fixer for C/C++
* Document clang-format options
* Refer ale-cpp-clangformat to ale-c-clangformat
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/clangformat.vim | 21 |
2 files changed, 26 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 5c3b8d94..b77ac031 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -82,6 +82,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['php'], \ 'description': 'Fix PHP files with phpcbf.', \ }, +\ 'clang-format': { +\ 'function': 'ale#fixers#clangformat#Fix', +\ 'suggested_filetypes': ['c', 'cpp'], +\ 'description': 'Fix C/C++ files with clang-format.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/clangformat.vim b/autoload/ale/fixers/clangformat.vim new file mode 100644 index 00000000..b2ed7daa --- /dev/null +++ b/autoload/ale/fixers/clangformat.vim @@ -0,0 +1,21 @@ +" Author: Peter Renström <renstrom.peter@gmail.com> +" Description: Fixing C/C++ files with clang-format. + +call ale#Set('c_clangformat_executable', 'clang-format') +call ale#Set('c_clangformat_use_global', 0) +call ale#Set('c_clangformat_options', '') + +function! ale#fixers#clangformat#GetExecutable(buffer) abort + return ale#node#FindExecutable(a:buffer, 'c_clangformat', [ + \ 'clang-format', + \]) +endfunction + +function! ale#fixers#clangformat#Fix(buffer) abort + let l:options = ale#Var(a:buffer, 'c_clangformat_options') + + return { + \ 'command': ale#Escape(ale#fixers#clangformat#GetExecutable(a:buffer)) + \ . ' ' . l:options, + \} +endfunction |