summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-22 12:59:40 +0100
committerw0rp <devw0rp@gmail.com>2017-05-22 12:59:40 +0100
commit1e72a7a130c51f02b5910e982267f17e8c4880d6 (patch)
tree20d1caab9dd12128b72806ff8a8f65e26f27766f /autoload
parent4526018344b26c82b5969d837630f4ee7785d629 (diff)
downloadale-1e72a7a130c51f02b5910e982267f17e8c4880d6.zip
Add a fixer for Python for automatically adding blank lines before control statements
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/handlers/python.vim20
2 files changed, 25 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index b85c5d76..59b8997a 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -2,6 +2,11 @@
" Description: A registry of functions for fixing things.
let s:default_registry = {
+\ 'add_blank_lines_for_python_control_statements': {
+\ 'function': 'ale#handlers#python#AddLinesBeforeControlStatements',
+\ 'suggested_filetypes': ['python'],
+\ 'description': 'Add blank lines before control statements.',
+\ },
\ 'autopep8': {
\ 'function': 'ale#handlers#python#AutoPEP8',
\ 'suggested_filetypes': ['python'],
diff --git a/autoload/ale/handlers/python.vim b/autoload/ale/handlers/python.vim
index 5e9ddecd..952df8f4 100644
--- a/autoload/ale/handlers/python.vim
+++ b/autoload/ale/handlers/python.vim
@@ -36,6 +36,26 @@ function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort
return l:output
endfunction
+" Add blank lines before control statements.
+function! ale#handlers#python#AddLinesBeforeControlStatements(buffer, lines) abort
+ let l:new_lines = []
+ let l:last_indent_size = 0
+
+ for l:line in a:lines
+ let l:indent_size = len(matchstr(l:line, '^ *'))
+
+ if l:indent_size <= l:last_indent_size
+ \&& match(l:line, '\v^ *(return|if|for|while|break|continue)') >= 0
+ call add(l:new_lines, '')
+ endif
+
+ call add(l:new_lines, l:line)
+ let l:last_indent_size = l:indent_size
+ endfor
+
+ return l:new_lines
+endfunction
+
function! ale#handlers#python#AutoPEP8(buffer, lines) abort
return {
\ 'command': 'autopep8 -'