Mercurial > vim
annotate runtime/indent/vim.vim @ 27096:d539c144aeb4 v8.2.4077
patch 8.2.4077: not all Libsensors files are recognized
Commit: https://github.com/vim/vim/commit/8d9e470aa91a93da7d6bda62521aef69a79e956d
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jan 13 14:49:10 2022 +0000
patch 8.2.4077: not all Libsensors files are recognized
Problem: Not all Libsensors files are recognized.
Solution: Add "sensors.d/*" pattern. (Doug Kearns)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 13 Jan 2022 16:00:05 +0100 |
parents | c725b8e17f1f |
children | d19b7aee1925 |
rev | line source |
---|---|
7 | 1 " Vim indent file |
2 " Language: Vim script | |
3 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
26438 | 4 " Last Change: 2021 Nov 27 |
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() | |
22441 | 13 setlocal indentkeys+==end,=},=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() |
7 | 39 " Find a non-blank line above the current line. |
40 let lnum = prevnonblank(v:lnum - 1) | |
41 | |
23737 | 42 " The previous line, ignoring line continuation |
43 let prev_text_end = lnum > 0 ? getline(lnum) : '' | |
44 | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
45 " 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
|
46 " starts with '\' or '"\ ', use the indent of the line above it. |
6238 | 47 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
|
48 if cur_text !~ s:lineContPat |
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
49 while lnum > 0 && getline(lnum) =~ s:lineContPat |
7 | 50 let lnum = lnum - 1 |
51 endwhile | |
52 endif | |
53 | |
54 " At the start of the file use zero indent. | |
55 if lnum == 0 | |
56 return 0 | |
57 endif | |
23737 | 58 |
59 " the start of the previous line, skipping over line continuation | |
6238 | 60 let prev_text = getline(lnum) |
23573 | 61 let found_cont = 0 |
7 | 62 |
63 " 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
|
64 " 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
|
65 " after a line that doesn't (or g:vim_indent_cont if it exists). |
7 | 66 let ind = indent(lnum) |
18489 | 67 |
68 " In heredoc indenting works completely differently. | |
69 if has('syntax_items') | |
70 let syn_here = synIDattr(synID(v:lnum, 1, 1), "name") | |
71 if syn_here =~ 'vimLetHereDocStop' | |
72 " End of heredoc: use indent of matching start line | |
73 let lnum = v:lnum - 1 | |
74 while lnum > 0 | |
24520 | 75 let attr = synIDattr(synID(lnum, 1, 1), "name") |
76 if attr != '' && attr !~ 'vimLetHereDoc' | |
18489 | 77 return indent(lnum) |
78 endif | |
79 let lnum -= 1 | |
80 endwhile | |
81 return 0 | |
82 endif | |
83 if syn_here =~ 'vimLetHereDoc' | |
84 if synIDattr(synID(lnum, 1, 1), "name") !~ 'vimLetHereDoc' | |
85 " First line in heredoc: increase indent | |
86 return ind + shiftwidth() | |
87 endif | |
88 " Heredoc continues: no change in indent | |
89 return ind | |
90 endif | |
91 endif | |
92 | |
14714
bdbb049c2aa8
patch 8.1.0369: continuation lines cannot contain comments
Christian Brabandt <cb@256bit.org>
parents:
9407
diff
changeset
|
93 if cur_text =~ s:lineContPat && v:lnum > 1 && prev_text !~ s:lineContPat |
23573 | 94 let found_cont = 1 |
22 | 95 if exists("g:vim_indent_cont") |
96 let ind = ind + g:vim_indent_cont | |
97 else | |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
98 let ind = ind + shiftwidth() * 3 |
22 | 99 endif |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
8951
diff
changeset
|
100 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
|
101 let ind = ind + shiftwidth() |
2729
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
102 else |
6238 | 103 " A line starting with :au does not increment/decrement indent. |
23931 | 104 " A { may start a block or a dict. Assume that when a } follows it's a |
105 " terminated dict. | |
106 if prev_text !~ '^\s*au\%[tocmd]' && prev_text !~ '^\s*{.*}' | |
22441 | 107 let i = match(prev_text, '\(^\||\)\s*\(export\s\+\)\?\({\|\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\|finall\%[y]\|fu\%[nction]\|def\|el\%[seif]\)\>\)') |
6238 | 108 if i >= 0 |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
109 let ind += shiftwidth() |
6238 | 110 if strpart(prev_text, i, 1) == '|' && has('syntax_items') |
26100 | 111 \ && 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
|
112 let ind -= shiftwidth() |
6238 | 113 endif |
2729
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
114 endif |
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
115 endif |
7 | 116 endif |
117 | |
118 " If the previous line contains an "end" after a pipe, but not in an ":au" | |
333 | 119 " command. And not when there is a backslash before the pipe. |
395 | 120 " And when syntax HL is enabled avoid a match inside a string. |
6238 | 121 let i = match(prev_text, '[^\\]|\s*\(ene\@!\)') |
122 if i > 0 && prev_text !~ '^\s*au\%[tocmd]' | |
395 | 123 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
|
124 let ind = ind - shiftwidth() |
395 | 125 endif |
7 | 126 endif |
127 | |
23573 | 128 " For a line starting with "}" find the matching "{". If it is at the start |
129 " of the line align with it, probably end of a block. | |
130 " Use the mapped "%" from matchit to find the match, otherwise we may match | |
131 " a { inside a comment or string. | |
132 if cur_text =~ '^\s*}' | |
133 if maparg('%') != '' | |
134 exe v:lnum | |
135 silent! normal % | |
136 if line('.') < v:lnum && getline('.') =~ '^\s*{' | |
137 let ind = indent('.') | |
138 endif | |
139 else | |
140 " todo: use searchpair() to find a match | |
141 endif | |
142 endif | |
143 | |
144 " Below a line starting with "}" find the matching "{". If it is at the | |
145 " end of the line we must be below the end of a dictionary. | |
146 if prev_text =~ '^\s*}' | |
147 if maparg('%') != '' | |
148 exe lnum | |
149 silent! normal % | |
150 if line('.') == lnum || getline('.') !~ '^\s*{' | |
151 let ind = ind - shiftwidth() | |
152 endif | |
153 else | |
154 " todo: use searchpair() to find a match | |
155 endif | |
156 endif | |
157 | |
158 " Below a line starting with "]" we must be below the end of a list. | |
23931 | 159 " Include a "}" and "},} in case a dictionary ends too. |
160 if prev_text_end =~ '^\s*\(},\=\s*\)\=]' | |
23573 | 161 let ind = ind - shiftwidth() |
162 endif | |
163 | |
23931 | 164 let ends_in_comment = has('syntax_items') |
24024 | 165 \ && synIDattr(synID(lnum, len(getline(lnum)), 1), "name") =~ '\(Comment\|String\)$' |
23931 | 166 |
24024 | 167 " A line ending in "{" or "[" is most likely the start of a dict/list literal, |
23931 | 168 " indent the next line more. Not for a continuation line or {{{. |
169 if !ends_in_comment && prev_text_end =~ '\s[{[]\s*$' && !found_cont | |
23573 | 170 let ind = ind + shiftwidth() |
171 endif | |
7 | 172 |
173 " 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
|
174 " :endfun, :enddef, :else and :augroup END. |
23573 | 175 if cur_text =~ '^\s*\(ene\@!\|cat\|finall\|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
|
176 let ind = ind - shiftwidth() |
7 | 177 endif |
178 | |
179 return ind | |
180 endfunction | |
181 | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
182 let &cpo = s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
183 unlet s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
184 |
7 | 185 " vim:sw=2 |