Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim indent file |
| 2 | " Language: YACC input file |
| 3 | " Maintainer: Nikolai Weibull <source@pcppopper.org> |
| 4 | " URL: http://www.pcppopper.org/vim/indent/pcp/yacc/ |
| 5 | " Latest Revision: 2004-04-25 |
| 6 | " arch-tag: 629aa719-8fe4-4787-adb7-ae94ca801610 |
| 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=GetYaccIndent() |
| 16 | setlocal indentkeys=!^F,o,O |
| 17 | |
| 18 | " Only define the function once. |
| 19 | if exists("*GetYaccIndent") |
| 20 | finish |
| 21 | endif |
| 22 | |
| 23 | function GetYaccIndent() |
| 24 | if v:lnum == 1 |
| 25 | return 0 |
| 26 | endif |
| 27 | |
| 28 | let ind = indent(v:lnum - 1) |
| 29 | let line = getline(v:lnum - 1) |
| 30 | |
| 31 | if line == '' |
| 32 | let ind = 0 |
| 33 | elseif line =~ '^\w\+\s*:' |
| 34 | let ind = ind + matchend(line, '^\w\+\s*') |
| 35 | elseif line =~ '^\s*;' |
| 36 | let ind = 0 |
| 37 | else |
| 38 | let ind = indent(v:lnum) |
| 39 | endif |
| 40 | |
| 41 | return ind |
| 42 | endfunction |
| 43 | |
| 44 | " vim: set sts=2 sw=2: |