Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s:indent_like_previous_line: rename/move vars #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions indent/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -305,26 +304,29 @@ 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 || (&autoindent && current_indent == 0) || !empty_or_only_whitespace)
\ && s:is_dedented_already(current_indent, base)
return -1
endif

Expand Down