diff options
Diffstat (limited to 'indent')
-rw-r--r-- | indent/cython.vim | 47 | ||||
-rw-r--r-- | indent/kotlin.vim | 18 | ||||
-rw-r--r-- | indent/mako.vim | 85 | ||||
-rw-r--r-- | indent/plantuml.vim | 46 | ||||
-rw-r--r-- | indent/python.vim | 47 | ||||
-rw-r--r-- | indent/terraform.vim | 28 |
6 files changed, 206 insertions, 65 deletions
diff --git a/indent/cython.vim b/indent/cython.vim index 5d1bb261..2b8fef1e 100644 --- a/indent/cython.vim +++ b/indent/cython.vim @@ -52,13 +52,13 @@ if !exists('g:python_pep8_indent_searchpair_timeout') endif let s:block_rules = { - \ '^\s*elif\>': ['if', 'elif'], - \ '^\s*except\>': ['try', 'except'], - \ '^\s*finally\>': ['try', 'except', 'else'] - \ } + \ '^\s*elif\>': [['if', 'elif'], ['else']], + \ '^\s*except\>': [['try', 'except'], []], + \ '^\s*finally\>': [['try', 'except', 'else'], []] + \ } let s:block_rules_multiple = { - \ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'], - \ } + \ '^\s*else\>': [['if', 'elif', 'for', 'try', 'except'], []] + \ } " Pairs to look for when searching for opening parenthesis. " The value is the maximum offset in lines. let s:paren_pairs = {'()': 50, '[]': 100, '{}': 1000} @@ -73,13 +73,15 @@ let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>' let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' . \ '=~? "\\vcomment|jedi\\S"' +let s:special_chars_syn_pattern = "\\vstring|comment|^pythonbytes%(contents)=$|pythonTodo|jedi\\S" + if !get(g:, 'python_pep8_indent_skip_concealed', 0) || !has('conceal') " Skip strings and comments. Return 1 for chars to skip. " jedi* refers to syntax definitions from jedi-vim for call signatures, which " are inserted temporarily into the buffer. function! s:_skip_special_chars(line, col) return synIDattr(synID(a:line, a:col, 0), 'name') - \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" + \ =~? s:special_chars_syn_pattern endfunction else " Also ignore anything concealed. @@ -94,8 +96,8 @@ else function! s:_skip_special_chars(line, col) return synIDattr(synID(a:line, a:col, 0), 'name') - \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" - \ || s:is_concealed(a:line, a:col) + \ =~? s:special_chars_syn_pattern + \ || s:is_concealed(a:line, a:col) endfunction endif @@ -152,15 +154,23 @@ function! s:find_start_of_multiline_statement(lnum) endfunction " Find possible indent(s) of the block starter that matches the current line. -function! s:find_start_of_block(lnum, types, multiple) +function! s:find_start_of_block(lnum, types, skip, multiple) abort let r = [] let re = '\V\^\s\*\('.join(a:types, '\|').'\)\>' + if !empty(a:skip) + let re_skip = '\V\^\s\*\('.join(a:skip, '\|').'\)\>' + else + let re_skip = '' + endif let lnum = a:lnum let last_indent = indent(lnum) + 1 while lnum > 0 && last_indent > 0 let indent = indent(lnum) if indent < last_indent - if getline(lnum) =~# re + let line = getline(lnum) + if !empty(re_skip) && line =~# re_skip + let last_indent = indent + elseif line =~# re if !a:multiple return [indent] endif @@ -217,6 +227,11 @@ function! s:indent_like_opening_paren(lnum) let res = base else let res = base + s:sw() + + " Special case for parenthesis. + if text[paren_col-1] ==# '(' && getline(a:lnum) !~# '\v\)\s*:?\s*$' + return res + endif endif else " Indent to match position of opening paren. @@ -241,14 +256,16 @@ function! s:indent_like_block(lnum) let text = getline(a:lnum) for [multiple, block_rules] in [ \ [0, s:block_rules], - \ [1, s:block_rules_multiple]] - for [line_re, blocks] in items(block_rules) + \ [1, s:block_rules_multiple], + \ ] + for [line_re, blocks_ignore] in items(block_rules) if text !~# line_re continue endif - let indents = s:find_start_of_block(a:lnum - 1, blocks, multiple) - if !len(indents) + let [blocks, skip] = blocks_ignore + let indents = s:find_start_of_block(a:lnum - 1, blocks, skip, multiple) + if empty(indents) return -1 endif if len(indents) == 1 diff --git a/indent/kotlin.vim b/indent/kotlin.vim index a9a1ae20..56211b36 100644 --- a/indent/kotlin.vim +++ b/indent/kotlin.vim @@ -5,9 +5,9 @@ endif " Vim indent file " Language: Kotlin " Maintainer: Alexander Udalov -" Latest Revision: 15 July 2017 +" Latest Revision: 26 May 2019 -if exists("b:did_indent") +if exists('b:did_indent') finish endif let b:did_indent = 1 @@ -45,24 +45,14 @@ function! GetKotlinIndent() let prev_open_paren = prev =~ '^.*(\s*$' let cur_close_paren = cur =~ '^\s*).*$' - - if prev_open_paren && !cur_close_paren - return prev_indent + 2 * &shiftwidth - endif - - if cur_close_paren && !prev_open_paren - return prev_indent - 2 * &shiftwidth - endif - - let prev_open_brace = prev =~ '^.*\({\|->\)\s*$' let cur_close_brace = cur =~ '^\s*}.*$' - if prev_open_brace && !cur_close_brace + if prev_open_paren && !cur_close_paren || prev_open_brace && !cur_close_brace return prev_indent + &shiftwidth endif - if cur_close_brace && !prev_open_brace + if cur_close_paren && !prev_open_paren || cur_close_brace && !prev_open_brace return prev_indent - &shiftwidth endif diff --git a/indent/mako.vim b/indent/mako.vim index 06f83d16..48b5c5c5 100644 --- a/indent/mako.vim +++ b/indent/mako.vim @@ -174,66 +174,101 @@ endfun " [-- <ELEMENT ? - - ...> --] call <SID>HtmlIndentPush('a') call <SID>HtmlIndentPush('abbr') -call <SID>HtmlIndentPush('acronym') call <SID>HtmlIndentPush('address') +call <SID>HtmlIndentPush('applet') +call <SID>HtmlIndentPush('article') +call <SID>HtmlIndentPush('aside') +call <SID>HtmlIndentPush('audio') call <SID>HtmlIndentPush('b') +call <SID>HtmlIndentPush('bdi') call <SID>HtmlIndentPush('bdo') -call <SID>HtmlIndentPush('big') call <SID>HtmlIndentPush('blockquote') call <SID>HtmlIndentPush('button') +call <SID>HtmlIndentPush('canvas') call <SID>HtmlIndentPush('caption') -call <SID>HtmlIndentPush('center') call <SID>HtmlIndentPush('cite') call <SID>HtmlIndentPush('code') call <SID>HtmlIndentPush('colgroup') +call <SID>HtmlIndentPush('content') +call <SID>HtmlIndentPush('data') +call <SID>HtmlIndentPush('datalist') call <SID>HtmlIndentPush('del') +call <SID>HtmlIndentPush('details') call <SID>HtmlIndentPush('dfn') +call <SID>HtmlIndentPush('dialog') call <SID>HtmlIndentPush('dir') call <SID>HtmlIndentPush('div') call <SID>HtmlIndentPush('dl') +call <SID>HtmlIndentPush('element') call <SID>HtmlIndentPush('em') call <SID>HtmlIndentPush('fieldset') -call <SID>HtmlIndentPush('font') +call <SID>HtmlIndentPush('figcaption') +call <SID>HtmlIndentPush('figure') +call <SID>HtmlIndentPush('footer') call <SID>HtmlIndentPush('form') -call <SID>HtmlIndentPush('frameset') call <SID>HtmlIndentPush('h1') call <SID>HtmlIndentPush('h2') call <SID>HtmlIndentPush('h3') call <SID>HtmlIndentPush('h4') call <SID>HtmlIndentPush('h5') call <SID>HtmlIndentPush('h6') +call <SID>HtmlIndentPush('header') +call <SID>HtmlIndentPush('hgroup') call <SID>HtmlIndentPush('i') call <SID>HtmlIndentPush('iframe') call <SID>HtmlIndentPush('ins') call <SID>HtmlIndentPush('kbd') call <SID>HtmlIndentPush('label') call <SID>HtmlIndentPush('legend') +call <SID>HtmlIndentPush('li') +call <SID>HtmlIndentPush('main') call <SID>HtmlIndentPush('map') +call <SID>HtmlIndentPush('mark') +call <SID>HtmlIndentPush('MediaStream') call <SID>HtmlIndentPush('menu') -call <SID>HtmlIndentPush('noframes') +call <SID>HtmlIndentPush('menuitem') +call <SID>HtmlIndentPush('meter') +call <SID>HtmlIndentPush('nav') +call <SID>HtmlIndentPush('noembed') call <SID>HtmlIndentPush('noscript') call <SID>HtmlIndentPush('object') call <SID>HtmlIndentPush('ol') call <SID>HtmlIndentPush('optgroup') +call <SID>HtmlIndentPush('option') +call <SID>HtmlIndentPush('output') +call <SID>HtmlIndentPush('picture') call <SID>HtmlIndentPush('pre') +call <SID>HtmlIndentPush('progress') call <SID>HtmlIndentPush('q') +call <SID>HtmlIndentPush('rb') +call <SID>HtmlIndentPush('rp') +call <SID>HtmlIndentPush('rt') +call <SID>HtmlIndentPush('rtc') +call <SID>HtmlIndentPush('ruby') call <SID>HtmlIndentPush('s') call <SID>HtmlIndentPush('samp') call <SID>HtmlIndentPush('script') +call <SID>HtmlIndentPush('section') call <SID>HtmlIndentPush('select') +call <SID>HtmlIndentPush('shadow') +call <SID>HtmlIndentPush('slot') call <SID>HtmlIndentPush('small') call <SID>HtmlIndentPush('span') call <SID>HtmlIndentPush('strong') call <SID>HtmlIndentPush('style') call <SID>HtmlIndentPush('sub') +call <SID>HtmlIndentPush('summary') call <SID>HtmlIndentPush('sup') call <SID>HtmlIndentPush('table') +call <SID>HtmlIndentPush('template') call <SID>HtmlIndentPush('textarea') +call <SID>HtmlIndentPush('time') call <SID>HtmlIndentPush('title') call <SID>HtmlIndentPush('tt') call <SID>HtmlIndentPush('u') call <SID>HtmlIndentPush('ul') call <SID>HtmlIndentPush('var') +call <SID>HtmlIndentPush('video') " For some reason the default HTML indentation script doesn't consider these " elements to be worthy of indentation. @@ -260,6 +295,44 @@ if !exists('g:html_indent_strict_table') call <SID>HtmlIndentPush('thead') endif +" [-- <OBSOLETE ELEMENTS ? - - ...> --] +call <SID>HtmlIndentPush('abbr') +call <SID>HtmlIndentPush('acronym') +call <SID>HtmlIndentPush('applet') +call <SID>HtmlIndentPush('audio') +call <SID>HtmlIndentPush('basefont') +call <SID>HtmlIndentPush('bgsound') +call <SID>HtmlIndentPush('big') +call <SID>HtmlIndentPush('blink') +call <SID>HtmlIndentPush('center') +call <SID>HtmlIndentPush('command') +call <SID>HtmlIndentPush('content') +call <SID>HtmlIndentPush('dir') +call <SID>HtmlIndentPush('element') +call <SID>HtmlIndentPush('embed') +call <SID>HtmlIndentPush('font') +call <SID>HtmlIndentPush('frame') +call <SID>HtmlIndentPush('frameset') +call <SID>HtmlIndentPush('image') +call <SID>HtmlIndentPush('img') +call <SID>HtmlIndentPush('isindex') +call <SID>HtmlIndentPush('keygen') +call <SID>HtmlIndentPush('listing') +call <SID>HtmlIndentPush('marquee') +call <SID>HtmlIndentPush('menuitem') +call <SID>HtmlIndentPush('multicol') +call <SID>HtmlIndentPush('nextid') +call <SID>HtmlIndentPush('nobr') +call <SID>HtmlIndentPush('noembed') +call <SID>HtmlIndentPush('noframes') +call <SID>HtmlIndentPush('object') +call <SID>HtmlIndentPush('plaintext') +call <SID>HtmlIndentPush('shadow') +call <SID>HtmlIndentPush('spacer') +call <SID>HtmlIndentPush('strike') +call <SID>HtmlIndentPush('tt') +call <SID>HtmlIndentPush('xmp') + " [-- <Mako Elements> --] call <SID>MakoIndentPush('%def') call <SID>MakoIndentPush('%block') diff --git a/indent/plantuml.vim b/indent/plantuml.vim index 383a6b41..919a0c86 100644 --- a/indent/plantuml.vim +++ b/indent/plantuml.vim @@ -2,6 +2,12 @@ if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'plantuml') != -1 finish endif +scriptencoding utf-8 +" Vim indent file +" Language: PlantUML +" Maintainer: Anders Thøgersen <first name at bladre dot dk> +" License: VIM LICENSE + if exists('b:did_indent') finish endif @@ -15,14 +21,6 @@ if exists('*GetPlantUMLIndent') finish endif -let s:incIndent = - \ '^\s*\%(loop\|alt\|opt\|group\|critical\|else\|legend\|box\|if\|while\)\>\|' . - \ '^\s*ref\>[^:]*$\|' . - \ '^\s*[hr]\?note\>\%(\%("[^"]*" \<as\>\)\@![^:]\)*$\|' . - \ '^\s*title\s*$\|' . - \ '^\s*skinparam\>.*{\s*$\|' . - \ '^\s*\%(state\|class\|partition\|rectangle\|enum\|interface\|namespace\|object\)\>.*{' - let s:decIndent = '^\s*\%(end\|else\|}\)' function! GetPlantUMLIndent(...) abort @@ -38,6 +36,8 @@ function! GetPlantUMLIndent(...) abort let pline = getline(pnum) let cline = getline(clnum) + let s:incIndent = s:getIncIndent() + if cline =~ s:decIndent if pline =~ s:incIndent return pindent @@ -57,3 +57,33 @@ function! s:insidePlantUMLTags(lnum) abort call cursor(a:lnum, 1) return search('@startuml', 'Wbn') && search('@enduml', 'Wn') endfunction + +function! s:listSyntax(syntaxKeyword) abort + " Get a list of words assigned to a syntax keyword + " The 'syntax list <syntax keyword>' command returns + " a string with the keyword itself, followed by xxx, + " on which we can split to extract the keywords string. + " This string must then be split on whitespace + let syntaxWords = split( + \ execute('syntax list ' . a:syntaxKeyword), + \ a:syntaxKeyword . ' xxx ')[-1] + return split(syntaxWords) +endfunction + +function! s:typeKeywordIncPattern() abort + " Extract keywords for plantumlTypeKeyword, returning the inc pattern + let syntaxWords = join(s:listSyntax('plantumlTypeKeyword'), '\\\|') + return '^\s*\%(' . syntaxWords . '\)\>.*{' +endfunction + +function! s:getIncIndent() abort + " Function to determine the s:incIndent pattern + return + \ '^\s*\%(class\|object\|interface\|partition\|rectangle\|enum\|namespace\)\>.*{\s*$\|' . + \ '^\s*\%(loop\|alt\|opt\|group\|critical\|else\|legend\|box\|if\|while\|fork\|split\)\>\|' . + \ '^\s*ref\>[^:]*$\|' . + \ '^\s*[hr]\?note\>\%(\%("[^"]*" \<as\>\)\@![^:]\)*$\|' . + \ '^\s*title\s*$\|' . + \ '^\s*skinparam\>.*{\s*$\|' . + \ s:typeKeywordIncPattern() +endfunction diff --git a/indent/python.vim b/indent/python.vim index 5d1bb261..2b8fef1e 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -52,13 +52,13 @@ if !exists('g:python_pep8_indent_searchpair_timeout') endif let s:block_rules = { - \ '^\s*elif\>': ['if', 'elif'], - \ '^\s*except\>': ['try', 'except'], - \ '^\s*finally\>': ['try', 'except', 'else'] - \ } + \ '^\s*elif\>': [['if', 'elif'], ['else']], + \ '^\s*except\>': [['try', 'except'], []], + \ '^\s*finally\>': [['try', 'except', 'else'], []] + \ } let s:block_rules_multiple = { - \ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'], - \ } + \ '^\s*else\>': [['if', 'elif', 'for', 'try', 'except'], []] + \ } " Pairs to look for when searching for opening parenthesis. " The value is the maximum offset in lines. let s:paren_pairs = {'()': 50, '[]': 100, '{}': 1000} @@ -73,13 +73,15 @@ let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>' let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' . \ '=~? "\\vcomment|jedi\\S"' +let s:special_chars_syn_pattern = "\\vstring|comment|^pythonbytes%(contents)=$|pythonTodo|jedi\\S" + if !get(g:, 'python_pep8_indent_skip_concealed', 0) || !has('conceal') " Skip strings and comments. Return 1 for chars to skip. " jedi* refers to syntax definitions from jedi-vim for call signatures, which " are inserted temporarily into the buffer. function! s:_skip_special_chars(line, col) return synIDattr(synID(a:line, a:col, 0), 'name') - \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" + \ =~? s:special_chars_syn_pattern endfunction else " Also ignore anything concealed. @@ -94,8 +96,8 @@ else function! s:_skip_special_chars(line, col) return synIDattr(synID(a:line, a:col, 0), 'name') - \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" - \ || s:is_concealed(a:line, a:col) + \ =~? s:special_chars_syn_pattern + \ || s:is_concealed(a:line, a:col) endfunction endif @@ -152,15 +154,23 @@ function! s:find_start_of_multiline_statement(lnum) endfunction " Find possible indent(s) of the block starter that matches the current line. -function! s:find_start_of_block(lnum, types, multiple) +function! s:find_start_of_block(lnum, types, skip, multiple) abort let r = [] let re = '\V\^\s\*\('.join(a:types, '\|').'\)\>' + if !empty(a:skip) + let re_skip = '\V\^\s\*\('.join(a:skip, '\|').'\)\>' + else + let re_skip = '' + endif let lnum = a:lnum let last_indent = indent(lnum) + 1 while lnum > 0 && last_indent > 0 let indent = indent(lnum) if indent < last_indent - if getline(lnum) =~# re + let line = getline(lnum) + if !empty(re_skip) && line =~# re_skip + let last_indent = indent + elseif line =~# re if !a:multiple return [indent] endif @@ -217,6 +227,11 @@ function! s:indent_like_opening_paren(lnum) let res = base else let res = base + s:sw() + + " Special case for parenthesis. + if text[paren_col-1] ==# '(' && getline(a:lnum) !~# '\v\)\s*:?\s*$' + return res + endif endif else " Indent to match position of opening paren. @@ -241,14 +256,16 @@ function! s:indent_like_block(lnum) let text = getline(a:lnum) for [multiple, block_rules] in [ \ [0, s:block_rules], - \ [1, s:block_rules_multiple]] - for [line_re, blocks] in items(block_rules) + \ [1, s:block_rules_multiple], + \ ] + for [line_re, blocks_ignore] in items(block_rules) if text !~# line_re continue endif - let indents = s:find_start_of_block(a:lnum - 1, blocks, multiple) - if !len(indents) + let [blocks, skip] = blocks_ignore + let indents = s:find_start_of_block(a:lnum - 1, blocks, skip, multiple) + if empty(indents) return -1 endif if len(indents) == 1 diff --git a/indent/terraform.vim b/indent/terraform.vim index 888e5149..2a0e5799 100644 --- a/indent/terraform.vim +++ b/indent/terraform.vim @@ -3,20 +3,31 @@ if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'terraform') != - endif " Only load this file if no other indent file was loaded -if exists("b:did_indent") +if exists('b:did_indent') finish endif let b:did_indent = 1 +let s:cpo_save = &cpoptions +set cpoptions&vim + setlocal nolisp -setlocal autoindent sw=2 ts=2 +setlocal autoindent shiftwidth=2 tabstop=2 softtabstop=2 setlocal indentexpr=TerraformIndent(v:lnum) setlocal indentkeys+=<:>,0=},0=) +let b:undo_indent = 'setlocal lisp< autoindent< shiftwidth< tabstop< softtabstop<' + \ . ' indentexpr< indentkeys<' + +let &cpoptions = s:cpo_save +unlet s:cpo_save -if exists("*TerraformIndent") +if exists('*TerraformIndent') finish endif +let s:cpo_save = &cpoptions +set cpoptions&vim + function! TerraformIndent(lnum) " Beginning of the file should have no indent if a:lnum == 0 @@ -32,8 +43,8 @@ function! TerraformIndent(lnum) let thisindent = previndent " Config block starting with [ { ( should increase the indent level - if prevline =~ '[\[{\(]\s*$' - let thisindent += &sw + if prevline =~# '[\[{\(]\s*$' + let thisindent += &shiftwidth endif " Current line without comments should continue the indent level @@ -41,9 +52,12 @@ function! TerraformIndent(lnum) " Config block ending with ) } ] should get the indentation " level from the initial config block - if thisline =~ '^\s*[\)}\]]' - let thisindent -= &sw + if thisline =~# '^\s*[\)}\]]' + let thisindent -= &shiftwidth endif return thisindent endfunction + +let &cpoptions = s:cpo_save +unlet s:cpo_save |