Mercurial > hg > RemoteEditor > vim7
comparison runtime/indent/ld.vim @ 0:76efa0be13f1
Initial revision
author | atsuki |
---|---|
date | Sat, 10 Nov 2007 15:07:22 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:76efa0be13f1 |
---|---|
1 " Vim indent file | |
2 " Language: ld(1) script | |
3 " Maintainer: Nikolai Weibull <now@bitwi.se> | |
4 " Latest Revision: 2006-12-20 | |
5 | |
6 if exists("b:did_indent") | |
7 finish | |
8 endif | |
9 let b:did_indent = 1 | |
10 | |
11 setlocal indentexpr=GetLDIndent() | |
12 setlocal indentkeys=0{,0},!^F,o,O | |
13 setlocal nosmartindent | |
14 | |
15 if exists("*GetLDIndent") | |
16 finish | |
17 endif | |
18 | |
19 function s:prevnonblanknoncomment(lnum) | |
20 let lnum = a:lnum | |
21 while lnum > 1 | |
22 let lnum = prevnonblank(lnum) | |
23 let line = getline(lnum) | |
24 if line =~ '\*/' | |
25 while lnum > 1 && line !~ '/\*' | |
26 let lnum -= 1 | |
27 endwhile | |
28 if line =~ '^\s*/\*' | |
29 let lnum -= 1 | |
30 else | |
31 break | |
32 endif | |
33 else | |
34 break | |
35 endif | |
36 endwhile | |
37 return lnum | |
38 endfunction | |
39 | |
40 function s:count_braces(lnum, count_open) | |
41 let n_open = 0 | |
42 let n_close = 0 | |
43 let line = getline(a:lnum) | |
44 let pattern = '[{}]' | |
45 let i = match(line, pattern) | |
46 while i != -1 | |
47 if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'ld\%(Comment\|String\)' | |
48 if line[i] == '{' | |
49 let n_open += 1 | |
50 elseif line[i] == '}' | |
51 if n_open > 0 | |
52 let n_open -= 1 | |
53 else | |
54 let n_close += 1 | |
55 endif | |
56 endif | |
57 endif | |
58 let i = match(line, pattern, i + 1) | |
59 endwhile | |
60 return a:count_open ? n_open : n_close | |
61 endfunction | |
62 | |
63 function GetLDIndent() | |
64 let line = getline(v:lnum) | |
65 if line =~ '^\s*\*' | |
66 return cindent(v:lnum) | |
67 elseif line =~ '^\s*}' | |
68 return indent(v:lnum) - &sw | |
69 endif | |
70 | |
71 let pnum = s:prevnonblanknoncomment(v:lnum - 1) | |
72 if pnum == 0 | |
73 return 0 | |
74 endif | |
75 | |
76 let ind = indent(pnum) + s:count_braces(pnum, 1) * &sw | |
77 | |
78 let pline = getline(pnum) | |
79 if pline =~ '}\s*$' | |
80 let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * &sw | |
81 endif | |
82 | |
83 return ind | |
84 endfunction |