annotate runtime/indent/config.vim @ 375:f14cbd913415 v7.0097

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