0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00
vim/runtime/indent/make.vim

53 lines
1.1 KiB
VimL
Raw Normal View History

2004-06-13 20:20:40 +00:00
" Vim indent file
2005-06-29 22:40:58 +00:00
" Language: Makefile
2006-04-21 22:12:41 +00:00
" Maintainer: Nikolai Weibull <now@bitwi.se>
" Latest Revision: 2006-04-19
2004-06-13 20:20:40 +00:00
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
2006-04-21 22:12:41 +00:00
let s:rule_rx = '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)'
let s:continuation_rx = '\\$'
let s:assignment_rx = '^\s*\h\w*\s*+\==\s*\zs.*\\$'
2004-06-13 20:20:40 +00:00
function GetMakeIndent()
2005-06-29 22:40:58 +00:00
let lnum = v:lnum - 1
if lnum == 0
2004-06-13 20:20:40 +00:00
return 0
endif
2005-06-29 22:40:58 +00:00
let line = getline(lnum)
2006-04-21 22:12:41 +00:00
let ind = indent(lnum)
if line =~ s:rule_rx
return ind + &ts
elseif line =~ s:continuation_rx
while lnum > 0 && line =~ s:continuation_rx && line !~ s:assignment_rx
let lnum -= 1
let line = getline(lnum)
endwhile
if line =~ s:assignment_rx
call cursor(lnum, 1)
return search(s:assignment_rx, 'W') != 0 ? virtcol('.') - 1 : 0
else
return 0
endif
else
let pnum = lnum - 1
if pnum == 0
return ind
endif
return getline(pnum) =~ s:continuation_rx ? 0 : ind
2004-06-13 20:20:40 +00:00
endif
endfunction