From 035a868ea55374da6fb04b13a486692e7531d612 Mon Sep 17 00:00:00 2001 From: Arnar Birgisson Date: Fri, 2 Mar 2012 15:25:52 +0100 Subject: [PATCH 1/2] Fix bug where selection wouldn't work if on an empty line. --- ftplugin/python/pythontextobj.vim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ftplugin/python/pythontextobj.vim b/ftplugin/python/pythontextobj.vim index 0afd09d..2775bd6 100644 --- a/ftplugin/python/pythontextobj.vim +++ b/ftplugin/python/pythontextobj.vim @@ -102,7 +102,12 @@ function! s:FindPythonObjectStart(obj) " TODO: don't match definitions at equal or greater indent unless it matches " at cursor position let cursor_start_pos = line(".") - let cursor_indent = indent(cursor_start_pos) + " Empty lines have the indentation of the previous non-empty line in python, + " so we skip backwards until we find one that is not empty + while (getline(".") =~ '^\s*$') && (line(".") > 1) + exec line(".") - 1 + endwhile + let cursor_indent = indent(line(".")) if (a:obj == "class") let objregexp = "^\\s*class\\s\\+[a-zA-Z0-9_]\\+" \ . "\\s*\\((\\([a-zA-Z0-9_,. \\t\\n]\\)*)\\)\\=\\s*:" From 87b485a8a710729a00a5005ba8c311628fcaade6 Mon Sep 17 00:00:00 2001 From: Arnar Birgisson Date: Fri, 2 Mar 2012 16:05:15 +0100 Subject: [PATCH 2/2] Fix bug where the outer text object on a top level (0-indent def/class) would go on to include lines above the decorators. --- ftplugin/python/pythontextobj.vim | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/ftplugin/python/pythontextobj.vim b/ftplugin/python/pythontextobj.vim index 2775bd6..6e4bc0a 100644 --- a/ftplugin/python/pythontextobj.vim +++ b/ftplugin/python/pythontextobj.vim @@ -75,26 +75,19 @@ function! s:NextIndent(start) endwhile return lastline endfunction - + function! s:StartDecorators(start) - " get def/class start pos - " move upwards, breaking on first line of different indent that doesn't - " start w/ @ + " Returns the line of the first decorator line above the starting line, + " counting only decorators with the same level. exec a:start normal ^ let def_indent = indent(line(".")) - let found = 0 - while (! found) + normal k + while (indent(line(".") == def_indent) && getline(".") =~ '\v^\s*\@') normal k - let ln = line(".") - if (ln == 1) - return ln - endif - if (indent(ln) != def_indent || getline(ln) =~ '\v^\s*[^@].+$') - return line(".") + 1 - endif endwhile + return line(".") + 1 endfunction