summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-06-18 11:03:31 +0100
committerw0rp <devw0rp@gmail.com>2017-06-18 11:03:31 +0100
commit629ff513ec09cc5db24d493abe125cc71e89e54e (patch)
treedbde1150b7bae5ab296c6e8efb2e92cae1692fd9 /autoload
parentfb682be1997f812171def14976b5dfbef38c9f0d (diff)
downloadale-629ff513ec09cc5db24d493abe125cc71e89e54e.zip
#659 - Add options for Python fixers, and cut down on duplicated documentation
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fixers/autopep8.vim17
-rw-r--r--autoload/ale/fixers/isort.vim10
-rw-r--r--autoload/ale/fixers/yapf.vim10
-rw-r--r--autoload/ale/python.vim50
4 files changed, 62 insertions, 25 deletions
diff --git a/autoload/ale/fixers/autopep8.vim b/autoload/ale/fixers/autopep8.vim
index 32d2824b..8bfc0d90 100644
--- a/autoload/ale/fixers/autopep8.vim
+++ b/autoload/ale/fixers/autopep8.vim
@@ -1,13 +1,26 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Fixing files with autopep8.
+call ale#Set('python_autopep8_executable', 'autopep8')
+call ale#Set('python_autopep8_use_global', 0)
+call ale#Set('python_autopep8_options', '')
+
function! ale#fixers#autopep8#Fix(buffer) abort
- let l:executable = ale#python#GetExecutable(a:buffer, 'autopep8')
+ let l:executable = ale#python#FindExecutable(
+ \ a:buffer,
+ \ 'python_autopep8',
+ \ ['/bin/autopep8'],
+ \)
+
if empty(l:executable)
return 0
endif
+ let l:options = ale#Var(a:buffer, 'python_autopep8_options')
+
return {
- \ 'command': ale#Escape(l:executable) . ' -'
+ \ 'command': ale#Escape(l:executable)
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+ \ . ' -',
\}
endfunction
diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim
index c37f12f7..e1ddcda3 100644
--- a/autoload/ale/fixers/isort.vim
+++ b/autoload/ale/fixers/isort.vim
@@ -1,8 +1,16 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Fixing Python imports with isort.
+call ale#Set('python_isort_executable', 'isort')
+call ale#Set('python_isort_use_global', 0)
+
function! ale#fixers#isort#Fix(buffer) abort
- let l:executable = ale#python#GetExecutable(a:buffer, 'isort')
+ let l:executable = ale#python#FindExecutable(
+ \ a:buffer,
+ \ 'python_isort',
+ \ ['/bin/isort'],
+ \)
+
if empty(l:executable)
return 0
endif
diff --git a/autoload/ale/fixers/yapf.vim b/autoload/ale/fixers/yapf.vim
index 3eae09bc..fe6512aa 100644
--- a/autoload/ale/fixers/yapf.vim
+++ b/autoload/ale/fixers/yapf.vim
@@ -1,8 +1,16 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Fixing Python files with yapf.
+call ale#Set('python_yapf_executable', 'yapf')
+call ale#Set('python_yapf_use_global', 0)
+
function! ale#fixers#yapf#Fix(buffer) abort
- let l:executable = ale#python#GetExecutable(a:buffer, 'yapf')
+ let l:executable = ale#python#FindExecutable(
+ \ a:buffer,
+ \ 'python_yapf',
+ \ ['/bin/yapf'],
+ \)
+
if empty(l:executable)
return 0
endif
diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim
index f835e942..a88b4b62 100644
--- a/autoload/ale/python.vim
+++ b/autoload/ale/python.vim
@@ -9,27 +9,6 @@ let g:ale_virtualenv_dir_names = get(g:, 'ale_virtualenv_dir_names', [
\ 'virtualenv',
\])
-" Given a buffer number and a command name, find the path to the executable.
-" First search on a virtualenv for Python, if nothing is found, try the global
-" command. Returns an empty string if cannot find the executable
-function! ale#python#GetExecutable(buffer, cmd_name) abort
- let l:virtualenv = ale#python#FindVirtualenv(a:buffer)
-
- if !empty(l:virtualenv)
- let l:ve_executable = l:virtualenv . '/bin/' . a:cmd_name
-
- if executable(l:ve_executable)
- return l:ve_executable
- endif
- endif
-
- if executable(a:cmd_name)
- return a:cmd_name
- endif
-
- return ''
-endfunction
-
" Given a buffer number, find the project root directory for Python.
" The root directory is defined as the first directory found while searching
" upwards through paths, including the current directory, until a path
@@ -58,3 +37,32 @@ function! ale#python#FindVirtualenv(buffer) abort
return ''
endfunction
+
+" Given a buffer number and a command name, find the path to the executable.
+" First search on a virtualenv for Python, if nothing is found, try the global
+" command. Returns an empty string if cannot find the executable
+function! ale#python#FindExecutable(buffer, base_var_name, path_list) abort
+ if ale#Var(a:buffer, a:base_var_name . '_use_global')
+ return ale#Var(a:buffer, a:base_var_name . '_executable')
+ endif
+
+ let l:virtualenv = ale#python#FindVirtualenv(a:buffer)
+
+ if !empty(l:virtualenv)
+ for l:path in a:path_list
+ let l:ve_executable = l:virtualenv . l:path
+
+ if executable(l:ve_executable)
+ return l:ve_executable
+ endif
+ endfor
+ endif
+
+ let l:global_executable = ale#Var(a:buffer, a:base_var_name . '_executable')
+
+ if executable(l:global_executable)
+ return l:global_executable
+ endif
+
+ return ''
+endfunction