codekingpro/portable-devtools
114k
1" Elm indent plugin file2" Language: Elm3" Maintainer: Andreas Scharf <as@99n.de>4" Original Author: Joseph Hager <ajhager@gmail.com>5" Copyright: Joseph Hager <ajhager@gmail.com>6" License: BSD37" Latest Revision: 2021-09-298 9" Only load this indent file when no other was loaded.10if exists('b:did_indent')11 finish12endif13let b:did_indent = 114 15" Local defaults16setlocal expandtab17setlocal indentexpr=GetElmIndent()18setlocal indentkeys+=0=else,0=if,0=of,0=import,0=then,0=type,0\|,0},0\],0),=-},0=in19setlocal nolisp20setlocal nosmartindent21 22let b:undo_indent = "setl et< inde< indk< lisp< si<"23 24" Only define the function once.25if exists('*GetElmIndent')26 finish27endif28 29" Indent pairs30function! s:FindPair(pstart, pmid, pend)31 "call search(a:pend, 'bW')32 return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))33endfunction34 35function! GetElmIndent()36 let l:lnum = v:lnum - 137 38 " Ident 0 if the first line of the file:39 if l:lnum == 040 return 041 endif42 43 let l:ind = indent(l:lnum)44 let l:lline = getline(l:lnum)45 let l:line = getline(v:lnum)46 47 " Indent if current line begins with '}':48 if l:line =~? '^\s*}'49 return s:FindPair('{', '', '}')50 51 " Indent if current line begins with 'else':52 elseif l:line =~# '^\s*else\>'53 if l:lline !~# '^\s*\(if\|then\)\>'54 return s:FindPair('\<if\>', '', '\<else\>')55 endif56 57 " Indent if current line begins with 'then':58 elseif l:line =~# '^\s*then\>'59 if l:lline !~# '^\s*\(if\|else\)\>'60 return s:FindPair('\<if\>', '', '\<then\>')61 endif62 63 " HACK: Indent lines in case with nearest case clause:64 elseif l:line =~# '->' && l:line !~# ':' && l:line !~# '\\'65 return indent(search('^\s*case', 'bWn')) + &shiftwidth66 67 " HACK: Don't change the indentation if the last line is a comment.68 elseif l:lline =~# '^\s*--'69 return l:ind70 71 " Align the end of block comments with the start72 elseif l:line =~# '^\s*-}'73 return indent(search('{-', 'bWn'))74 75 " Indent double shift after let with an empty rhs76 elseif l:lline =~# '\<let\>.*\s=$'77 return l:ind + 4 + &shiftwidth78 79 " Align 'in' with the parent let.80 elseif l:line =~# '^\s*in\>'81 return indent(search('^\s*let', 'bWn'))82 83 " Align bindings with the parent let.84 elseif l:lline =~# '\<let\>'85 return l:ind + 486 87 " Align bindings with the parent in.88 elseif l:lline =~# '^\s*in\>'89 return l:ind90 91 endif92 93 " Add a 'shiftwidth' after lines ending with:94 if l:lline =~# '\(|\|=\|->\|<-\|(\|\[\|{\|\<\(of\|else\|if\|then\)\)\s*$'95 let l:ind = l:ind + &shiftwidth96 97 " Add a 'shiftwidth' after lines starting with type ending with '=':98 elseif l:lline =~# '^\s*type' && l:line =~# '^\s*='99 let l:ind = l:ind + &shiftwidth100 101 " Back to normal indent after comments:102 elseif l:lline =~# '-}\s*$'103 call search('-}', 'bW')104 let 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.107 elseif l:line =~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*$'108 let l:ind = l:ind + &shiftwidth109 110 elseif l:lline ==# '' && getline(l:lnum - 1) !=# ''111 let l:ind = indent(search('^\s*\S+', 'bWn'))112 113 endif114 115 return l:ind116endfunc117 