mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
@ -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, :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
|
||||
|
||||
|
Reference in New Issue
Block a user