Mercurial > vim
comparison runtime/indent/vim.vim @ 23737:34b4eb3a8458
Update runtime files.
Commit: https://github.com/vim/vim/commit/e0e3917554327f2524066f89fbbef9c83c1535da
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 25 21:14:57 2021 +0100
Update runtime files.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 25 Jan 2021 21:30:05 +0100 |
parents | e2e2cc5d0856 |
children | 5b37a0bf7e3a |
comparison
equal
deleted
inserted
replaced
23736:e5035ccad5a8 | 23737:34b4eb3a8458 |
---|---|
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: 2021 Jan 06 | 4 " Last Change: 2021 Jan 21 |
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 |
36 | 36 |
37 function GetVimIndentIntern() | 37 function GetVimIndentIntern() |
38 " Find a non-blank line above the current line. | 38 " Find a non-blank line above the current line. |
39 let lnum = prevnonblank(v:lnum - 1) | 39 let lnum = prevnonblank(v:lnum - 1) |
40 | 40 |
41 " The previous line, ignoring line continuation | |
42 let prev_text_end = lnum > 0 ? getline(lnum) : '' | |
43 | |
41 " If the current line doesn't start with '\' or '"\ ' and below a line that | 44 " If the current line doesn't start with '\' or '"\ ' and below a line that |
42 " starts with '\' or '"\ ', use the indent of the line above it. | 45 " starts with '\' or '"\ ', use the indent of the line above it. |
43 let cur_text = getline(v:lnum) | 46 let cur_text = getline(v:lnum) |
44 if cur_text !~ s:lineContPat | 47 if cur_text !~ s:lineContPat |
45 while lnum > 0 && getline(lnum) =~ s:lineContPat | 48 while lnum > 0 && getline(lnum) =~ s:lineContPat |
49 | 52 |
50 " At the start of the file use zero indent. | 53 " At the start of the file use zero indent. |
51 if lnum == 0 | 54 if lnum == 0 |
52 return 0 | 55 return 0 |
53 endif | 56 endif |
57 | |
58 " the start of the previous line, skipping over line continuation | |
54 let prev_text = getline(lnum) | 59 let prev_text = getline(lnum) |
55 let found_cont = 0 | 60 let found_cont = 0 |
56 | 61 |
57 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function | 62 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function |
58 " and :else. Add it three times for a line that starts with '\' or '"\ ' | 63 " and :else. Add it three times for a line that starts with '\' or '"\ ' |
145 " todo: use searchpair() to find a match | 150 " todo: use searchpair() to find a match |
146 endif | 151 endif |
147 endif | 152 endif |
148 | 153 |
149 " Below a line starting with "]" we must be below the end of a list. | 154 " Below a line starting with "]" we must be below the end of a list. |
150 if prev_text =~ '^\s*]' | 155 if prev_text_end =~ '^\s*]' |
151 let ind = ind - shiftwidth() | 156 let ind = ind - shiftwidth() |
152 endif | 157 endif |
153 | 158 |
154 " A line ending in "{"/"[} is most likely the start of a dict/list literal, | 159 " 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. | 160 " indent the next line more. Not for a continuation line. |
156 if prev_text =~ '[{[]\s*$' && !found_cont | 161 if prev_text_end =~ '[{[]\s*$' && !found_cont |
157 let ind = ind + shiftwidth() | 162 let ind = ind + shiftwidth() |
158 endif | 163 endif |
159 | 164 |
160 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry, | 165 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry, |
161 " :endfun, :enddef, :else and :augroup END. | 166 " :endfun, :enddef, :else and :augroup END. |