Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim indent file |
Bram Moolenaar | 214641f | 2017-03-05 17:04:09 +0100 | [diff] [blame] | 2 | " Language: YACC input file |
| 3 | " Previous Maintainer: Nikolai Weibull <now@bitwi.se> |
| 4 | " Latest Revision: 2006-12-20 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5 | |
| 6 | " Only load this indent file when no other was loaded. |
| 7 | if exists("b:did_indent") |
| 8 | finish |
| 9 | endif |
| 10 | |
| 11 | let b:did_indent = 1 |
| 12 | |
| 13 | setlocal indentexpr=GetYaccIndent() |
| 14 | setlocal indentkeys=!^F,o,O |
Bram Moolenaar | 335437b | 2007-05-10 18:32:52 +0000 | [diff] [blame] | 15 | setlocal nosmartindent |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 16 | |
| 17 | " Only define the function once. |
| 18 | if exists("*GetYaccIndent") |
| 19 | finish |
| 20 | endif |
| 21 | |
| 22 | function GetYaccIndent() |
| 23 | if v:lnum == 1 |
| 24 | return 0 |
| 25 | endif |
| 26 | |
| 27 | let ind = indent(v:lnum - 1) |
| 28 | let line = getline(v:lnum - 1) |
| 29 | |
| 30 | if line == '' |
| 31 | let ind = 0 |
| 32 | elseif line =~ '^\w\+\s*:' |
| 33 | let ind = ind + matchend(line, '^\w\+\s*') |
| 34 | elseif line =~ '^\s*;' |
| 35 | let ind = 0 |
| 36 | else |
| 37 | let ind = indent(v:lnum) |
| 38 | endif |
| 39 | |
| 40 | return ind |
| 41 | endfunction |