" Vim indent file
" Language:	Vim script
" Maintainer:	Bram Moolenaar <Bram@vim.org>
" Last Change:	2001 Jan 15

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

setlocal indentexpr=GetVimIndent()
setlocal indentkeys+==end,=else,0\\

" Only define the function once.
if exists("*GetVimIndent")
  finish
endif

function GetVimIndent()
  " Find a non-blank line above the current line.
  let lnum = prevnonblank(v:lnum - 1)

  " At the start of the file use zero indent.
  if lnum == 0
    return 0
  endif

  " Add a 'shiftwidth' after :if, :while, :function and :else.
  " Also for a line that starts with '\' after a line that doesn't.
  let ind = indent(lnum)
  if getline(lnum) =~ '^\s*\(if\>\|wh\|fu\|el\)' || (getline(v:lnum) =~ '^\s*\\' && v:lnum > 1 && getline(lnum) !~ '^\s*\\')
    let ind = ind + &sw
  endif

  " Subtract a 'shiftwidth' on a :endif, :endwhile, :endfun and :else
  if getline(v:lnum) =~ '^\s*\(ene\@!\|el\)'
    let ind = ind - &sw
  endif

  return ind
endfunction

" vim:sw=2
