diff options
author | w0rp <devw0rp@gmail.com> | 2017-08-11 10:31:25 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-08-11 10:31:25 +0100 |
commit | 78b9ae0f1c65e53eac509b6946f8c70369fab980 (patch) | |
tree | bff335f57b7f678f16172d5028a43d84a4c2ad41 /autoload | |
parent | d5ae3201a4128c9e7b1042e9ea40b7f13cf72a10 (diff) | |
download | ale-78b9ae0f1c65e53eac509b6946f8c70369fab980.zip |
Add a fix function for breaking up long Python lines, which is hidden for now
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fixers/generic_python.vim | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/autoload/ale/fixers/generic_python.vim b/autoload/ale/fixers/generic_python.vim index 8bdde505..124146be 100644 --- a/autoload/ale/fixers/generic_python.vim +++ b/autoload/ale/fixers/generic_python.vim @@ -23,3 +23,38 @@ function! ale#fixers#generic_python#AddLinesBeforeControlStatements(buffer, line return l:new_lines endfunction + +" This function breaks up long lines so that autopep8 or other tools can +" fix the badly-indented code which is produced as a result. +function! ale#fixers#generic_python#BreakUpLongLines(buffer, lines) abort + " Default to a maximum line length of 79 + let l:max_line_length = 79 + let l:conf = ale#path#FindNearestFile(a:buffer, 'setup.cfg') + + " Read the maximum line length from setup.cfg + if !empty(l:conf) + for l:match in ale#util#GetMatches( + \ readfile(l:conf), + \ '\v^ *max-line-length *\= *(\d+)', + \) + let l:max_line_length = str2nr(l:match[1]) + endfor + endif + + let l:new_list = [] + + for l:line in a:lines + if len(l:line) > l:max_line_length && l:line !~# '# *noqa' + let l:line = substitute(l:line, '\v([(,])([^)])', '\1\n\2', 'g') + let l:line = substitute(l:line, '\v([^(])([)])', '\1,\n\2', 'g') + + for l:split_line in split(l:line, "\n") + call add(l:new_list, l:split_line) + endfor + else + call add(l:new_list, l:line) + endif + endfor + + return l:new_list +endfunction |