comparison 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
comparison
equal deleted inserted replaced
23572:b35e568d74e6 23573:e2e2cc5d0856
1 " Vim indent file 1 " Vim indent file
2 " Language: Vim script 2 " Language: Vim script
3 " Maintainer: Bram Moolenaar <Bram@vim.org> 3 " Maintainer: Bram Moolenaar <Bram@vim.org>
4 " Last Change: 2020 Sep 27 4 " Last Change: 2021 Jan 06
5 5
6 " Only load this indent file when no other was loaded. 6 " Only load this indent file when no other was loaded.
7 if exists("b:did_indent") 7 if exists("b:did_indent")
8 finish 8 finish
9 endif 9 endif
50 " At the start of the file use zero indent. 50 " At the start of the file use zero indent.
51 if lnum == 0 51 if lnum == 0
52 return 0 52 return 0
53 endif 53 endif
54 let prev_text = getline(lnum) 54 let prev_text = getline(lnum)
55 let found_cont = 0
55 56
56 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function 57 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function
57 " and :else. Add it three times for a line that starts with '\' or '"\ ' 58 " and :else. Add it three times for a line that starts with '\' or '"\ '
58 " after a line that doesn't (or g:vim_indent_cont if it exists). 59 " after a line that doesn't (or g:vim_indent_cont if it exists).
59 let ind = indent(lnum) 60 let ind = indent(lnum)
81 return ind 82 return ind
82 endif 83 endif
83 endif 84 endif
84 85
85 if cur_text =~ s:lineContPat && v:lnum > 1 && prev_text !~ s:lineContPat 86 if cur_text =~ s:lineContPat && v:lnum > 1 && prev_text !~ s:lineContPat
87 let found_cont = 1
86 if exists("g:vim_indent_cont") 88 if exists("g:vim_indent_cont")
87 let ind = ind + g:vim_indent_cont 89 let ind = ind + g:vim_indent_cont
88 else 90 else
89 let ind = ind + shiftwidth() * 3 91 let ind = ind + shiftwidth() * 3
90 endif 92 endif
112 if !has('syntax_items') || synIDattr(synID(lnum, i + 2, 1), "name") !~ '\(Comment\|String\)$' 114 if !has('syntax_items') || synIDattr(synID(lnum, i + 2, 1), "name") !~ '\(Comment\|String\)$'
113 let ind = ind - shiftwidth() 115 let ind = ind - shiftwidth()
114 endif 116 endif
115 endif 117 endif
116 118
119 " For a line starting with "}" find the matching "{". If it is at the start
120 " of the line align with it, probably end of a block.
121 " Use the mapped "%" from matchit to find the match, otherwise we may match
122 " a { inside a comment or string.
123 if cur_text =~ '^\s*}'
124 if maparg('%') != ''
125 exe v:lnum
126 silent! normal %
127 if line('.') < v:lnum && getline('.') =~ '^\s*{'
128 let ind = indent('.')
129 endif
130 else
131 " todo: use searchpair() to find a match
132 endif
133 endif
134
135 " Below a line starting with "}" find the matching "{". If it is at the
136 " end of the line we must be below the end of a dictionary.
137 if prev_text =~ '^\s*}'
138 if maparg('%') != ''
139 exe lnum
140 silent! normal %
141 if line('.') == lnum || getline('.') !~ '^\s*{'
142 let ind = ind - shiftwidth()
143 endif
144 else
145 " todo: use searchpair() to find a match
146 endif
147 endif
148
149 " Below a line starting with "]" we must be below the end of a list.
150 if prev_text =~ '^\s*]'
151 let ind = ind - shiftwidth()
152 endif
153
154 " A line ending in "{"/"[} is most likely the start of a dict/list literal,
155 " indent the next line more. Not for a continuation line.
156 if prev_text =~ '[{[]\s*$' && !found_cont
157 let ind = ind + shiftwidth()
158 endif
117 159
118 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry, 160 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry,
119 " :endfun, :enddef, :else and :augroup END. 161 " :endfun, :enddef, :else and :augroup END.
120 if cur_text =~ '^\s*\(ene\@!\|}\|cat\|finall\|el\|aug\%[roup]\s\+[eE][nN][dD]\)' 162 if cur_text =~ '^\s*\(ene\@!\|cat\|finall\|el\|aug\%[roup]\s\+[eE][nN][dD]\)'
121 let ind = ind - shiftwidth() 163 let ind = ind - shiftwidth()
122 endif 164 endif
123 165
124 return ind 166 return ind
125 endfunction 167 endfunction