From 664aa988f6d9cdb7b75218666fbe348c85ef8b29 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Wed, 4 Sep 2019 15:44:43 +0200 Subject: Update --- indent/svelte.vim | 76 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 28 deletions(-) (limited to 'indent/svelte.vim') diff --git a/indent/svelte.vim b/indent/svelte.vim index 0b3c732f..ef0569ed 100644 --- a/indent/svelte.vim +++ b/indent/svelte.vim @@ -18,6 +18,14 @@ unlet! b:did_indent let s:html_indent = &l:indentexpr let b:did_indent = 1 +if !exists('g:svelte_indent_script') + let g:svelte_indent_script = 1 +endif + +if !exists('g:svelte_indent_style') + let g:svelte_indent_style = 1 +endif + setlocal indentexpr=GetSvelteIndent() setlocal indentkeys=o,O,*,<>>,{,},0),0],!^F,;,=:else,=:then,=:catch,=/if,=/each,=/await @@ -44,9 +52,21 @@ function! GetSvelteIndent() let previous_line = getline(previous_line_number) let previous_line_indent = indent(previous_line_number) - " The inside of scripts an styles should be indented. - if previous_line =~ '^<\(script\|style\)' - return shiftwidth() + " The inside of scripts an styles should be indented unless disabled. + if previous_line =~ '^\s*), - " capitalized component tags (), and custom svelte tags - " (). - if synID(previous_line_number, match(previous_line, '\S') + 1, 0) == hlID('htmlTag') - \ && synID(current_line_number, match(current_line, '\S') + 1, 0) != hlID('htmlEndTag') - let indents_match = indent == previous_line_indent - let previous_closes = previous_line =~ '/>$' - - if indents_match && !previous_closes && previous_line =~ '<\(\u\|\l\+:\l\+\)' - return previous_line_indent + shiftwidth() - elseif !indents_match && previous_closes - return previous_line_indent - endif - endif - " "/await" or ":catch" or ":then" if current_line =~ '^\s*{\s*\/await' || current_line =~ '^\s*{\s*:\(catch\|then\)' let await_start = searchpair('{\s*#await\>', '', '{\s*\/await\>', 'bW') @@ -124,5 +119,30 @@ function! GetSvelteIndent() endif endif + " "#if" or "#each" + if previous_line =~ '^\s*{\s*#\(if\|each\|await\)' + return previous_line_indent + shiftwidth() + endif + + " ":else" or ":then" + if previous_line =~ '^\s*{\s*:\(else\|catch\|then\)' + return previous_line_indent + shiftwidth() + endif + + " Custom element juggling for abnormal self-closing tags (), + " capitalized component tags (), and custom svelte tags + " (). + if synID(previous_line_number, match(previous_line, '\S') + 1, 0) == hlID('htmlTag') + \ && synID(current_line_number, match(current_line, '\S') + 1, 0) != hlID('htmlEndTag') + let indents_match = indent == previous_line_indent + let previous_closes = previous_line =~ '/>$' + + if indents_match && !previous_closes && previous_line =~ '<\(\u\|\l\+:\l\+\)' + return previous_line_indent + shiftwidth() + elseif !indents_match && previous_closes + return previous_line_indent + endif + endif + return indent endfunction -- cgit v1.2.3