robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ab20681c52
master
1" Vim indent file 2" Language: J 3" Maintainer: David Bürgin <dbuergin@gluet.ch> 4" URL: https://gitlab.com/glts/vim-j 5" Last Change: 2015-01-11 6 7if exists ( 'b:did_indent' ) 8finish 9endif 10let b: did_indent = 1 11 12setlocal indentexpr = GetJIndent () 13setlocal indentkeys -= 0{,0},:,0# 14setlocal indentkeys += 0),0<:>,=case.,=catch.,=catchd.,=catcht.,=do.,=else.,=elseif.,=end.,=fcase. 15 16let b: undo_indent = 'setlocal indentkeys< indentexpr<' 17 18if exists ( '*GetJIndent' ) 19finish 20endif 21 22" If g:j_indent_definitions is true, the bodies of explicit definitions of 23" adverbs, conjunctions, and verbs will be indented. Default is false (0). 24if ! exists ( 'g:j_indent_definitions' ) 25let g: j_indent_definitions = 0 26endif 27 28function GetJIndent () abort 29let l: prevlnum = prevnonblank ( v: lnum - 1 ) 30if l: prevlnum == 0 31return 0 32endif 33let l: indent = indent ( l: prevlnum ) 34let l: prevline = getline ( l: prevlnum ) 35if l: prevline =~# '^\s*\%(case\|catch[dt]\=\|do\|else\%(if\)\=\|fcase\|for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.\%(\%(\<end\.\)\@!.\)*$' 36" Increase indentation after an initial control word that starts or 37" continues a block and is not terminated by "end." 38let l: indent += shiftwidth () 39elseif g: j_indent_definitions && ( l: prevline =~# '\<\%([1-4]\|13\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\>' || l: prevline =~# '^\s*:\s*$' ) 40" Increase indentation in explicit definitions of adverbs, conjunctions, 41" and verbs 42let l: indent += shiftwidth () 43endif 44" Decrease indentation in lines that start with either control words that 45" continue or end a block, or the special items ")" and ":" 46if getline ( v: lnum ) =~# '^\s*\%()\|:\|\%(case\|catch[dt]\=\|do\|else\%(if\)\=\|end\|fcase\)\.\)' 47let l: indent -= shiftwidth () 48endif 49return l: indent 50endfunction