blob: f376424ad81c31b01a339a759eb19403c2912283 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
2" Language: Makefile
3" Maintainer: Nikolai Weibull <source@pcppopper.org>
4" URL: http://www.pcppopper.org/vim/indent/pcp/make/
5" Latest Revision: 2004-04-25
6" arch-tag: b539e147-a05c-4860-98af-1d2436db2f4b
7
8" Only load this indent file when no other was loaded.
9if exists("b:did_indent")
10 finish
11endif
12
13let b:did_indent = 1
14
15setlocal indentexpr=GetMakeIndent()
16setlocal indentkeys=!^F,o,O
17
18" Only define the function once.
19if exists("*GetMakeIndent")
20 finish
21endif
22
23function s:GetStringWidth(line, str)
24 let end = matchend(a:line, a:str)
25 let width = 0
26 let i = 0
27 while i < end
28 if a:line[i] != "\t"
29 let width = width + 1
30 else
31 let width = width + &ts - (width % &ts)
32 endif
33 let i = i + 1
34 endwhile
35 return width
36endfunction
37
38function GetMakeIndent()
39 if v:lnum == 1
40 return 0
41 endif
42
43 let ind = indent(v:lnum - 1)
44 let line = getline(v:lnum - 1)
45
46 if line == ''
47 let ind = 0
48 elseif line =~ '^[^ \t#:][^#:]*:\{1,2}\([^=:]\|$\)'
49 let ind = ind + &ts
50 elseif line =~ '^\s*\h\w*\s*=\s*.\+\\$'
51 let ind = s:GetStringWidth(line, '=\s*')
52 endif
53
54 return ind
55endfunction
56
57" vim: set sts=2 sw=2: