blob: 6c39c69687028b5961ffb8c38498cac4b87d9f2d [file] [log] [blame]
Bram Moolenaar662db672011-03-22 14:05:35 +01001" Vim indent file
Bram Moolenaarce001a32022-04-27 15:25:03 +01002" Language: Treetop
3" Maintainer: Doug Kearns <dougkearns@gmail.com>
4" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
5" Last Change: 2022 April 25
Bram Moolenaar662db672011-03-22 14:05:35 +01006
7if exists("b:did_indent")
8 finish
9endif
10let b:did_indent = 1
11
12setlocal indentexpr=GetTreetopIndent()
13setlocal indentkeys=0{,0},!^F,o,O,=end
14setlocal nosmartindent
15
Bram Moolenaarce001a32022-04-27 15:25:03 +010016let b:undo_indent = "setl inde< indk< si<"
17
Bram Moolenaar662db672011-03-22 14:05:35 +010018if exists("*GetTreetopIndent")
19 finish
20endif
21
22function GetTreetopIndent()
23 let pnum = prevnonblank(v:lnum - 1)
24 if pnum == 0
25 return 0
26 endif
27
28 let ind = indent(pnum)
29 let line = getline(pnum)
30
31 if line =~ '^\s*\%(grammar\|module\|rule\)\>'
Bram Moolenaar036986f2017-03-16 17:41:02 +010032 let ind += shiftwidth()
Bram Moolenaar662db672011-03-22 14:05:35 +010033 endif
34
35 let line = getline(v:lnum)
36 if line =~ '^\s*end\>'
Bram Moolenaar036986f2017-03-16 17:41:02 +010037 let ind -= shiftwidth()
Bram Moolenaar662db672011-03-22 14:05:35 +010038 end
39
Bram Moolenaar6c391a72021-09-09 21:55:11 +020040 return ind
Bram Moolenaar662db672011-03-22 14:05:35 +010041endfunction