1" Vim indent file 2" Language: Makefile 3" Maintainer: Nikolai Weibull <[email protected]> 4" Latest Revision: 2005-06-29 5 6if exists("b:did_indent") 7 finish 8endif 9let b:did_indent = 1 10 11setlocal indentexpr=GetMakeIndent() 12setlocal indentkeys=!^F,o,O 13 14if exists("*GetMakeIndent") 15 finish 16endif 17 18function s:GetStringWidth(line, str) 19 let end = matchend(a:line, a:str) 20 let width = 0 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 29endfunction 30 31function GetMakeIndent() 32 let lnum = v:lnum - 1 33 if lnum == 0 34 return 0 35 endif 36 37 let line = getline(lnum) 38 if line == '' 39 return 0 40 elseif line =~ '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)' 41 return indent(lnum) + &ts 42 elseif line =~ '^\s*\h\w*\s*+\==\s*.\+\\$' 43 return s:GetStringWidth(line, '+\==\s*') 44 endif 45endfunction 46