Skip to content

Commit e083709

Browse files
authored
Merge pull request #124 from funous/clangformatcommand
Add support for an arbitrary clang_format command with arguments
2 parents 57d6fbb + 293c208 commit e083709

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

autoload/codefmt/clangformat.vim

+13-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ let s:plugin = maktaba#plugin#Get('codefmt')
1818

1919
function! s:ClangFormatHasAtLeastVersion(minimum_version) abort
2020
if !exists('s:clang_format_version')
21-
let l:executable = s:plugin.Flag('clang_format_executable')
22-
if codefmt#ShouldPerformIsAvailableChecks() && !executable(l:executable)
21+
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray(
22+
\ 'clang_format_executable')
23+
if codefmt#ShouldPerformIsAvailableChecks() && !executable(l:cmd[0])
2324
return 0
2425
endif
2526

26-
let l:syscall = maktaba#syscall#Create([l:executable, '--version'])
27+
let l:syscall = maktaba#syscall#Create(l:cmd + ['--version'])
2728
" Call with throw_errors disabled because some versions of clang-format
2829
" misbehave and return exit code 1 along with the successful version
2930
" output (see https://github.com/google/vim-codefmt/issues/84).
@@ -104,7 +105,13 @@ function! codefmt#clangformat#GetFormatter() abort
104105
\ 'configure the clang_format_executable flag'}
105106

106107
function l:formatter.IsAvailable() abort
107-
return executable(s:plugin.Flag('clang_format_executable'))
108+
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray(
109+
\ 'clang_format_executable')
110+
if !empty(l:cmd) && executable(l:cmd[0])
111+
return 1
112+
else
113+
return 0
114+
endif
108115
endfunction
109116

110117
function l:formatter.AppliesToBuffer() abort
@@ -136,9 +143,8 @@ function! codefmt#clangformat#GetFormatter() abort
136143
return
137144
endif
138145

139-
let l:cmd = [
140-
\ s:plugin.Flag('clang_format_executable'),
141-
\ '-style', l:style]
146+
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray(
147+
\ 'clang_format_executable') + ['-style', l:style]
142148
let l:fname = expand('%:p')
143149
if !empty(l:fname)
144150
let l:cmd += ['-assume-filename', l:fname]

doc/codefmt.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ The path to the autopep8 executable.
3030
Default: 'autopep8' `
3131

3232
*codefmt:clang_format_executable*
33-
The path to the clang-format executable.
33+
The path to the clang-format executable. String, list, or callable that takes
34+
no args and returns a string or a list.
3435
Default: 'clang-format' `
3536

3637
*codefmt:clang_format_style*

0 commit comments

Comments
 (0)