diff options
| author | Calvin Morrison <calvin@pobox.com> | 2026-06-23 16:38:48 -0400 |
|---|---|---|
| committer | Calvin Morrison <calvin@pobox.com> | 2026-06-23 16:38:48 -0400 |
| commit | 66818f40225eb2c2722ba62a3743e478d9111b03 (patch) | |
| tree | 7dafd5994668a56578418ceea069bc7d8d020f18 /indent/pvx.vim | |
Highlights comments, strings, labels, control flow, and the object
method-call operator; indents to match the convention encoded in
native-sage-connector's formatpvx.pl (one tab per block level).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'indent/pvx.vim')
| -rw-r--r-- | indent/pvx.vim | 56 |
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 |
