robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0c2a7aa5f7
master
1" Elm indent plugin file 2" Language: Elm 3" Maintainer: Andreas Scharf <as@99n.de> 4" Original Author: Joseph Hager <ajhager@gmail.com> 5" Copyright: Joseph Hager <ajhager@gmail.com> 6" License: BSD3 7" Latest Revision: 2021-09-29 8 9" Only load this indent file when no other was loaded. 10if exists ( 'b:did_indent' ) 11finish 12endif 13let b: did_indent = 1 14 15" Local defaults 16setlocal expandtab 17setlocal indentexpr = GetElmIndent () 18setlocal indentkeys += 0=else,0=if,0=of,0=import,0=then,0=type,0\|,0},0\],0),=-},0=in 19setlocal nolisp 20setlocal nosmartindent 21 22let b: undo_indent = "setl et< inde< indk< lisp< si<" 23 24" Only define the function once. 25if exists ( '*GetElmIndent' ) 26finish 27endif 28 29" Indent pairs 30function ! s: FindPair ( pstart , pmid , pend ) 31"call search(a:pend, 'bW') 32return indent ( searchpair ( a: pstart , a: pmid , a: pend , 'bWn' , 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"' )) 33endfunction 34 35function ! GetElmIndent () 36let l: lnum = v: lnum - 1 37 38" Ident 0 if the first line of the file: 39if l: lnum == 0 40return 0 41endif 42 43let l: ind = indent ( l: lnum ) 44let l: lline = getline ( l: lnum ) 45let l: line = getline ( v: lnum ) 46 47" Indent if current line begins with '}': 48if l: line =~? '^\s*}' 49return s: FindPair ( '{' , '' , '}' ) 50 51" Indent if current line begins with 'else': 52elseif l: line =~# '^\s*else\>' 53if l: lline !~# '^\s*\(if\|then\)\>' 54return s: FindPair ( '\<if\>' , '' , '\<else\>' ) 55endif 56 57" Indent if current line begins with 'then': 58elseif l: line =~# '^\s*then\>' 59if l: lline !~# '^\s*\(if\|else\)\>' 60return s: FindPair ( '\<if\>' , '' , '\<then\>' ) 61endif 62 63" HACK: Indent lines in case with nearest case clause: 64elseif l: line =~# '->' && l: line !~# ':' && l: line !~# '\\' 65return indent ( search ( '^\s*case' , 'bWn' )) + & shiftwidth 66 67" HACK: Don't change the indentation if the last line is a comment. 68elseif l: lline =~# '^\s*--' 69return l: ind 70 71" Align the end of block comments with the start 72elseif l: line =~# '^\s*-}' 73return indent ( search ( '{-' , 'bWn' )) 74 75" Indent double shift after let with an empty rhs 76elseif l: lline =~# '\<let\>.*\s=$' 77return l: ind + 4 + & shiftwidth 78 79" Align 'in' with the parent let. 80elseif l: line =~# '^\s*in\>' 81return indent ( search ( '^\s*let' , 'bWn' )) 82 83" Align bindings with the parent let. 84elseif l: lline =~# '\<let\>' 85return l: ind + 4 86 87" Align bindings with the parent in. 88elseif l: lline =~# '^\s*in\>' 89return l: ind 90 91endif 92 93" Add a 'shiftwidth' after lines ending with: 94if l: lline =~# '\(|\|=\|->\|<-\|(\|\[\|{\|\<\(of\|else\|if\|then\)\)\s*$' 95let l: ind = l: ind + & shiftwidth 96 97" Add a 'shiftwidth' after lines starting with type ending with '=': 98elseif l: lline =~# '^\s*type' && l: line =~# '^\s*=' 99let l: ind = l: ind + & shiftwidth 100 101" Back to normal indent after comments: 102elseif l: lline =~# '-}\s*$' 103call search ( '-}' , 'bW' ) 104let l: ind = indent ( searchpair ( '{-' , '' , '-}' , 'bWn' , 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"' )) 105 106" Ident some operators if there aren't any starting the last line. 107elseif l: line =~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l: lline !~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l: lline !~# '^\s*$' 108let l: ind = l: ind + & shiftwidth 109 110elseif l: lline ==# '' && getline ( l: lnum - 1 ) !=# '' 111let l: ind = indent ( search ( '^\s*\S+' , 'bWn' )) 112 113endif 114 115return l: ind 116endfunc