2017-06-07 13:02:29 +00:00
|
|
|
" Author: w0rp <devw0rp@gmail.com>
|
|
|
|
" Description: Fixing Python files with yapf.
|
|
|
|
|
2017-06-18 10:03:31 +00:00
|
|
|
call ale#Set('python_yapf_executable', 'yapf')
|
2018-04-09 18:11:20 +00:00
|
|
|
call ale#Set('python_yapf_use_global', get(g:, 'ale_use_global_executables', 0))
|
2017-06-18 10:03:31 +00:00
|
|
|
|
2017-06-07 13:02:29 +00:00
|
|
|
function! ale#fixers#yapf#Fix(buffer) abort
|
2017-06-18 10:03:31 +00:00
|
|
|
let l:executable = ale#python#FindExecutable(
|
|
|
|
\ a:buffer,
|
|
|
|
\ 'python_yapf',
|
2017-07-05 12:07:55 +00:00
|
|
|
\ ['yapf'],
|
2017-06-18 10:03:31 +00:00
|
|
|
\)
|
|
|
|
|
2017-11-04 10:46:19 +00:00
|
|
|
if !executable(l:executable)
|
2017-06-07 19:42:30 +00:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2017-06-07 13:02:29 +00:00
|
|
|
let l:config = ale#path#FindNearestFile(a:buffer, '.style.yapf')
|
|
|
|
let l:config_options = !empty(l:config)
|
2017-07-20 10:07:07 +00:00
|
|
|
\ ? ' --no-local-style --style ' . ale#Escape(l:config)
|
2017-06-07 13:02:29 +00:00
|
|
|
\ : ''
|
|
|
|
|
|
|
|
return {
|
2017-07-20 10:07:07 +00:00
|
|
|
\ 'command': ale#Escape(l:executable) . l:config_options,
|
2017-06-07 13:02:29 +00:00
|
|
|
\}
|
|
|
|
endfunction
|