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
This commit is contained in:
Peter Renström
2017-08-24 23:49:43 +02:00
committed by w0rp
parent 623fdf212c
commit 4bea50b82f
8 changed files with 94 additions and 4 deletions

View File

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

View File

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