From 9eb89f572044da016e4749c13e6950f05a0cbdb7 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 29 Jan 2019 12:13:06 +0100 Subject: [PATCH 1/3] s:indent_like_previous_line: rename/move vars --- indent/python.vim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/indent/python.vim b/indent/python.vim index 5da97e9..90e1396 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -275,7 +275,6 @@ function! s:indent_like_previous_line(lnum) let text = getline(lnum) let start = s:find_start_of_multiline_statement(lnum) let base = indent(start) - let current = indent(a:lnum) " Ignore last character in previous line? let lastcol = len(text) @@ -305,26 +304,28 @@ function! s:indent_like_previous_line(lnum) return base + s:sw() endif - let empty = getline(a:lnum) =~# '^\s*$' + let empty_or_only_whitespace = getline(a:lnum) =~# '^\s*$' " Current and prev line are empty, next is not -> indent like next. - if empty && a:lnum > 1 && + if empty_or_only_whitespace && a:lnum > 1 && \ (getline(a:lnum - 1) =~# '^\s*$') && \ !(getline(a:lnum + 1) =~# '^\s*$') return indent(a:lnum + 1) endif + let current_indent = indent(a:lnum) + " If the previous statement was a stop-execution statement or a pass if getline(start) =~# s:stop_statement " Remove one level of indentation if the user hasn't already dedented - if empty || current > base - s:sw() + if empty_or_only_whitespace || current_indent > base - s:sw() return base - s:sw() endif " Otherwise, trust the user return -1 endif - if (current || !empty) && s:is_dedented_already(current, base) + if (current_indent || !empty_or_only_whitespace) && s:is_dedented_already(current_indent, base) return -1 endif From 106a9186f4baa6e72970e6b62f9b8ce0fb7c1d31 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 29 Jan 2019 12:14:53 +0100 Subject: [PATCH 2/3] s:indent_like_previous_line: return -1 with &autoindent Fixes https://github.com/Vimjas/vim-python-pep8-indent/issues/121. --- indent/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/python.vim b/indent/python.vim index 90e1396..831f71c 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -325,7 +325,7 @@ function! s:indent_like_previous_line(lnum) return -1 endif - if (current_indent || !empty_or_only_whitespace) && s:is_dedented_already(current_indent, base) + if (&autoindent || current_indent || !empty_or_only_whitespace) && s:is_dedented_already(current_indent, base) return -1 endif From 626247c7eafea9a9037e187a5d9b0f0a89315564 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 29 Jan 2019 12:21:20 +0100 Subject: [PATCH 3/3] fixup! s:indent_like_previous_line: return -1 with &autoindent --- indent/python.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indent/python.vim b/indent/python.vim index 831f71c..9aca3de 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -325,7 +325,8 @@ function! s:indent_like_previous_line(lnum) return -1 endif - if (&autoindent || current_indent || !empty_or_only_whitespace) && s:is_dedented_already(current_indent, base) + if (current_indent || (&autoindent && current_indent == 0) || !empty_or_only_whitespace) + \ && s:is_dedented_already(current_indent, base) return -1 endif