From 941aeb8c3abaf7290012e15775be014fee6d4404 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Mon, 11 Sep 2017 09:31:59 +0200 Subject: [PATCH 1/4] Indent on new lines starting by an operator or = This should make it possible to indent correctly for union types and chaining operators such as pipes or concatenations --- indent/elm.vim | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/indent/elm.vim b/indent/elm.vim index 8e346ee..41e47dc 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 @@ -89,17 +89,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) !=# '' From e9cafb073e2ad7aa646aa026c6f3ed0ad40dfd61 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Mon, 11 Sep 2017 09:51:50 +0200 Subject: [PATCH 2/4] Align else to corresponding if --- indent/elm.vim | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/indent/elm.vim b/indent/elm.vim index 41e47dc..01e6bc5 100644 --- a/indent/elm.vim +++ b/indent/elm.vim @@ -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 !~# '\\' From 5d3f0880702898b5d6c22622a5c577e86a78ed82 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Sun, 5 Nov 2017 19:47:37 +0100 Subject: [PATCH 3/4] fix function definition name highlights --- syntax/elm.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/syntax/elm.vim b/syntax/elm.vim index b587bf0..864dde7 100644 --- a/syntax/elm.vim +++ b/syntax/elm.vim @@ -6,8 +6,7 @@ endif " Keywords syn keyword elmConditional case else if of then -syn keyword elmAlias alias -syn keyword elmTypedef type port let in +syn keyword elmTypedef type port let in infixr infixl alias syn keyword elmImport exposing as import module where " Operators @@ -41,9 +40,12 @@ syn match elmInt "-\?\<\d\+\>\|0[xX][0-9a-fA-F]\+\>" syn match elmFloat "\(\<\d\+\.\d\+\>\)" " 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 @@ -59,7 +61,6 @@ hi def link elmBraces Delimiter 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 From dd161289bfe9250efd5e4ee5d246489f81f6bc45 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Sun, 15 Apr 2018 11:04:04 +0200 Subject: [PATCH 4/4] Improve syntax highlight --- syntax/elm.vim | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/syntax/elm.vim b/syntax/elm.vim index 864dde7..f4dd6be 100644 --- a/syntax/elm.vim +++ b/syntax/elm.vim @@ -6,7 +6,8 @@ endif " Keywords syn keyword elmConditional case else if of then -syn keyword elmTypedef type port let in infixr infixl alias +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 @@ -14,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 "[,;]" @@ -36,8 +37,8 @@ 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 region elmRecord matchgroup=elmRecord start="{[^-]" end="[^-]}" contains=ALL contained @@ -58,12 +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 elmOperator Operator hi def link elmType Identifier -hi def link elmNumberType Identifier +hi def link elmTypeClass Identifier syn sync minlines=500