blob: 2ab7d7b38ccdf18fce12df556f9f40f5ee58d4b1 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
Bram Moolenaar335437b2007-05-10 18:32:52 +00002" Language: YACC input file
Bram Moolenaar57657d82006-04-21 22:12:41 +00003" Maintainer: Nikolai Weibull <now@bitwi.se>
Bram Moolenaar335437b2007-05-10 18:32:52 +00004" Latest Revision: 2006-12-20
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
Bram Moolenaar335437b2007-05-10 18:32:52 +000015setlocal nosmartindent
Bram Moolenaar071d4272004-06-13 20:20:40 +000016
17" Only define the function once.
18if exists("*GetYaccIndent")
19 finish
20endif
21
22function 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
41endfunction