robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ab20681c52
master
1" Vim indent file 2" Language: RPL/2 3" Version: 0.2 4" Last Change: 2017 Jun 13 5" Maintainer: BERTRAND Joël <rpl2@free.fr> 6 7" Only load this indent file when no other was loaded. 8if exists ( "b:did_indent" ) 9finish 10endif 11let b: did_indent = 1 12 13setlocal autoindent 14setlocal indentkeys += =~end,=~case,=~if,=~then,=~else,=~do,=~until,=~while,=~repeat,=~select,=~default,=~for,=~start,=~next,=~step,<<>,<>> 15 16" Define the appropriate indent function but only once 17setlocal indentexpr = RplGetFreeIndent () 18if exists ( "*RplGetFreeIndent" ) 19finish 20endif 21 22let b: undo_indent = "set ai< indentkeys< indentexpr<" 23 24function RplGetIndent ( lnum ) 25let ind = indent ( a: lnum ) 26let prevline = getline ( a: lnum ) 27" Strip tail comment 28let prevstat = substitute ( prevline , '!.*$' , '' , '' ) 29 30" Add a shiftwidth to statements following if, iferr, then, else, elseif, 31" case, select, default, do, until, while, repeat, for, start 32if prevstat =~? '\<\(if\|iferr\|do\|while\)\>' && prevstat =~? '\<end\>' 33elseif prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)' && prevstat =~? '\s\+>>\($\|\s\+\)' 34elseif prevstat =~? '\<\(if\|iferr\|then\|else\|elseif\|select\|case\|do\|until\|while\|repeat\|for\|start\|default\)\>' || prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)' 35let ind = ind + shiftwidth () 36endif 37 38" Subtract a shiftwidth from then, else, elseif, end, until, repeat, next, 39" step 40let line = getline ( v: lnum ) 41if line =~? '^\s*\(then\|else\|elseif\|until\|repeat\|next\|step\|default\|end\)\>' 42let ind = ind - shiftwidth () 43elseif line =~? '^\s*>>\($\|\s\+\)' 44let ind = ind - shiftwidth () 45endif 46 47return ind 48endfunction 49 50function RplGetFreeIndent () 51" Find the previous non-blank line 52let lnum = prevnonblank ( v: lnum - 1 ) 53 54" Use zero indent at the top of the file 55if lnum == 0 56return 0 57endif 58 59let ind = RplGetIndent ( lnum ) 60return ind 61endfunction 62 63" vim:sw=2 tw=130