diff --git a/indent/elm.vim b/indent/elm.vim index 8e346ee..01e6bc5 100644 --- a/indent/elm.vim +++ b/indent/elm.vim @@ -9,7 +9,7 @@ let b:did_indent = 1 " Local defaults setlocal expandtab setlocal indentexpr=GetElmIndent() -setlocal indentkeys+=0=else,0=if,0=of,0=import,0=then,0=type,0\|,0},0\],0),=-},0=in +setlocal indentkeys+=0=else,0=if,0=of,0=import,0=then,0=type,0\|,0},0\],0),=-},0=in,0\= setlocal nolisp setlocal nosmartindent @@ -43,17 +43,9 @@ function! GetElmIndent() if l:line =~? '^\s*}' return s:FindPair('{', '', '}') - " Indent if current line begins with 'else': + " Align 'else' with the parent if. elseif l:line =~# '^\s*else\>' - if l:lline !~# '^\s*\(if\|then\)\>' - return s:FindPair('\', '', '\') - endif - - " Indent if current line begins with 'then': - elseif l:line =~# '^\s*then\>' - if l:lline !~# '^\s*\(if\|else\)\>' - return s:FindPair('\', '', '\') - endif + return indent(search('^\s*if', 'bWn')) " HACK: Indent lines in case with nearest case clause: elseif l:line =~# '->' && l:line !~# ':' && l:line !~# '\\' @@ -89,17 +81,14 @@ function! GetElmIndent() if l:lline =~# '\(|\|=\|->\|<-\|(\|\[\|{\|\<\(of\|else\|if\|then\)\)\s*$' let l:ind = l:ind + &shiftwidth - " Add a 'shiftwidth' after lines starting with type ending with '=': - elseif l:lline =~# '^\s*type' && l:line =~# '^\s*=' - let l:ind = l:ind + &shiftwidth - " Back to normal indent after comments: elseif l:lline =~# '-}\s*$' call search('-}', 'bW') let l:ind = indent(searchpair('{-', '', '-}', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')) " Ident some operators if there aren't any starting the last line. - elseif l:line =~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*$' + " Including '=' for Union types indentation + elseif l:line =~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\|=\)' && l:lline !~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\|=\)' && l:lline !~# '^\s*$' let l:ind = l:ind + &shiftwidth elseif l:lline ==# '' && getline(l:lnum - 1) !=# '' diff --git a/syntax/elm.vim b/syntax/elm.vim index b587bf0..f4dd6be 100644 --- a/syntax/elm.vim +++ b/syntax/elm.vim @@ -6,8 +6,8 @@ endif " Keywords syn keyword elmConditional case else if of then -syn keyword elmAlias alias -syn keyword elmTypedef type port let in +syn match elmTypealias "type alias" contains=elmTypedef +syn keyword elmTypedef type port let in infixr infixl infix syn keyword elmImport exposing as import module where " Operators @@ -15,7 +15,7 @@ syn match elmOperator "\([-!#$%`&\*\+./<=>\?@\\^|~:]\|\<_\>\)" " Types syn match elmType "\<[A-Z][0-9A-Za-z_'-]*" -syn keyword elmNumberType number +syn keyword elmTypeClass number appendable comparable " Delimiters syn match elmDelimiter "[,;]" @@ -37,13 +37,16 @@ syn region elmTripleString start="\"\"\"" skip="\\\"" end="\"\"\"" contains=elmS syn match elmChar "'[^'\\]'\|'\\.'\|'\\u[0-9a-fA-F]\{4}'" " Numbers -syn match elmInt "-\?\<\d\+\>\|0[xX][0-9a-fA-F]\+\>" -syn match elmFloat "\(\<\d\+\.\d\+\>\)" +syn match elmInt "-\?\<0[xX][0-9a-fA-F]\+\>" +syn match elmFloat "-\?\<[0-9]\+\(\.[0-9]\+\)\?\([eE][+-]\?[0-9]\+\)\?\>" " Identifiers -syn match elmTopLevelDecl "^\s*[a-zA-Z][a-zA-z0-9_]*\('\)*\s\+:\s\+" contains=elmOperator +syn region elmRecord matchgroup=elmRecord start="{[^-]" end="[^-]}" contains=ALL contained +syn match elmTopLevelDecl "^\s*[a-zA-Z][a-zA-z0-9_]*\('\)*\_s\+:\(\s\+\|$\)" contains=elmOperator +syn match elmTopLevelBinding "^\s*\(let \)\?\zs[a-zA-Z][a-zA-z0-9_]*\('\)*\ze\([^{]*\|.*{[^}]*}.*\)[^-!#$%&\*\+./<=>\?@\\^|~:]=\([^-!#$%&\*\+./<=>\?@\\^|~:]\|$\)" contains=elmRecord hi def link elmTopLevelDecl Function +hi def link elmTopLevelBinding Function hi def link elmTupleFunction Normal hi def link elmTodo Todo hi def link elmComment Comment @@ -56,13 +59,13 @@ hi def link elmInt Number hi def link elmFloat Float hi def link elmDelimiter Delimiter hi def link elmBraces Delimiter +hi def link elmTypealias TypeDef hi def link elmTypedef TypeDef hi def link elmImport Include hi def link elmConditional Conditional -hi def link elmAlias Delimiter hi def link elmOperator Operator hi def link elmType Identifier -hi def link elmNumberType Identifier +hi def link elmTypeClass Identifier syn sync minlines=500