From: Hynek Schlawack Date: Fri, 3 Jan 2014 20:00:18 +0000 (+0100) Subject: Unindent 'finally' after 'else' too X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/4ee0349126e2668aead81fdbe8e8752d7d28f9e1?ds=sidebyside;hp=--cc Unindent 'finally' after 'else' too --- 4ee0349126e2668aead81fdbe8e8752d7d28f9e1 diff --git a/indent/python.vim b/indent/python.vim index 4dcdf8b..db12e24 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -137,9 +137,8 @@ function! GetPythonPEPIndent(lnum) endif endif - " If the line starts with 'except', or 'finally', line up with 'try' - " or 'except'. - if thisline =~ '^\s*\(except\|finally\)\>' + " If the line starts with 'except' line up with 'try' or 'except'. + if thisline =~ '^\s*except\>' let bslnum = s:BlockStarter(a:lnum, '^\s*\(try\|except\)\>') if bslnum > 0 return indent(bslnum) @@ -148,6 +147,17 @@ function! GetPythonPEPIndent(lnum) endif endif + " If the line starts with 'finally', line up with 'try', 'else', or + " 'except'. + if thisline =~ '^\s*finally\>' + let bslnum = s:BlockStarter(a:lnum, '^\s*\(try\|except\|else\)\>') + if bslnum > 0 + return indent(bslnum) + else + return -1 + endif + endif + " If the line starts with 'else', line it up with 'try', 'except', 'for', " 'if', or 'elif'. if thisline =~ '^\s*else\>' diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 77b94ef..a622cf8 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -144,6 +144,15 @@ shared_examples_for "vim" do end end + describe "when an 'else' is followed by" do + before { vim.feedkeys 'i\\else:\XXX\' } + it "a 'finally', it lines up with the 'else'" do + vim.feedkeys 'finally:' + indent.should == shiftwidth * 2 + end + end + + describe "when a 'try' is followed by" do before { vim.feedkeys 'i\\try:\' } it "an 'except', it lines up with the 'try'" do