Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim indent file |
| 2 | " Language: RPL/2 |
| 3 | " Version: 0.2 |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 4 | " Last Change: 2017 Jun 13 |
Bram Moolenaar | cb80aa2 | 2020-10-26 21:12:46 +0100 | [diff] [blame] | 5 | " Maintainer: BERTRAND Joël <rpl2@free.fr> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6 | |
| 7 | " Only load this indent file when no other was loaded. |
| 8 | if exists("b:did_indent") |
| 9 | finish |
| 10 | endif |
| 11 | let b:did_indent = 1 |
| 12 | |
Bram Moolenaar | 582fd85 | 2005-03-28 20:58:01 +0000 | [diff] [blame] | 13 | setlocal autoindent |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 14 | setlocal 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 |
| 17 | setlocal indentexpr=RplGetFreeIndent() |
| 18 | if exists("*RplGetFreeIndent") |
| 19 | finish |
| 20 | endif |
| 21 | |
Bram Moolenaar | 582fd85 | 2005-03-28 20:58:01 +0000 | [diff] [blame] | 22 | let b:undo_indent = "set ai< indentkeys< indentexpr<" |
| 23 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 24 | function RplGetIndent(lnum) |
| 25 | let ind = indent(a:lnum) |
| 26 | let prevline=getline(a:lnum) |
| 27 | " Strip tail comment |
| 28 | let 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 |
| 32 | if prevstat =~? '\<\(if\|iferr\|do\|while\)\>' && prevstat =~? '\<end\>' |
| 33 | elseif prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)' && prevstat =~? '\s\+>>\($\|\s\+\)' |
| 34 | elseif prevstat =~? '\<\(if\|iferr\|then\|else\|elseif\|select\|case\|do\|until\|while\|repeat\|for\|start\|default\)\>' || prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 35 | let ind = ind + shiftwidth() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 36 | endif |
| 37 | |
| 38 | " Subtract a shiftwidth from then, else, elseif, end, until, repeat, next, |
| 39 | " step |
| 40 | let line = getline(v:lnum) |
| 41 | if line =~? '^\s*\(then\|else\|elseif\|until\|repeat\|next\|step\|default\|end\)\>' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 42 | let ind = ind - shiftwidth() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 43 | elseif line =~? '^\s*>>\($\|\s\+\)' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 44 | let ind = ind - shiftwidth() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 45 | endif |
| 46 | |
| 47 | return ind |
| 48 | endfunction |
| 49 | |
| 50 | function RplGetFreeIndent() |
| 51 | " Find the previous non-blank line |
| 52 | let lnum = prevnonblank(v:lnum - 1) |
| 53 | |
| 54 | " Use zero indent at the top of the file |
| 55 | if lnum == 0 |
| 56 | return 0 |
| 57 | endif |
| 58 | |
| 59 | let ind=RplGetIndent(lnum) |
| 60 | return ind |
| 61 | endfunction |
| 62 | |
| 63 | " vim:sw=2 tw=130 |