diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-01-11 19:40:15 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-01-11 19:40:15 +0100 |
commit | 82be4849eed0b8fbee45bc8da99b685ec89af59a (patch) | |
tree | 23edae21e79564327a052e2a6204f569cb602f30 /runtime/indent | |
parent | 48e11c10548782f573411b6302f77adb69c40401 (diff) |
Update runtime files.
Diffstat (limited to 'runtime/indent')
-rw-r--r-- | runtime/indent/systemverilog.vim | 2 | ||||
-rw-r--r-- | runtime/indent/testdir/vim.in | 19 | ||||
-rw-r--r-- | runtime/indent/testdir/vim.ok | 19 | ||||
-rw-r--r-- | runtime/indent/vim.vim | 46 |
4 files changed, 83 insertions, 3 deletions
diff --git a/runtime/indent/systemverilog.vim b/runtime/indent/systemverilog.vim index 68487f84ba..590fd4d998 100644 --- a/runtime/indent/systemverilog.vim +++ b/runtime/indent/systemverilog.vim @@ -227,4 +227,4 @@ endfunction let &cpo = s:cpo_save unlet s:cpo_save -" vim:sw=2
\ No newline at end of file +" vim:sw=2 diff --git a/runtime/indent/testdir/vim.in b/runtime/indent/testdir/vim.in index 235f31d061..47e692975f 100644 --- a/runtime/indent/testdir/vim.in +++ b/runtime/indent/testdir/vim.in @@ -22,7 +22,26 @@ let cmd = " END_INDENT " START_INDENT +" INDENT_EXE let g:vim_indent_cont = 5 + +let list = [ +\ 'one', +\ 'two'] + +" END_INDENT + +" START_INDENT " INDENT_EXE unlet g:vim_indent_cont + +let list = [ +'one', +'two', +] +echo + +" END_INDENT + +" START_INDENT " INDENT_AT this-line func Some() let f = x " this-line diff --git a/runtime/indent/testdir/vim.ok b/runtime/indent/testdir/vim.ok index 61369d4b93..3f53c5286c 100644 --- a/runtime/indent/testdir/vim.ok +++ b/runtime/indent/testdir/vim.ok @@ -22,7 +22,26 @@ let cmd = " END_INDENT " START_INDENT +" INDENT_EXE let g:vim_indent_cont = 5 + +let list = [ + \ 'one', + \ 'two'] + +" END_INDENT + +" START_INDENT " INDENT_EXE unlet g:vim_indent_cont + +let list = [ + 'one', + 'two', + ] +echo + +" END_INDENT + +" START_INDENT " INDENT_AT this-line func Some() let f = x " this-line diff --git a/runtime/indent/vim.vim b/runtime/indent/vim.vim index 4b0867d88a..3e502c9adb 100644 --- a/runtime/indent/vim.vim +++ b/runtime/indent/vim.vim @@ -1,7 +1,7 @@ " Vim indent file " Language: Vim script " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2020 Sep 27 +" Last Change: 2021 Jan 06 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -52,6 +52,7 @@ function GetVimIndentIntern() return 0 endif let prev_text = getline(lnum) + let found_cont = 0 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function " and :else. Add it three times for a line that starts with '\' or '"\ ' @@ -83,6 +84,7 @@ function GetVimIndentIntern() endif if cur_text =~ s:lineContPat && v:lnum > 1 && prev_text !~ s:lineContPat + let found_cont = 1 if exists("g:vim_indent_cont") let ind = ind + g:vim_indent_cont else @@ -114,10 +116,50 @@ function GetVimIndentIntern() endif endif + " For a line starting with "}" find the matching "{". If it is at the start + " of the line align with it, probably end of a block. + " Use the mapped "%" from matchit to find the match, otherwise we may match + " a { inside a comment or string. + if cur_text =~ '^\s*}' + if maparg('%') != '' + exe v:lnum + silent! normal % + if line('.') < v:lnum && getline('.') =~ '^\s*{' + let ind = indent('.') + endif + else + " todo: use searchpair() to find a match + endif + endif + + " Below a line starting with "}" find the matching "{". If it is at the + " end of the line we must be below the end of a dictionary. + if prev_text =~ '^\s*}' + if maparg('%') != '' + exe lnum + silent! normal % + if line('.') == lnum || getline('.') !~ '^\s*{' + let ind = ind - shiftwidth() + endif + else + " todo: use searchpair() to find a match + endif + endif + + " Below a line starting with "]" we must be below the end of a list. + if prev_text =~ '^\s*]' + let ind = ind - shiftwidth() + endif + + " A line ending in "{"/"[} is most likely the start of a dict/list literal, + " indent the next line more. Not for a continuation line. + if prev_text =~ '[{[]\s*$' && !found_cont + let ind = ind + shiftwidth() + endif " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry, " :endfun, :enddef, :else and :augroup END. - if cur_text =~ '^\s*\(ene\@!\|}\|cat\|finall\|el\|aug\%[roup]\s\+[eE][nN][dD]\)' + if cur_text =~ '^\s*\(ene\@!\|cat\|finall\|el\|aug\%[roup]\s\+[eE][nN][dD]\)' let ind = ind - shiftwidth() endif |