diff options
| author | Adam Stankiewicz <sheerun@sher.pl> | 2020-08-14 19:15:07 +0200 | 
|---|---|---|
| committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-08-14 19:15:07 +0200 | 
| commit | a3bdbcdb3c60a9563fb90e02b28ae46cee5ef974 (patch) | |
| tree | 6e0b340417985e714838230de04d9610bdfb8677 /indent | |
| parent | 34e01b8b62701afbd6b4ab1ffb4057617f540dce (diff) | |
| download | vim-polyglot-a3bdbcdb3c60a9563fb90e02b28ae46cee5ef974.tar.gz vim-polyglot-a3bdbcdb3c60a9563fb90e02b28ae46cee5ef974.zip | |
Fix svelte branch name, closes #522
Diffstat (limited to 'indent')
| -rw-r--r-- | indent/crystal.vim | 2 | ||||
| -rw-r--r-- | indent/ecrystal.vim | 6 | ||||
| -rw-r--r-- | indent/svelte.vim | 148 | ||||
| -rw-r--r-- | indent/terraform.vim | 10 | 
4 files changed, 162 insertions, 4 deletions
| diff --git a/indent/crystal.vim b/indent/crystal.vim index c69b2a28..2ba6563c 100644 --- a/indent/crystal.vim +++ b/indent/crystal.vim @@ -15,7 +15,7 @@ setlocal nosmartindent  " Now, set up our indentation expression and keys that trigger it.  setlocal indentexpr=GetCrystalIndent(v:lnum)  setlocal indentkeys=0{,0},0),0],!^F,o,O,e,. -setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue +setlocal indentkeys+==end,=else,=elsif,=when,=in,=ensure,=rescue  " Only define the function once.  if exists('*GetCrystalIndent') diff --git a/indent/ecrystal.vim b/indent/ecrystal.vim index 9826cd7c..ad3303c3 100644 --- a/indent/ecrystal.vim +++ b/indent/ecrystal.vim @@ -52,7 +52,7 @@ if b:ecrystal_indent_multiline  endif  setlocal indentexpr=GetEcrystalIndent() -setlocal indentkeys+=<>>,=end,=else,=elsif,=rescue,=ensure,=when +setlocal indentkeys+=<>>,=end,=else,=elsif,=rescue,=ensure,=when,=in  let b:did_indent = 1 @@ -71,10 +71,10 @@ let s:ecr_control_open = '<%%\@!-\=[=#]\@!'  let s:ecr_comment_open = '<%%\@!-\=#'  let s:ecr_indent_regex = -      \ '\<\%(if\|unless\|else\|elsif\|case\|when\|while\|until\|begin\|do\|rescue\|ensure\|\)\>' +      \ '\<\%(if\|unless\|else\|elsif\|case\|when\|in\|while\|until\|begin\|do\|rescue\|ensure\|\)\>'  let s:ecr_dedent_regex = -      \ '\<\%(end\|else\|elsif\|when\|rescue\|ensure\)\>' +      \ '\<\%(end\|else\|elsif\|when\|in\|rescue\|ensure\)\>'  " Return the value of a single shift-width  if exists('*shiftwidth') diff --git a/indent/svelte.vim b/indent/svelte.vim new file mode 100644 index 00000000..8d9fbb2f --- /dev/null +++ b/indent/svelte.vim @@ -0,0 +1,148 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'svelte') == -1 + +" Vim indent file +" Language:   Svelte 3 (HTML/JavaScript) +" Author:     Evan Lecklider <evan@lecklider.com> +" Maintainer: Evan Lecklide <evan@lecklider.com> +" URL:        https://github.com/evanleck/vim-svelte + +if exists("b:did_indent") +  finish +endif + +runtime! indent/html.vim +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 + +" Only define the function once. +if exists('*GetSvelteIndent') +  finish +endif + +function! GetSvelteIndent() +  let current_line_number = v:lnum + +  if current_line_number == 0 +    return 0 +  endif + +  let current_line = getline(current_line_number) + +  " Opening script and style tags should be all the way outdented. +  if current_line =~ '^\s*</\?\(script\|style\)' +    return 0 +  endif + +  let previous_line_number = prevnonblank(current_line_number - 1) +  let previous_line = getline(previous_line_number) +  let previous_line_indent = indent(previous_line_number) + +  " 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 + +  " For some reason, the HTML CSS indentation keeps indenting the next line over +  " and over after each style declaration. +  if searchpair('<style>', '', '</style>', 'bW') && previous_line =~ ';$' && current_line !~ '}' +    return previous_line_indent +  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') + +    if await_start +      return indent(await_start) +    endif +  endif + +  " "/each" +  if current_line =~ '^\s*{\s*\/each' +    let each_start = searchpair('{\s*#each\>', '', '{\s*\/each\>', 'bW') + +    if each_start +      return indent(each_start) +    endif +  endif + +  " "/if" +  if current_line =~ '^\s*{\s*\/if' +    let if_start = searchpair('{\s*#if\>', '', '{\s*\/if\>', 'bW') + +    if if_start +      return indent(if_start) +    endif +  endif + +  " ":else" is tricky because it can match an opening "#each" _or_ an opening +  " "#if", so we try to be smart and look for the closest of the two. +  if current_line =~ '^\s*{\s*:else' +    let if_start = searchpair('{\s*#if\>', '', '{\s*\/if\>', 'bW') + +    " If it's an "else if" then we know to look for an "#if" +    if current_line =~ '^\s*{\s*:else if' && if_start +      return indent(if_start) +    else +      " The greater line number will be closer to the cursor position because +      " we're searching backward. +      return indent(max([if_start, searchpair('{\s*#each\>', '', '{\s*\/each\>', 'bW')])) +    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 + +endif diff --git a/indent/terraform.vim b/indent/terraform.vim index 129ec368..c035c216 100644 --- a/indent/terraform.vim +++ b/indent/terraform.vim @@ -49,6 +49,16 @@ function! TerraformIndent(lnum)      let thisindent -= &shiftwidth    endif +  " If the previous line starts a block comment /*, increase by one +  if prevline =~# '/\*' +    let thisindent += 1 +  endif + +  " If the previous line ends a block comment */, decrease by one +  if prevline =~# '\*/' +    let thisindent -= 1 +  endif +    return thisindent  endfunction | 
