diff options
author | Miklós Tusz <mdtusz@gmail.com> | 2018-10-10 09:04:20 -0400 |
---|---|---|
committer | Miklós Tusz <mdtusz@gmail.com> | 2018-12-21 20:07:14 -0800 |
commit | 6619e1ac53143dd4f09223c9414e1159852aaf31 (patch) | |
tree | 425b5c0c09ec47ebca994b2fa074b78c52b8ad02 | |
parent | 73ca1e71918a0b50b7bbcbed91857c3618ad93cc (diff) | |
download | ale-6619e1ac53143dd4f09223c9414e1159852aaf31.zip |
Add auto_pipenv config for black
Added ability to set `python_black_auto_pipenv` to allow for usage
of a local pipenv black executable.
-rw-r--r-- | autoload/ale/fixers/black.vim | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/autoload/ale/fixers/black.vim b/autoload/ale/fixers/black.vim index 4169322a..7523bcae 100644 --- a/autoload/ale/fixers/black.vim +++ b/autoload/ale/fixers/black.vim @@ -4,22 +4,32 @@ call ale#Set('python_black_executable', 'black') call ale#Set('python_black_use_global', get(g:, 'ale_use_global_executables', 0)) call ale#Set('python_black_options', '') +call ale#Set('python_black_auto_pipenv', 0) + +function! ale#fixers#black#GetExecutable(buffer) abort + if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_black_auto_pipenv')) + \ && ale#python#PipenvPresent(a:buffer) + return 'pipenv' + endif + + return ale#python#FindExecutable(a:buffer, 'python_black', ['black']) +endfunction function! ale#fixers#black#Fix(buffer) abort - let l:executable = ale#python#FindExecutable( - \ a:buffer, - \ 'python_black', - \ ['black'], - \) + let l:executable = ale#fixers#black#GetExecutable(a:buffer) if !executable(l:executable) return 0 endif + let l:exec_args = l:executable =~? 'pipenv$' + \ ? ' run black' + \ : '' + let l:options = ale#Var(a:buffer, 'python_black_options') return { - \ 'command': ale#Escape(l:executable) + \ 'command': ale#Escape(l:executable) . l:exec_args \ . (!empty(l:options) ? ' ' . l:options : '') \ . ' -', \} |