Mercurial > vim
annotate runtime/indent/vim.vim @ 21716:ba99b55d3fb7
Added tag v8.2.1407 for changeset 571832713efa4381d7390f0756b5db03a05301db
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 09 Aug 2020 17:30:04 +0200 |
parents | 3a1ed539ae2a |
children | a3bb84cd0f59 |
rev | line source |
---|---|
7 | 1 " Vim indent file |
2 " Language: Vim script | |
3 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
21499 | 4 " Last Change: 2020 Jul 19 |
7 | 5 |
6 " Only load this indent file when no other was loaded. | |
7 if exists("b:did_indent") | |
8 finish | |
9 endif | |
10 let b:did_indent = 1 | |
11 | |
12 setlocal indentexpr=GetVimIndent() | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18489
diff
changeset
|
13 setlocal indentkeys+==end,=},=else,=cat,=fina,=END,0\\,0=\"\\\ |
21499 | 14 setlocal indentkeys-=0# |
7 | 15 |
3557 | 16 let b:undo_indent = "setl indentkeys< indentexpr<" |
17 | |
7 | 18 " Only define the function once. |
19 if exists("*GetVimIndent") | |
20 finish | |
21 endif | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
22 let s:keepcpo= &cpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
23 set cpo&vim |
7 | 24 |
25 function GetVimIndent() | |
3750 | 26 let ignorecase_save = &ignorecase |
27 try | |
28 let &ignorecase = 0 | |
29 return GetVimIndentIntern() | |
30 finally | |
31 let &ignorecase = ignorecase_save | |
32 endtry | |
33 endfunc | |
34 | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
35 let s:lineContPat = '^\s*\(\\\|"\\ \)' |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
36 |
3750 | 37 function GetVimIndentIntern() |
7 | 38 " Find a non-blank line above the current line. |
39 let lnum = prevnonblank(v:lnum - 1) | |
40 | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
41 " If the current line doesn't start with '\' or '"\ ' and below a line that |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
42 " starts with '\' or '"\ ', use the indent of the line above it. |
6238 | 43 let cur_text = getline(v:lnum) |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
44 if cur_text !~ s:lineContPat |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
45 while lnum > 0 && getline(lnum) =~ s:lineContPat |
7 | 46 let lnum = lnum - 1 |
47 endwhile | |
48 endif | |
49 | |
50 " At the start of the file use zero indent. | |
51 if lnum == 0 | |
52 return 0 | |
53 endif | |
6238 | 54 let prev_text = getline(lnum) |
7 | 55 |
56 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
57 " and :else. Add it three times for a line that starts with '\' or '"\ ' |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
58 " after a line that doesn't (or g:vim_indent_cont if it exists). |
7 | 59 let ind = indent(lnum) |
18489 | 60 |
61 " In heredoc indenting works completely differently. | |
62 if has('syntax_items') | |
63 let syn_here = synIDattr(synID(v:lnum, 1, 1), "name") | |
64 if syn_here =~ 'vimLetHereDocStop' | |
65 " End of heredoc: use indent of matching start line | |
66 let lnum = v:lnum - 1 | |
67 while lnum > 0 | |
68 if synIDattr(synID(lnum, 1, 1), "name") !~ 'vimLetHereDoc' | |
69 return indent(lnum) | |
70 endif | |
71 let lnum -= 1 | |
72 endwhile | |
73 return 0 | |
74 endif | |
75 if syn_here =~ 'vimLetHereDoc' | |
76 if synIDattr(synID(lnum, 1, 1), "name") !~ 'vimLetHereDoc' | |
77 " First line in heredoc: increase indent | |
78 return ind + shiftwidth() | |
79 endif | |
80 " Heredoc continues: no change in indent | |
81 return ind | |
82 endif | |
83 endif | |
84 | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
85 if cur_text =~ s:lineContPat && v:lnum > 1 && prev_text !~ s:lineContPat |
22 | 86 if exists("g:vim_indent_cont") |
87 let ind = ind + g:vim_indent_cont | |
88 else | |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
89 let ind = ind + shiftwidth() * 3 |
22 | 90 endif |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
8951
diff
changeset
|
91 elseif prev_text =~ '^\s*aug\%[roup]\s\+' && prev_text !~ '^\s*aug\%[roup]\s\+[eE][nN][dD]\>' |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
92 let ind = ind + shiftwidth() |
2729
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
93 else |
6238 | 94 " A line starting with :au does not increment/decrement indent. |
95 if prev_text !~ '^\s*au\%[tocmd]' | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18489
diff
changeset
|
96 let i = match(prev_text, '\(^\||\)\s*\({\|\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|def\|el\%[seif]\)\>\)') |
6238 | 97 if i >= 0 |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
98 let ind += shiftwidth() |
6238 | 99 if strpart(prev_text, i, 1) == '|' && has('syntax_items') |
100 \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$' | |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
101 let ind -= shiftwidth() |
6238 | 102 endif |
2729
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
103 endif |
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
104 endif |
7 | 105 endif |
106 | |
107 " If the previous line contains an "end" after a pipe, but not in an ":au" | |
333 | 108 " command. And not when there is a backslash before the pipe. |
395 | 109 " And when syntax HL is enabled avoid a match inside a string. |
6238 | 110 let i = match(prev_text, '[^\\]|\s*\(ene\@!\)') |
111 if i > 0 && prev_text !~ '^\s*au\%[tocmd]' | |
395 | 112 if !has('syntax_items') || synIDattr(synID(lnum, i + 2, 1), "name") !~ '\(Comment\|String\)$' |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
113 let ind = ind - shiftwidth() |
395 | 114 endif |
7 | 115 endif |
116 | |
117 | |
118 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry, | |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18489
diff
changeset
|
119 " :endfun, :enddef, :else and :augroup END. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18489
diff
changeset
|
120 if cur_text =~ '^\s*\(ene\@!\|}\|cat\|fina\|el\|aug\%[roup]\s\+[eE][nN][dD]\)' |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
121 let ind = ind - shiftwidth() |
7 | 122 endif |
123 | |
124 return ind | |
125 endfunction | |
126 | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
127 let &cpo = s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
128 unlet s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
129 |
7 | 130 " vim:sw=2 |