diff options
Diffstat (limited to 'indent')
-rw-r--r-- | indent/handlebars.vim | 20 | ||||
-rw-r--r-- | indent/javascript.vim | 4 | ||||
-rw-r--r-- | indent/pgsql.vim | 10 | ||||
-rw-r--r-- | indent/rust.vim | 6 | ||||
-rw-r--r-- | indent/svelte.vim | 76 |
5 files changed, 67 insertions, 49 deletions
diff --git a/indent/handlebars.vim b/indent/handlebars.vim index 3fbace93..2253a7a3 100644 --- a/indent/handlebars.vim +++ b/indent/handlebars.vim @@ -23,9 +23,6 @@ endif unlet! b:did_indent setlocal indentexpr= -" keep track of whether or not we are in a block expression for indenting -unlet! s:in_block_expr - runtime! indent/html.vim unlet! b:did_indent @@ -87,23 +84,19 @@ function! GetHandlebarsIndent(...) " tag is on a separate line " indent after block {{#block - if prevLine =~# '\v\s*\{\{\#.*\s*' - let s:in_block_expr = 1 + if prevLine =~# '\v\s*\{\{[#^].*\s*' let ind = ind + sw endif " but not if the block ends on the same line if prevLine =~# '\v\s*\{\{\#(.+)(\s+|\}\}).*\{\{\/\1' - let s:in_block_expr = 0 let ind = ind - sw endif " unindent after block close {{/block}} if currentLine =~# '\v^\s*\{\{\/\S*\}\}\s*' - let s:in_block_expr = 0 let ind = ind - sw endif " indent after component block {{a-component if prevLine =~# '\v\s*\{\{\w' - let s:in_block_expr = 0 let ind = ind + sw endif " but not if the component block ends on the same line @@ -111,9 +104,16 @@ function! GetHandlebarsIndent(...) let ind = ind - sw endif " unindent }} lines, and following lines if not inside a block expression + let savedPos = getpos('.') if currentLine =~# '\v^\s*\}\}\s*$' || (currentLine !~# '\v^\s*\{\{\/' && prevLine =~# '\v^\s*[^\{\} \t]+\}\}\s*$') - if !s:in_block_expr - let ind = ind - sw + let closingLnum = search('}}\s*$', 'Wbc', lnum) + let [openingLnum, col] = searchpairpos('{{', '', '}}', 'Wb') + if openingLnum > 0 && closingLnum > 0 + if strpart(getline(openingLnum), col - 1, 3) !~ '{{[#^]' + let ind = ind - sw + endif + else + call setpos('.', savedPos) endif endif " unindent {{else}} diff --git a/indent/javascript.vim b/indent/javascript.vim index 176a45b9..49154dbb 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -396,7 +396,9 @@ function GetJavascriptIndent() if idx != -1 call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()') elseif getline(v:lnum) !~ '^\S' && s:stack[-1] =~? 'block\|^jsobject$' - call s:GetPair('{','}','bW','s:SkipFunc()') + if !s:GetPair('{','}','bW','s:SkipFunc()') && s:stack[-1] ==# 'jsObject' + return indent(l:lnum) + endif else call s:AlternatePair() endif diff --git a/indent/pgsql.vim b/indent/pgsql.vim index 7db0187c..9c99b0c5 100644 --- a/indent/pgsql.vim +++ b/indent/pgsql.vim @@ -24,7 +24,7 @@ setlocal indentkeys-=: setlocal indentkeys-=0# setlocal indentkeys-=e -if has('patch-7.3.694') || (v:version == 703 && has('patch694')) +if exists('*shiftwidth') fun! s:shiftwidth() return shiftwidth() endf @@ -41,16 +41,12 @@ endif " SQL is generally case insensitive, so this files assumes that " These keywords are something that would trigger an indent LEFT, not " an indent right, since the SQLBlockStart is used for those keywords -setlocal indentkeys+==~end,=~else,=~elseif,=~elsif,0=~when,0=) +setlocal indentkeys+==~begin,=~end,=~else,=~elseif,=~elsif,0=~when,=~exception,0=) " GetSQLIndent is executed whenever one of the expressions " in the indentkeys is typed setlocal indentexpr=GetSQLIndent() -" Only define the functions once. -if exists("*GetSQLIndent") - finish -endif let s:keepcpo= &cpo set cpo&vim @@ -340,7 +336,7 @@ function! GetSQLIndent() " Check current line; search for simplistic matching start-of-block let line = getline(v:lnum) - if line =~? '^\s*els' + if line =~? '^\s*els' || line =~? '^\s*begin' || line =~? '^\s*exception' " Any line when you type else will automatically back up one " ident level (ie else, elseif, elsif) let ind = ind - s:shiftwidth() diff --git a/indent/rust.vim b/indent/rust.vim index ee7f6cf6..68178070 100644 --- a/indent/rust.vim +++ b/indent/rust.vim @@ -15,8 +15,8 @@ endif let b:did_indent = 1 setlocal cindent -setlocal cinoptions=L0,(0,Ws,J1,j1,m1 -setlocal cinkeys=0{,0},!^F,o,O,0[,0] +setlocal cinoptions=L0,(s,Ws,J1,j1,m1 +setlocal cinkeys=0{,0},!^F,o,O,0[,0],0(,0) " Don't think cinwords will actually do anything at all... never mind setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern,macro @@ -24,7 +24,7 @@ setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,ex setlocal nolisp " Make sure lisp indenting doesn't supersede us setlocal autoindent " indentexpr isn't much help otherwise " Also do indentkeys, otherwise # gets shoved to column 0 :-/ -setlocal indentkeys=0{,0},!^F,o,O,0[,0] +setlocal indentkeys=0{,0},!^F,o,O,0[,0],0(,0) setlocal indentexpr=GetRustIndent(v:lnum) 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,*<Return>,<>>,{,},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*<script' + if g:svelte_indent_script + return previous_line_indent + shiftwidth() + else + return previous_line_indent + endif + endif + + if previous_line =~ '^\s*<style' + if g:svelte_indent_style + return previous_line_indent + shiftwidth() + else + return previous_line_indent + endif endif execute "let indent = " . s:html_indent @@ -57,31 +77,6 @@ function! GetSvelteIndent() return previous_line_indent 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 (<Widget />), - " capitalized component tags (<Widget></Widget>), and custom svelte tags - " (<svelte:head></svelte:head>). - 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 (<Widget />), + " capitalized component tags (<Widget></Widget>), and custom svelte tags + " (<svelte:head></svelte:head>). + 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 |