annotate runtime/indent/config.vim @ 400:a4ba09cd859e

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