Subversion Repositories programming

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
361 ira 1
" Vim indent file
2
" Language:	     Shell Script
3
" Maintainer:    Nikolai Weibull <now@bitwi.se>
4
" Modified:      Edward L. Fox <edyfox@gmail.com>
5
" Last Modified: 2006-07-31 19:21:11
6
 
7
if exists("b:did_indent")
8
    finish
9
endif
10
let b:did_indent = 1
11
 
12
setlocal indentexpr=GetShIndent()
13
setlocal indentkeys+==then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
14
setlocal indentkeys-=:,0#
15
 
16
if exists("*GetShIndent")
17
    finish
18
endif
19
 
20
let s:cpo_save = &cpo
21
set cpo&vim
22
 
23
function GetShIndent()
24
    let lnum = prevnonblank(v:lnum - 1)
25
    if lnum == 0
26
        return 0
27
    endif
28
 
29
    " Add a 'shiftwidth' after if, while, else, case, until, for, function()
30
    " Skip if the line also contains the closure for the above
31
 
32
    let ind = indent(lnum)
33
    let line = getline(lnum)
34
    if line =~ '^\s*\(if\|then\|do\|else\|elif\|while\|until\|for\)\>'
35
                \ || (line =~ '^\s*case\>' && g:sh_indent_case_labels)
36
                \ || line =~ '^\s*\<\k\+\>\s*()\s*{'
37
                \ || line =~ '^\s*[^(]\+\s*)'
38
                \ || line =~ '^\s*{'
39
        if line !~ '\(esac\|fi\|done\)\>\s*$' && line !~ '}\s*$'
40
            let ind = ind + &sw
41
        endif
42
    endif
43
 
44
    if line =~ ';;'
45
        let ind = ind - &sw
46
    endif
47
 
48
    " Subtract a 'shiftwidth' on a then, do, else, esac, fi, done
49
    " Retain the indentation level if line matches fin (for find)
50
    let line = getline(v:lnum)
51
    if (line =~ '^\s*\(then\|do\|else\|elif\|fi\|done\)\>'
52
                \ || (line =~ '^\s*esac\>' && g:sh_indent_case_labels)
53
                \ || line =~ '^\s*}'
54
                \ )
55
                \ && line !~ '^\s*fi[ln]\>'
56
        let ind = ind - &sw
57
    endif
58
 
59
    return ind
60
endfunction
61
 
62
let &cpo = s:cpo_save
63
unlet s:cpo_save