blob: 9d0798d49237589cad495b582caf7426830554ed [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
Bram Moolenaar42eeac32005-06-29 22:40:58 +00002" Language: YACC input file
3" Maintainer: Nikolai Weibull <nikolai+work.vim@bitwi.se>
4" Latest Revision: 2005-06-29
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
6" Only load this indent file when no other was loaded.
7if exists("b:did_indent")
8 finish
9endif
10
11let b:did_indent = 1
12
13setlocal indentexpr=GetYaccIndent()
14setlocal indentkeys=!^F,o,O
15
16" Only define the function once.
17if exists("*GetYaccIndent")
18 finish
19endif
20
21function GetYaccIndent()
22 if v:lnum == 1
23 return 0
24 endif
25
26 let ind = indent(v:lnum - 1)
27 let line = getline(v:lnum - 1)
28
29 if line == ''
30 let ind = 0
31 elseif line =~ '^\w\+\s*:'
32 let ind = ind + matchend(line, '^\w\+\s*')
33 elseif line =~ '^\s*;'
34 let ind = 0
35 else
36 let ind = indent(v:lnum)
37 endif
38
39 return ind
40endfunction