Bram Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 1 | " Vim indent file |
| 2 | " Language: Oblivion Language (obl) |
| 3 | " Original Creator: Kat <katisntgood@gmail.com> |
| 4 | " Maintainer: Kat <katisntgood@gmail.com> |
| 5 | " Created: 01 November 2021 |
| 6 | " Last Change: 13 November 2022 |
| 7 | |
| 8 | if exists("b:did_indent") |
| 9 | finish |
| 10 | endif |
| 11 | let b:did_indent = 1 |
| 12 | let b:undo_indent = 'setlocal indentkeys< indentexpr<' |
| 13 | |
| 14 | setlocal indentexpr=GetOblIndent() |
| 15 | setlocal indentkeys+==~endif,=~else,=~loop,=~end |
| 16 | |
| 17 | if exists("*GetOblIndent") |
| 18 | finish |
| 19 | endif |
| 20 | let s:keepcpo = &cpo |
| 21 | set cpo&vim |
| 22 | |
| 23 | let s:SKIP_LINES = '^\s*\(;.*\)' |
| 24 | function! GetOblIndent() |
| 25 | |
| 26 | let lnum = prevnonblank(v:lnum - 1) |
| 27 | let cur_text = getline(v:lnum) |
| 28 | if lnum == 0 |
| 29 | return 0 |
| 30 | endif |
| 31 | let prev_text = getline(lnum) |
| 32 | let found_cont = 0 |
| 33 | let ind = indent(lnum) |
| 34 | |
| 35 | " indent next line on start terms |
| 36 | let i = match(prev_text, '\c^\s*\(\s\+\)\?\(\(if\|while\|foreach\|begin\|else\%[if]\)\>\)') |
| 37 | if i >= 0 |
| 38 | let ind += shiftwidth() |
| 39 | if strpart(prev_text, i, 1) == '|' && has('syntax_items') |
| 40 | \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$' |
| 41 | let ind -= shiftwidth() |
| 42 | endif |
| 43 | endif |
| 44 | " indent current line on end/else terms |
| 45 | if cur_text =~ '\c^\s*\(\s\+\)\?\(\(loop\|endif\|else\%[if]\)\>\)' |
| 46 | let ind = ind - shiftwidth() |
| 47 | " if we are at a begin block just go to column 0 |
| 48 | elseif cur_text =~ '\c^\s*\(\s\+\)\?\(\(begin\|end\)\>\)' |
| 49 | let ind = 0 |
| 50 | endif |
| 51 | return ind |
| 52 | endfunction |
| 53 | |
| 54 | let &cpo = s:keepcpo |
| 55 | unlet s:keepcpo |