blob: d100ceb38b7eb01ebafa0ea862700ffe43629339 [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
Bram Moolenaar57657d82006-04-21 22:12:41 +00003" Maintainer: Nikolai Weibull <now@bitwi.se>
4" Latest Revision: 2006-04-19
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