Add Reload/Ignore All buttons to file changed dialog
[MacVim.git] / runtime / indent / sh.vim
blob483e5430ecf96f50e0af08fe85a87b3967d8dbe1
1 " Vim indent file
2 " Language:         Shell Script
3 " Maintainer:       Nikolai Weibull <now@bitwi.se>
4 " Latest Revision:  2006-04-19
6 if exists("b:did_indent")
7   finish
8 endif
9 let b:did_indent = 1
11 setlocal indentexpr=GetShIndent()
12 setlocal indentkeys+==then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
13 setlocal indentkeys-=:,0#
15 if exists("*GetShIndent")
16   finish
17 endif
19 let s:cpo_save = &cpo
20 set cpo&vim
22 function GetShIndent()
23   let lnum = prevnonblank(v:lnum - 1)
24   if lnum == 0
25     return 0
26   endif
28   " Add a 'shiftwidth' after if, while, else, case, until, for, function()
29   " Skip if the line also contains the closure for the above
30   let ind = indent(lnum)
31   let line = getline(lnum)
32   if line =~ '^\s*\(if\|then\|do\|else\|elif\|case\|while\|until\|for\)\>'
33         \ || line =~ '^\s*\<\k\+\>\s*()\s*{'
34         \ || line =~ '^\s*{'
35     if line !~ '\(esac\|fi\|done\)\>\s*$' && line !~ '}\s*$'
36       let ind = ind + &sw
37     endif
38   endif
40   " Subtract a 'shiftwidth' on a then, do, else, esac, fi, done
41   " Retain the indentation level if line matches fin (for find)
42   let line = getline(v:lnum)
43   if (line =~ '^\s*\(then\|do\|else\|elif\|esac\|fi\|done\)\>' || line =~ '^\s*}')
44         \ && line !~ '^\s*fi[ln]\>'
45     let ind = ind - &sw
46   endif
48   return ind
49 endfunction
51 let &cpo = s:cpo_save
52 unlet s:cpo_save