From f947b48cda8523be471047834e968ff8e9e9c2a9 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sun, 25 Aug 2013 14:47:26 +0300 Subject: [PATCH] more auto-indenting improvements --- indent/nimrod.vim | 48 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/indent/nimrod.vim b/indent/nimrod.vim index 280a1eb..92ae499 100644 --- a/indent/nimrod.vim +++ b/indent/nimrod.vim @@ -43,6 +43,7 @@ function! GetNimrodIndent(lnum) endif let pline = getline(plnum) + let cline = getline(a:lnum) let pline_len = strlen(pline) let plindent = indent(plnum) let clindent = indent(a:lnum) @@ -77,6 +78,32 @@ function! GetNimrodIndent(lnum) endwhile endif + if cline =~ '^\s*\(if\|when\|for\|while\|case\|of\|try\)\>' + " This is a benign line, do nothing + return -1 + endif + + " If the current line begins with a keyword that lines up with "try" + if cline =~ '^\s*\(except\|finally\)\>' + let lnum = a:lnum - 1 + while lnum >= 1 + if getline(lnum) =~ '^\s*\(try\|except\)\>' + let ind = indent(lnum) + if ind >= clindent + return -1 " indent is already less than this + endif + return ind " line up with previous try or except + endif + let lnum = lnum - 1 + endwhile + return -1 " no matching "try"! + endif + + " If the current line begins with a header keyword, dedent + if cline =~ '^\s*\(elif\|else\)\>' + return s:FindStartLine(a:lnum, '^\s*\(if\|when\|elif\|of\)') + endif + if pline =~ ':\s*$' "return s:FindStartLine(plnum, '(^\s*\(if\|when\|else\|elif\|case\|of\|try\|except\|finally\)\>)\|\') + &sw return s:FindStartLine(plnum, '^\s*\(if\|when\|else\|elif\|for\|while\|case\|of\|try\|except\|finally\)\>') + &sw @@ -107,27 +134,6 @@ function! GetNimrodIndent(lnum) return -1 endif - " If the current line begins with a keyword that lines up with "try" - if getline(a:lnum) =~ '^\s*\(except\|finally\)\>' - let lnum = a:lnum - 1 - while lnum >= 1 - if getline(lnum) =~ '^\s*\(try\|except\)\>' - let ind = indent(lnum) - if ind >= clindent - return -1 " indent is already less than this - endif - return ind " line up with previous try or except - endif - let lnum = lnum - 1 - endwhile - return -1 " no matching "try"! - endif - - " If the current line begins with a header keyword, dedent - if getline(a:lnum) =~ '^\s*\(elif\|else\)\>' - return s:FindStartLine(a:lnum, '^\s*\(if\|when\|elif\|of\)') - endif - return -1 endfunction