Mercurial > vim
diff runtime/indent/vim.vim @ 23573:e2e2cc5d0856
Update runtime files.
Commit: https://github.com/vim/vim/commit/82be4849eed0b8fbee45bc8da99b685ec89af59a
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 11 19:40:15 2021 +0100
Update runtime files.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 11 Jan 2021 19:45:05 +0100 |
parents | a3bb84cd0f59 |
children | 34b4eb3a8458 |
line wrap: on
line diff
--- 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