Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " 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. |
| 9 | if exists("b:did_indent") |
| 10 | finish |
| 11 | endif |
| 12 | |
| 13 | let b:did_indent = 1 |
| 14 | |
| 15 | setlocal indentexpr=GetMakeIndent() |
| 16 | setlocal indentkeys=!^F,o,O |
| 17 | |
| 18 | " Only define the function once. |
| 19 | if exists("*GetMakeIndent") |
| 20 | finish |
| 21 | endif |
| 22 | |
| 23 | function 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 |
| 36 | endfunction |
| 37 | |
| 38 | function 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 |
| 55 | endfunction |
| 56 | |
| 57 | " vim: set sts=2 sw=2: |