7
|
1 " Vim indent file
|
375
|
2 " Language: Autoconf configure.{ac,in} file
|
|
3 " Maintainer: Nikolai Weibull <nikolai+work.vim@bitwi.se>
|
389
|
4 " Latest Revision: 2005-06-30
|
375
|
5 " TODO: how about nested [()]'s in one line
|
|
6 " what's wrong with '\\\@!'?
|
7
|
7
|
|
8 " Only load this indent file when no other was loaded.
|
|
9 if exists("b:did_indent")
|
|
10 finish
|
|
11 endif
|
|
12
|
375
|
13 runtime! indent/sh.vim " will set b:did_indent
|
7
|
14
|
|
15 setlocal indentexpr=GetConfigIndent()
|
|
16 setlocal indentkeys=!^F,o,O,=then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
|
|
17
|
|
18 " Only define the function once.
|
|
19 if exists("*GetConfigIndent")
|
|
20 finish
|
|
21 endif
|
|
22
|
|
23 " get the offset (indent) of the end of the match of 'regexp' in 'line'
|
|
24 function s:GetOffsetOf(line, regexp)
|
|
25 let end = matchend(a:line, a:regexp)
|
|
26 let width = 0
|
|
27 let i = 0
|
|
28 while i < end
|
|
29 if a:line[i] != "\t"
|
|
30 let width = width + 1
|
|
31 else
|
|
32 let width = width + &ts - (width % &ts)
|
|
33 endif
|
|
34 let i = i + 1
|
|
35 endwhile
|
|
36 return width
|
|
37 endfunction
|
|
38
|
|
39 function GetConfigIndent()
|
|
40 " Find a non-blank line above the current line.
|
|
41 let lnum = prevnonblank(v:lnum - 1)
|
|
42
|
|
43 " Hit the start of the file, use zero indent.
|
|
44 if lnum == 0
|
|
45 return 0
|
|
46 endif
|
|
47
|
|
48 " where to put this
|
|
49 let ind = GetShIndent()
|
|
50 let line = getline(lnum)
|
|
51
|
|
52 " if previous line has unmatched, unescaped opening parentheses,
|
|
53 " indent to its position. TODO: not failsafe if multiple ('s
|
|
54 if line =~ '\\\@<!([^)]*$'
|
|
55 let ind = s:GetOffsetOf(line, '\\\@!(')
|
|
56 endif
|
|
57
|
|
58 " if previous line has unmatched opening bracket,
|
|
59 " indent to its position. TODO: same as above
|
|
60 if line =~ '\[[^]]*$'
|
|
61 let ind = s:GetOffsetOf(line, '\[')
|
|
62 endif
|
|
63
|
|
64 " if previous line had an unmatched closing parantheses,
|
|
65 " indent to the matching opening parantheses
|
|
66 if line =~ '[^(]*\\\@<!)$'
|
|
67 call search(')', 'bW')
|
|
68 let lnum = searchpair('\\\@<!(', '', ')', 'bWn')
|
|
69 let ind = indent(lnum)
|
|
70 endif
|
|
71
|
|
72 " if previous line had an unmatched closing bracket,
|
|
73 " indent to the matching opening bracket
|
|
74 if line =~ '[^[]*]$'
|
|
75 call search(']', 'bW')
|
|
76 let lnum = searchpair('\[', '', ']', 'bWn')
|
|
77 let ind = indent(lnum)
|
|
78 endif
|
|
79
|
|
80 return ind
|
|
81 endfunction
|
|
82
|
|
83 " vim: set sts=2 sw=2:
|