Skip to content

Commit

Permalink
Fixed bug dealing with Postlude
Browse files Browse the repository at this point in the history
  • Loading branch information
JessieAMorris committed Nov 2, 2012
1 parent 86916a8 commit 146dc3e
Showing 1 changed file with 77 additions and 9 deletions.
86 changes: 77 additions & 9 deletions indent/krl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
"finish
finish
endif
" let b:did_indent = 1
let b:did_indent = 1

" C indenting is not too bad.
" I've decided to no longer do cindenting. JAM 11/01/2012
Expand All @@ -16,10 +16,50 @@ endif
setlocal indentexpr=GetKRLIndent(v:lnum)

if exists("*GetKRLIndent")
"finish
finish
endif


function! s:GetIsInsideHereDoc( line_num )
let OPENHEREDOC = '=\s*<<'
let CLOSEHEREDOC = '\s*>>;'

let first_start = a:line_num

let open_line = 0
let close_line = 0

" Go backwards
while nline > 0
let nline = prevnonblank(nline-1)

" If the current line has a close heredoc before it,
" we're not in a heredoc.
if getline(nline) =~ CLOSEHEREDOC
return 0
endif

if getline(nline) =~ OPENHEREDOC
let open_line = nline
endif
endwhile

while nline <= line('$')
let nline = nextnonblank(nline-1)

" If the current line has a open heredoc before it,
" we're not in a heredoc.
if getline(nline) =~ OPENHEREDOC
return 0
endif

if getline(nline) =~ CLOSEHEREDOC
let open_line = nline
endif
endwhile
endfunction


function! s:GetPrevKRLNonCommentLineNum( line_num )
let SKIP_LINES = '^\s*\(\((\*\)\|\(\*\ \)\|\(\*)\)\)'

Expand All @@ -34,6 +74,20 @@ function! s:GetPrevKRLNonCommentLineNum( line_num )
return nline
endfunction

function! s:GetPrevKRLBracketIndent( line_num )
let OPENBRACKET = '\s*\({\|<<\|[\)\s*$'

let nline = a:line_num
while nline > 0
let nline = prevnonblank( nline-1 )
if getline( nline ) =~ OPENBRACKET
return indent( nline )
endif
endwhile

return indent( a:line_num )
endfunction

function! GetKRLIndent( line_num )
" Line 0 always starts at column 0
if a:line_num == 1
Expand Down Expand Up @@ -70,24 +124,28 @@ function! GetKRLIndent( line_num )
" If this line ends in } or >>, decrease the indent
" We do the close check first to make sure that even if
" the previous line was { or << to still unindent.
if this_codeline =~ '^\s*\(}\|>>\);\?'
if prev_codeline =~ '\s*\({\|<<\)\s*$'
if this_codeline =~ '^\s*\(}\|>>\|]\);\?'
if prev_codeline =~ '\s*\({\|<<\|[\)\s*$'
return indnt
elseif prev_codeline =~ '^\s*\<\(with\|and\)\>'
return s:GetPrevKRLBracketIndent( a:line_num )
else
return indnt - &shiftwidth
endif
endif

" If the previous line ends in { or << increase the indent
if prev_codeline =~ '\s*\({\|<<\)\s*$'
if prev_codeline =~ '\s*\({\|<<\|[\)\s*$'
return indnt + &shiftwidth
endif

" These two rules handle the indentation of with/and.
" These four rules handle the indentation of with/and.
" The first handles the case where with/and is on this line,
" and the second handles the case where it was on the previous line.
" Since the previous line unindent case comes after the return,
" this should work correctly.
"
" Also, there is a problem with the and interacting with postlude }'s
if this_codeline =~ '^\s*\<with\>'
return indnt + &shiftwidth
endif
Expand All @@ -98,9 +156,19 @@ function! GetKRLIndent( line_num )
endif
endif

if prev_codeline =~ '^\s*\<and\>'
if this_codeline =~ '^\s*\<and\>'
return indnt
endif
endif

if prev_codeline =~ '^\s*\<with\|and\>'
return indnt - &shiftwidth
end
if this_codeline =~ '^\s*\<and\>'
return indnt + &shiftwidth
else
return indnt - &shiftwidth
endif
endif

"If all else fails, just return the previous line's indentation
return indnt
Expand Down

0 comments on commit 146dc3e

Please sign in to comment.