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