Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 1 | " Vim indent file |
| 2 | " Language: ld(1) script |
| 3 | " Maintainer: Nikolai Weibull <nikolai+work.vim@bitwi.se> |
Bram Moolenaar | 42eeac3 | 2005-06-29 22:40:58 +0000 | [diff] [blame] | 4 | " Latest Revision: 2005-06-29 |
Bram Moolenaar | 24bbcfe | 2005-06-28 23:32:02 +0000 | [diff] [blame] | 5 | |
| 6 | if exists("b:did_indent") |
| 7 | finish |
| 8 | endif |
| 9 | let b:did_indent = 1 |
| 10 | |
| 11 | setlocal indentexpr=GetLDIndent() |
| 12 | setlocal indentkeys=0{,0},!^F,o,O |
| 13 | |
| 14 | if exists("*GetLDIndent") |
| 15 | finish |
| 16 | endif |
| 17 | |
| 18 | function s:count_braces(lnum, count_open) |
| 19 | let n_open = 0 |
| 20 | let n_close = 0 |
| 21 | let line = getline(a:lnum) |
| 22 | let pattern = '[{}]' |
| 23 | let i = match(line, pattern) |
| 24 | while i != -1 |
| 25 | if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'ld\%(Comment\|String\)' |
| 26 | if line[i] == '{' |
| 27 | let n_open += 1 |
| 28 | elseif line[i] == '}' |
| 29 | if n_open > 0 |
| 30 | let n_open -= 1 |
| 31 | else |
| 32 | let n_close += 1 |
| 33 | endif |
| 34 | endif |
| 35 | endif |
| 36 | let i = match(line, pattern, i + 1) |
| 37 | endwhile |
| 38 | return a:count_open ? n_open : n_close |
| 39 | endfunction |
| 40 | |
| 41 | function GetLDIndent() |
| 42 | let pnum = prevnonblank(v:lnum - 1) |
| 43 | if pnum == 0 |
| 44 | return 0 |
| 45 | endif |
| 46 | |
| 47 | return indent(pnum) + s:count_braces(pnum, 1) * &sw |
| 48 | \ - s:count_braces(v:lnum, 0) * &sw |
| 49 | endfunction |