comparison runtime/indent/make.vim @ 839:1f3b1021f002 v7.0e05

updated for version 7.0e05
author vimboss
date Fri, 21 Apr 2006 22:12:41 +0000
parents f14cbd913415
children d3bbb5dd3913
comparison
equal deleted inserted replaced
838:8e5830943bff 839:1f3b1021f002
1 " Vim indent file 1 " Vim indent file
2 " Language: Makefile 2 " Language: Makefile
3 " Maintainer: Nikolai Weibull <nikolai+work.vim@bitwi.se> 3 " Maintainer: Nikolai Weibull <now@bitwi.se>
4 " Latest Revision: 2005-06-29 4 " Latest Revision: 2006-04-19
5 5
6 if exists("b:did_indent") 6 if exists("b:did_indent")
7 finish 7 finish
8 endif 8 endif
9 let b:did_indent = 1 9 let b:did_indent = 1
13 13
14 if exists("*GetMakeIndent") 14 if exists("*GetMakeIndent")
15 finish 15 finish
16 endif 16 endif
17 17
18 function s:GetStringWidth(line, str) 18 let s:rule_rx = '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)'
19 let end = matchend(a:line, a:str) 19 let s:continuation_rx = '\\$'
20 let width = 0 20 let s:assignment_rx = '^\s*\h\w*\s*+\==\s*\zs.*\\$'
21 for c in a:line
22 if c == "\t"
23 let width += &ts - (width % &ts)
24 else
25 let width += 1
26 endif
27 endfor
28 return width
29 endfunction
30 21
31 function GetMakeIndent() 22 function GetMakeIndent()
32 let lnum = v:lnum - 1 23 let lnum = v:lnum - 1
33 if lnum == 0 24 if lnum == 0
34 return 0 25 return 0
35 endif 26 endif
36 27
37 let line = getline(lnum) 28 let line = getline(lnum)
38 if line == '' 29 let ind = indent(lnum)
39 return 0 30
40 elseif line =~ '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)' 31 if line =~ s:rule_rx
41 return indent(lnum) + &ts 32 return ind + &ts
42 elseif line =~ '^\s*\h\w*\s*+\==\s*.\+\\$' 33 elseif line =~ s:continuation_rx
43 return s:GetStringWidth(line, '+\==\s*') 34 while lnum > 0 && line =~ s:continuation_rx && line !~ s:assignment_rx
35 let lnum -= 1
36 let line = getline(lnum)
37 endwhile
38 if line =~ s:assignment_rx
39 call cursor(lnum, 1)
40 return search(s:assignment_rx, 'W') != 0 ? virtcol('.') - 1 : 0
41 else
42 return 0
43 endif
44 else
45 let pnum = lnum - 1
46 if pnum == 0
47 return ind
48 endif
49
50 return getline(pnum) =~ s:continuation_rx ? 0 : ind
44 endif 51 endif
45 endfunction 52 endfunction