Introduces the `format` Python module which provides `clang_format()` and `yapf()` functions which efficiently (compared to vimscript) invoke `clang-format` or `yapf` respectively then apply the minimal number of changes using `difflib.SequenceMatcher`. Additionally, in order to invoke these Python functions add |autoload| functions `format#clang_format()` and `format#yapf()` which can be directly used by the 'formatexpr' setting. Finally, add |ftplugin| files which set 'formatexpr' when the |autoload| functions are available.
15 lines
229 B
VimL
15 lines
229 B
VimL
if !has('pythonx')
|
|
finish
|
|
endif
|
|
|
|
" set debug=msg,throw
|
|
pythonx import format
|
|
|
|
function! format#clang_format() abort
|
|
pythonx format.clang_format()
|
|
endfunction
|
|
|
|
function! format#yapf() abort
|
|
pythonx format.yapf()
|
|
endfunction
|