summaryrefslogtreecommitdiff
path: root/indent
diff options
context:
space:
mode:
Diffstat (limited to 'indent')
-rw-r--r--indent/pvx.vim56
1 files changed, 56 insertions, 0 deletions
diff --git a/indent/pvx.vim b/indent/pvx.vim
new file mode 100644
index 0000000..bd3931f
--- /dev/null
+++ b/indent/pvx.vim
@@ -0,0 +1,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