robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
1b74d2bf0a
master
1" Vim indent file 2" Language: Kotlin 3" Maintainer: Alexander Udalov 4" URL: https://github.com/udalov/kotlin-vim 5" Last Change: 7 November 2021 6" 2023 Sep 17 by Vim Project (undo_indent) 7 8if exists ( 'b:did_indent' ) 9finish 10endif 11let b: did_indent = 1 12 13setlocal cinoptions & cinoptions += j1,L0 14setlocal indentexpr = GetKotlinIndent () 15setlocal indentkeys = 0},0),!^F,o,O,e,<CR> 16setlocal autoindent " TODO ? 17 18let b: undo_indent = "setlocal autoindent< cinoptions< indentexpr< indentkeys<" 19 20" TODO teach it to count bracket balance, etc. 21function ! GetKotlinIndent () 22if v: lnum == 0 23return 0 24endif 25 26let prev_num = prevnonblank ( v: lnum - 1 ) 27let prev = getline ( prev_num ) 28let prev_indent = indent ( prev_num ) 29let cur = getline ( v: lnum ) 30 31if cur =~ '^\s*\*' 32return cindent ( v: lnum ) 33endif 34 35if prev =~ '^\s*\*/' 36let st = prev 37while st > 1 38if getline ( st ) =~ '^\s*/\*' 39break 40endif 41let st = st - 1 42endwhile 43return indent ( st ) 44endif 45 46let prev_open_paren = prev =~ '^.*(\s*$' 47let cur_close_paren = cur =~ '^\s*).*$' 48let prev_open_brace = prev =~ '^.*\({\|->\)\s*$' 49let cur_close_brace = cur =~ '^\s*}.*$' 50 51if prev_open_paren && ! cur_close_paren || prev_open_brace && ! cur_close_brace 52return prev_indent + shiftwidth () 53endif 54 55if cur_close_paren && ! prev_open_paren || cur_close_brace && ! prev_open_brace 56return prev_indent - shiftwidth () 57endif 58 59return prev_indent 60endfunction