Mercurial > vim
annotate runtime/indent/vim.vim @ 29607:33d7c1fa2dac v9.0.0144
patch 9.0.0144: text property cannot override 'cursorline' highlight
Commit: https://github.com/vim/vim/commit/f4ba8bc47eb3c6b5899ef31d083b9b8f0d4ca456
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 5 17:05:04 2022 +0100
patch 9.0.0144: text property cannot override 'cursorline' highlight
Problem: Text property cannot override 'cursorline' highlight.
Solution: Add the "override" flag to prop_type_add(). (closes https://github.com/vim/vim/issues/5533,
closes #8225).
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 05 Aug 2022 18:15:08 +0200 |
parents | d314efe6447a |
children | ebed259f919f |
rev | line source |
---|---|
7 | 1 " Vim indent file |
2 " Language: Vim script | |
3 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
29274 | 4 " Last Change: 2022 Jun 24 |
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() | |
27903 | 13 setlocal indentkeys+==endif,=enddef,=endfu,=endfor,=endwh,=endtry,=},=else,=cat,=finall,=END,0\\,0=\"\\\ |
21499 | 14 setlocal indentkeys-=0# |
26438 | 15 setlocal indentkeys-=: |
7 | 16 |
3557 | 17 let b:undo_indent = "setl indentkeys< indentexpr<" |
18 | |
7 | 19 " Only define the function once. |
20 if exists("*GetVimIndent") | |
21 finish | |
22 endif | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
23 let s:keepcpo= &cpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
24 set cpo&vim |
7 | 25 |
26 function GetVimIndent() | |
3750 | 27 let ignorecase_save = &ignorecase |
28 try | |
29 let &ignorecase = 0 | |
30 return GetVimIndentIntern() | |
31 finally | |
32 let &ignorecase = ignorecase_save | |
33 endtry | |
34 endfunc | |
35 | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
36 let s:lineContPat = '^\s*\(\\\|"\\ \)' |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
37 |
3750 | 38 function GetVimIndentIntern() |
29274 | 39 " If the current line has line continuation and the previous one too, use |
40 " the same indent. This does not skip empty lines. | |
41 let cur_text = getline(v:lnum) | |
42 let cur_has_linecont = cur_text =~ s:lineContPat | |
43 if cur_has_linecont && v:lnum > 1 && getline(v:lnum - 1) =~ s:lineContPat | |
44 return indent(v:lnum - 1) | |
45 endif | |
46 | |
7 | 47 " Find a non-blank line above the current line. |
48 let lnum = prevnonblank(v:lnum - 1) | |
49 | |
23737 | 50 " The previous line, ignoring line continuation |
51 let prev_text_end = lnum > 0 ? getline(lnum) : '' | |
52 | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
53 " 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
|
54 " starts with '\' or '"\ ', use the indent of the line above it. |
29274 | 55 if !cur_has_linecont |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
56 while lnum > 0 && getline(lnum) =~ s:lineContPat |
7 | 57 let lnum = lnum - 1 |
58 endwhile | |
59 endif | |
60 | |
61 " At the start of the file use zero indent. | |
62 if lnum == 0 | |
63 return 0 | |
64 endif | |
23737 | 65 |
66 " the start of the previous line, skipping over line continuation | |
6238 | 67 let prev_text = getline(lnum) |
23573 | 68 let found_cont = 0 |
7 | 69 |
70 " 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
|
71 " 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
|
72 " after a line that doesn't (or g:vim_indent_cont if it exists). |
7 | 73 let ind = indent(lnum) |
18489 | 74 |
75 " In heredoc indenting works completely differently. | |
76 if has('syntax_items') | |
77 let syn_here = synIDattr(synID(v:lnum, 1, 1), "name") | |
78 if syn_here =~ 'vimLetHereDocStop' | |
79 " End of heredoc: use indent of matching start line | |
80 let lnum = v:lnum - 1 | |
81 while lnum > 0 | |
24520 | 82 let attr = synIDattr(synID(lnum, 1, 1), "name") |
83 if attr != '' && attr !~ 'vimLetHereDoc' | |
18489 | 84 return indent(lnum) |
85 endif | |
86 let lnum -= 1 | |
87 endwhile | |
88 return 0 | |
89 endif | |
90 if syn_here =~ 'vimLetHereDoc' | |
91 if synIDattr(synID(lnum, 1, 1), "name") !~ 'vimLetHereDoc' | |
92 " First line in heredoc: increase indent | |
93 return ind + shiftwidth() | |
94 endif | |
95 " Heredoc continues: no change in indent | |
96 return ind | |
97 endif | |
98 endif | |
99 | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
100 if cur_text =~ s:lineContPat && v:lnum > 1 && prev_text !~ s:lineContPat |
23573 | 101 let found_cont = 1 |
22 | 102 if exists("g:vim_indent_cont") |
103 let ind = ind + g:vim_indent_cont | |
104 else | |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
105 let ind = ind + shiftwidth() * 3 |
22 | 106 endif |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
8951
diff
changeset
|
107 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
|
108 let ind = ind + shiftwidth() |
2729
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
109 else |
6238 | 110 " A line starting with :au does not increment/decrement indent. |
23931 | 111 " A { may start a block or a dict. Assume that when a } follows it's a |
112 " terminated dict. | |
27903 | 113 " ":function" starts a block but "function(" doesn't. |
23931 | 114 if prev_text !~ '^\s*au\%[tocmd]' && prev_text !~ '^\s*{.*}' |
28010 | 115 let i = match(prev_text, '\(^\||\)\s*\(export\s\+\)\?\({\|\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\|finall\%[y]\|def\|el\%[seif]\)\>\|fu\%[nction][! ]\)') |
6238 | 116 if i >= 0 |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
117 let ind += shiftwidth() |
6238 | 118 if strpart(prev_text, i, 1) == '|' && has('syntax_items') |
26100 | 119 \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\|PatSep\)$' |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
120 let ind -= shiftwidth() |
6238 | 121 endif |
2729
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
122 endif |
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
123 endif |
7 | 124 endif |
125 | |
126 " If the previous line contains an "end" after a pipe, but not in an ":au" | |
333 | 127 " command. And not when there is a backslash before the pipe. |
395 | 128 " And when syntax HL is enabled avoid a match inside a string. |
6238 | 129 let i = match(prev_text, '[^\\]|\s*\(ene\@!\)') |
130 if i > 0 && prev_text !~ '^\s*au\%[tocmd]' | |
395 | 131 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
|
132 let ind = ind - shiftwidth() |
395 | 133 endif |
7 | 134 endif |
135 | |
23573 | 136 " For a line starting with "}" find the matching "{". If it is at the start |
137 " of the line align with it, probably end of a block. | |
138 " Use the mapped "%" from matchit to find the match, otherwise we may match | |
139 " a { inside a comment or string. | |
140 if cur_text =~ '^\s*}' | |
141 if maparg('%') != '' | |
142 exe v:lnum | |
143 silent! normal % | |
144 if line('.') < v:lnum && getline('.') =~ '^\s*{' | |
145 let ind = indent('.') | |
146 endif | |
147 else | |
148 " todo: use searchpair() to find a match | |
149 endif | |
150 endif | |
151 | |
152 " Below a line starting with "}" find the matching "{". If it is at the | |
153 " end of the line we must be below the end of a dictionary. | |
154 if prev_text =~ '^\s*}' | |
155 if maparg('%') != '' | |
156 exe lnum | |
157 silent! normal % | |
158 if line('.') == lnum || getline('.') !~ '^\s*{' | |
159 let ind = ind - shiftwidth() | |
160 endif | |
161 else | |
162 " todo: use searchpair() to find a match | |
163 endif | |
164 endif | |
165 | |
166 " Below a line starting with "]" we must be below the end of a list. | |
23931 | 167 " Include a "}" and "},} in case a dictionary ends too. |
168 if prev_text_end =~ '^\s*\(},\=\s*\)\=]' | |
23573 | 169 let ind = ind - shiftwidth() |
170 endif | |
171 | |
23931 | 172 let ends_in_comment = has('syntax_items') |
24024 | 173 \ && synIDattr(synID(lnum, len(getline(lnum)), 1), "name") =~ '\(Comment\|String\)$' |
23931 | 174 |
24024 | 175 " A line ending in "{" or "[" is most likely the start of a dict/list literal, |
23931 | 176 " indent the next line more. Not for a continuation line or {{{. |
177 if !ends_in_comment && prev_text_end =~ '\s[{[]\s*$' && !found_cont | |
23573 | 178 let ind = ind + shiftwidth() |
179 endif | |
7 | 180 |
27903 | 181 " Subtract a 'shiftwidth' on a :endif, :endwhile, :endfor, :catch, :finally, |
182 " :endtry, :endfun, :enddef, :else and :augroup END. | |
183 " Although ":en" would be enough only match short command names as in | |
184 " 'indentkeys'. | |
185 if cur_text =~ '^\s*\(endif\|endwh\|endfor\|endtry\|endfu\|enddef\|cat\|finall\|else\|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
|
186 let ind = ind - shiftwidth() |
27903 | 187 if ind < 0 |
188 let ind = 0 | |
189 endif | |
7 | 190 endif |
191 | |
192 return ind | |
193 endfunction | |
194 | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
195 let &cpo = s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
196 unlet s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
197 |
7 | 198 " vim:sw=2 |