xref: /vim-8.2.3635/runtime/indent/make.vim (revision 4a85b415)
1" Vim indent file
2" Language:         Makefile
3" Maintainer:       Nikolai Weibull <[email protected]>
4" Latest Revision:  2006-04-19
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
18let s:rule_rx = '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)'
19let s:continuation_rx = '\\$'
20let s:assignment_rx = '^\s*\h\w*\s*+\==\s*\zs.*\\$'
21
22function GetMakeIndent()
23  let lnum = v:lnum - 1
24  if lnum == 0
25    return 0
26  endif
27
28  let line = getline(lnum)
29  let ind = indent(lnum)
30
31  if line =~ s:rule_rx
32    return ind + &ts
33  elseif line =~ s:continuation_rx
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
51  endif
52endfunction
53