summaryrefslogtreecommitdiff
path: root/runtime/indent/make.vim
blob: 9db77f004aa992d06b390d9a656bb5d9cef1af46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
" Vim indent file
" Language:         Makefile
" Maintainer:       Nikolai Weibull <nikolai+work.vim@bitwi.se>
" Latest Revision:  2005-06-29

if exists("b:did_indent")
  finish
endif
let b:did_indent = 1

setlocal indentexpr=GetMakeIndent()
setlocal indentkeys=!^F,o,O

if exists("*GetMakeIndent")
  finish
endif

function s:GetStringWidth(line, str)
  let end = matchend(a:line, a:str)
  let width = 0
  for c in a:line
    if c == "\t"
      let width += &ts - (width % &ts)
    else
      let width += 1
    endif
  endfor
  return width
endfunction

function GetMakeIndent()
  let lnum = v:lnum - 1
  if lnum == 0
    return 0
  endif

  let line = getline(lnum)
  if line == ''
    return 0
  elseif line =~ '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)'
    return indent(lnum) + &ts
  elseif line =~ '^\s*\h\w*\s*+\==\s*.\+\\$'
    return s:GetStringWidth(line, '+\==\s*')
  endif
endfunction