robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
4de7038762
master
1" Vim indent file 2" Language: Haskell Cabal Build file 3" Maintainer: Mateo Gjika <@mateoxh> 4 5if exists ( 'b:did_indent' ) 6finish 7endif 8 9let b: did_indent = 1 10 11setlocal indentexpr = GetCabalIndent () 12setlocal indentkeys = !^F,o,O,e,0=elif,<:> 13 14let b: undo_indent = 'setlocal inde< indk<' 15 16let s: save_cpo = & cpo 17set cpo & vim 18 19function ! GetCabalIndent () abort 20let categories = '\v\c^<(executable|(foreign-)?library|flag|source-repository|test-suite|benchmark|common|custom-setup)>' 21let line = getline ( v: lnum ) 22let prevline = getline ( v: lnum - 1 ) 23 24if line =~# categories 25return 0 26endif 27 28if line =~# '^\s*--' 29return -1 30endif 31 32if line =~# '^\s*}' 33let [ lnum , col ] = s: searchpairpos ( '{' , '' , '}' , 'bnW' ) 34if [ lnum , col ] == [ 0 , 0 ] 35return -1 36else 37return indent ( lnum ) 38endif 39endif 40 41if line =~# '^\s*||' 42if prevline =~# '^\s*||' 43return indent ( v: lnum - 1 ) 44else 45return indent ( v: lnum - 1 ) + 1 46endif 47endif 48 49if line =~# '\v^\s*<elif>' 50let [ lnum , col ] = s: searchpairpos ( '\v<if>' , '' , '\v<elif>\zs' , 'bnW' ) 51return col - 1 52elseif line =~# '\v^\s*<else>' 53let [ lnum , col ] = s: searchpairpos ( '\v<if>' , '\v<elif>' , '\v<else>\zs' , 'bnW' ) 54return col - 1 55endif 56 57if prevline =~# '\v^\s*<(if|elif|else)>' 58return indent ( v: lnum - 1 ) + shiftwidth () 59endif 60 61if prevline =~# categories 62return indent ( v: lnum - 1 ) + shiftwidth () 63endif 64 65if empty ( prevline ) || line =~# '\v^\s*\S+:' 66call cursor ( v: lnum , 1 ) 67let prevCond = search ( '\v^\s*<(if|elif|else)>' , 'bnW' , 0 , 0 , 68 \"synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment'" ) 69let prevCat = search ( categories , 'bnW' , 0 , 0 , 70 \"synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment'" ) 71if prevCond > prevCat 72return indent ( v: lnum ) > indent ( prevCond ) 73 \? indent ( prevCond ) + shiftwidth () 74 \: indent ( prevCond ) 75elseif prevCat > 0 76return indent ( prevCat ) + shiftwidth () 77else 78return 0 79endif 80endif 81 82if line !~# '\v^\s*(<if>|--)' 83if prevline =~# '\v^\s*\S+:$' 84return indent ( v: lnum - 1 ) + shiftwidth () 85endif 86if prevline =~# '\v^\s*\S+:\s*\S' 87return match ( prevline , '\v^\s*\S+:\s*\zs' ) 88endif 89endif 90 91return indent ( prevnonblank ( v: lnum - 1 )) 92endfunction 93 94function ! s: searchpairpos ( start , middle , end , flags ) abort 95return searchpairpos ( a: start , a: middle , a: end , a: flags , 96 \"synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment'" ) 97endfunction 98 99let & cpo = s: save_cpo 100unlet s: save_cpo