summaryrefslogtreecommitdiffstats
path: root/runtime/indent/rpl.vim
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 08:50:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 08:50:31 +0000
commitaed8ce9da277f5ecffe968b324f242c41c3b752a (patch)
treed2e538394cb7a8a7c42a4aac6ccf1a8e3256999b /runtime/indent/rpl.vim
parentInitial commit. (diff)
downloadvim-aed8ce9da277f5ecffe968b324f242c41c3b752a.tar.xz
vim-aed8ce9da277f5ecffe968b324f242c41c3b752a.zip
Adding upstream version 2:9.0.1378.upstream/2%9.0.1378upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'runtime/indent/rpl.vim')
-rw-r--r--runtime/indent/rpl.vim63
1 files changed, 63 insertions, 0 deletions
diff --git a/runtime/indent/rpl.vim b/runtime/indent/rpl.vim
new file mode 100644
index 0000000..8577c4d
--- /dev/null
+++ b/runtime/indent/rpl.vim
@@ -0,0 +1,63 @@
+" Vim indent file
+" Language: RPL/2
+" Version: 0.2
+" Last Change: 2017 Jun 13
+" Maintainer: BERTRAND Joël <rpl2@free.fr>
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal autoindent
+setlocal indentkeys+==~end,=~case,=~if,=~then,=~else,=~do,=~until,=~while,=~repeat,=~select,=~default,=~for,=~start,=~next,=~step,<<>,<>>
+
+" Define the appropriate indent function but only once
+setlocal indentexpr=RplGetFreeIndent()
+if exists("*RplGetFreeIndent")
+ finish
+endif
+
+let b:undo_indent = "set ai< indentkeys< indentexpr<"
+
+function RplGetIndent(lnum)
+ let ind = indent(a:lnum)
+ let prevline=getline(a:lnum)
+ " Strip tail comment
+ let prevstat=substitute(prevline, '!.*$', '', '')
+
+ " Add a shiftwidth to statements following if, iferr, then, else, elseif,
+ " case, select, default, do, until, while, repeat, for, start
+ if prevstat =~? '\<\(if\|iferr\|do\|while\)\>' && prevstat =~? '\<end\>'
+ elseif prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)' && prevstat =~? '\s\+>>\($\|\s\+\)'
+ elseif prevstat =~? '\<\(if\|iferr\|then\|else\|elseif\|select\|case\|do\|until\|while\|repeat\|for\|start\|default\)\>' || prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)'
+ let ind = ind + shiftwidth()
+ endif
+
+ " Subtract a shiftwidth from then, else, elseif, end, until, repeat, next,
+ " step
+ let line = getline(v:lnum)
+ if line =~? '^\s*\(then\|else\|elseif\|until\|repeat\|next\|step\|default\|end\)\>'
+ let ind = ind - shiftwidth()
+ elseif line =~? '^\s*>>\($\|\s\+\)'
+ let ind = ind - shiftwidth()
+ endif
+
+ return ind
+endfunction
+
+function RplGetFreeIndent()
+ " Find the previous non-blank line
+ let lnum = prevnonblank(v:lnum - 1)
+
+ " Use zero indent at the top of the file
+ if lnum == 0
+ return 0
+ endif
+
+ let ind=RplGetIndent(lnum)
+ return ind
+endfunction
+
+" vim:sw=2 tw=130