robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
096cb572af
master
1" Vim indent file 2" Language: Idris 2 3" Maintainer: Idris Hackers (https://github.com/edwinb/idris2-vim), Serhii Khoma <srghma@gmail.com> 4" Author: raichoo <raichoo@googlemail.com> 5" Last Change: 2024 Nov 05 6" License: Vim (see :h license) 7" Repository: https://github.com/ShinKage/idris2-nvim 8" 9" indentation for idris (idris-lang.org) 10" 11" Based on haskell indentation by motemen <motemen@gmail.com> 12" 13" Indentation configuration variables: 14" 15" g:idris2_indent_if (default: 3) 16" Controls indentation after 'if' statements 17" Example: 18" if condition 19" >>>then expr 20" >>>else expr 21" 22" g:idris2_indent_case (default: 5) 23" Controls indentation of case expressions 24" Example: 25" case x of 26" >>>>>Left y => ... 27" >>>>>Right z => ... 28" 29" g:idris2_indent_let (default: 4) 30" Controls indentation after 'let' bindings 31" Example: 32" let x = expr in 33" >>>>body 34" 35" g:idris2_indent_rewrite (default: 8) 36" Controls indentation after 'rewrite' expressions 37" Example: 38" rewrite proof in 39" >>>>>>>>expr 40" 41" g:idris2_indent_where (default: 6) 42" Controls indentation of 'where' blocks 43" Example: 44" function args 45" >>>>>>where helper = expr 46" 47" g:idris2_indent_do (default: 3) 48" Controls indentation in 'do' blocks 49" Example: 50" do x <- action 51" >>>y <- action 52" 53" Example configuration in .vimrc: 54" let g:idris2_indent_if = 2 55 56if exists ( 'b:did_indent' ) 57finish 58endif 59 60setlocal indentexpr = GetIdrisIndent () 61setlocal indentkeys = !^F,o,O,} 62 63let b: did_indent = 1 64let b: undo_indent = "setlocal indentexpr< indentkeys<" 65 66" we want to use line continuations (\) BEGINNING 67let s: cpo_save = & cpo 68set cpo & vim 69 70" Define defaults for indent configuration 71let s: indent_defaults = { 72 \'idris2_indent_if' : 3 , 73 \'idris2_indent_case' : 5 , 74 \'idris2_indent_let' : 4 , 75 \'idris2_indent_rewrite' : 8 , 76 \'idris2_indent_where' : 6 , 77 \'idris2_indent_do' : 3 78 \} 79 80" we want to use line continuations (\) END 81let & cpo = s: cpo_save 82unlet s: cpo_save 83 84" Set up indent settings with user overrides 85for [ key , default ] in items ( s: indent_defaults ) 86let varname = 'g:' . key 87if ! exists ( varname ) 88execute 'let' varname '=' default 89endif 90endfor 91 92if exists ( "*GetIdrisIndent" ) 93finish 94endif 95 96function ! GetIdrisIndent () 97let prevline = getline ( v: lnum - 1 ) 98 99if prevline =~ '\s\+(\s*.\+\s\+:\s\+.\+\s*)\s\+->\s*$' 100return match ( prevline , '(' ) 101elseif prevline =~ '\s\+{\s*.\+\s\+:\s\+.\+\s*}\s\+->\s*$' 102return match ( prevline , '{' ) 103endif 104 105if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$' 106let s = match ( prevline , '[:=]' ) 107if s > 0 108return s + 2 109else 110return match ( prevline , '\S' ) 111endif 112endif 113 114if prevline =~ '[{([][^})\]]\+$' 115return match ( prevline , '[{([]' ) 116endif 117 118if prevline =~ '\<let\>\s\+.\+\<in\>\s*$' 119return match ( prevline , '\<let\>' ) + g: idris2_indent_let 120endif 121 122if prevline =~ '\<rewrite\>\s\+.\+\<in\>\s*$' 123return match ( prevline , '\<rewrite\>' ) + g: idris2_indent_rewrite 124endif 125 126if prevline !~ '\<else\>' 127let s = match ( prevline , '\<if\>.*\&.*\zs\<then\>' ) 128if s > 0 129return s 130endif 131 132let s = match ( prevline , '\<if\>' ) 133if s > 0 134return s + g: idris2_indent_if 135endif 136endif 137 138if prevline =~ '\(\<where\>\|\<do\>\|=\|[{([]\)\s*$' 139return match ( prevline , '\S' ) + & shiftwidth 140endif 141 142if prevline =~ '\<where\>\s\+\S\+.*$' 143return match ( prevline , '\<where\>' ) + g: idris2_indent_where 144endif 145 146if prevline =~ '\<do\>\s\+\S\+.*$' 147return match ( prevline , '\<do\>' ) + g: idris2_indent_do 148endif 149 150if prevline =~ '^\s*\<\(co\)\?data\>\s\+[^=]\+\s\+=\s\+\S\+.*$' 151return match ( prevline , '=' ) 152endif 153 154if prevline =~ '\<with\>\s\+([^)]*)\s*$' 155return match ( prevline , '\S' ) + & shiftwidth 156endif 157 158if prevline =~ '\<case\>\s\+.\+\<of\>\s*$' 159return match ( prevline , '\<case\>' ) + g: idris2_indent_case 160endif 161 162if prevline =~ '^\s*\(\<namespace\>\|\<\(co\)\?data\>\)\s\+\S\+\s*$' 163return match ( prevline , '\(\<namespace\>\|\<\(co\)\?data\>\)' ) + & shiftwidth 164endif 165 166if prevline =~ '^\s*\(\<using\>\|\<parameters\>\)\s*([^(]*)\s*$' 167return match ( prevline , '\(\<using\>\|\<parameters\>\)' ) + & shiftwidth 168endif 169 170if prevline =~ '^\s*\<mutual\>\s*$' 171return match ( prevline , '\<mutual\>' ) + & shiftwidth 172endif 173 174let line = getline ( v: lnum ) 175 176if ( line =~ '^\s*}\s*' && prevline !~ '^\s*;' ) 177return match ( prevline , '\S' ) - & shiftwidth 178endif 179 180return match ( prevline , '\S' ) 181endfunction 182 183" vim:et:sw=2:sts=2