summaryrefslogtreecommitdiff
path: root/indent/pvx.vim
blob: bd3931fb2628850a7f5c3e16618fd308f5e91a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
" Vim indent file
" Language:    ProvideX / PVX (Sage 100 business object source, *.pvxsrc)
" Maintainer:  native-sage-connector
"
" Mirrors the indent convention encoded in formatpvx.pl: a label, switch/
" case/default, for, while, repeat, or a trailing "{" opens one level;
" return, break, next, wend, until, else, end (def/switch/...), endif,
" endcase, or a leading "}" closes one level for that line itself.

if exists("b:did_indent")
  finish
endif
let b:did_indent = 1

setlocal indentexpr=GetPvxIndent()
setlocal indentkeys=o,O,0{,0},!^F,=end,=next,=wend,=until,=else,=break,=default,=case,=endif,=endcase
setlocal autoindent
setlocal nosmartindent
setlocal nocindent

if exists("*GetPvxIndent")
  finish
endif

" Strip leading indent, a trailing "! comment", and surrounding whitespace,
" so keyword patterns can be anchored at column 0 regardless of existing indent.
function! s:PvxStripComment(line)
  let l = substitute(a:line, '\s*!.*$', '', '')
  let l = substitute(l, '^\s*', '', '')
  return substitute(l, '\s*$', '', '')
endfunction

" Lines whose presence means the *next* line gets one more indent level.
let s:pvx_opener = '\c^\%(def\|switch\|case\|default\|for\|while\|repeat\)\>\|{\s*$\|^[A-Za-z_][A-Za-z0-9_.]*:\s*$'

" Lines that get one *less* indent level applied to themselves.
let s:pvx_closer = '\c^\%(end\|endif\|endcase\|next\|wend\|until\|else\|break\|return\)\>\|^}'

function! GetPvxIndent()
  let lnum = prevnonblank(v:lnum - 1)
  if lnum == 0
    return 0
  endif

  let ind = indent(lnum)

  if s:PvxStripComment(getline(lnum)) =~ s:pvx_opener
    let ind += &shiftwidth
  endif

  if s:PvxStripComment(getline(v:lnum)) =~ s:pvx_closer
    let ind -= &shiftwidth
  endif

  return ind < 0 ? 0 : ind
endfunction