annotate runtime/indent/solidity.vim @ 34559:ef55fe2ac8be v9.1.0180

patch 9.1.0180: Cursor pos wrong when double-width chars are concealed Commit: https://github.com/vim/vim/commit/010e1539d67442cc69a97bef6453efaf849d0db3 Author: zeertzjq <zeertzjq@outlook.com> Date: Thu Mar 14 18:22:17 2024 +0100 patch 9.1.0180: Cursor pos wrong when double-width chars are concealed Problem: Cursor pos wrong when double-width chars are concealed. Solution: Advance one more virtual column for a double-width char. Run some tests with both 'wrap' and 'nowrap' (zeertzjq). closes: #14197 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 14 Mar 2024 18:30:05 +0100
parents 32c896b7e001
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30547
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Vim indent file
32956
32c896b7e001 runtime(solidity): add new ftplugin (#12877)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
2 " Language: Solidity
32c896b7e001 runtime(solidity): add new ftplugin (#12877)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
3 " Maintainer: Cothi (jiungdev@gmail.com)
32c896b7e001 runtime(solidity): add new ftplugin (#12877)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
4 " Original Author: tomlion (https://github.com/tomlion/vim-solidity)
32c896b7e001 runtime(solidity): add new ftplugin (#12877)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
5 " Last Change: 2022 Sep 27
32c896b7e001 runtime(solidity): add new ftplugin (#12877)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
6 " 2023 Aug 22 Vim Project (undo_indent)
32c896b7e001 runtime(solidity): add new ftplugin (#12877)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
7 "
32c896b7e001 runtime(solidity): add new ftplugin (#12877)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
8 " Acknowledgement: Based off of vim-javascript
30547
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 "
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 " 0. Initialization {{{1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 " =================
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 " Only load this indent file when no other was loaded.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 if exists("b:did_indent")
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 finish
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 let b:did_indent = 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 setlocal nosmartindent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 " Now, set up our indentation expression and keys that trigger it.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 setlocal indentexpr=GetSolidityIndent()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24
32956
32c896b7e001 runtime(solidity): add new ftplugin (#12877)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
25 let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
32c896b7e001 runtime(solidity): add new ftplugin (#12877)
Christian Brabandt <cb@256bit.org>
parents: 30547
diff changeset
26
30547
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 " Only define the function once.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 if exists("*GetSolidityIndent")
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 finish
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 let s:cpo_save = &cpo
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 set cpo&vim
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 " 1. Variables {{{1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 " ============
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 let s:js_keywords = '^\s*\(break\|case\|catch\|continue\|debugger\|default\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 " Regex of syntax group names that are or delimit string or are comments.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 let s:syng_strcom = 'string\|regex\|comment\c'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 " Regex of syntax group names that are strings.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 let s:syng_string = 'regex\c'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 " Regex of syntax group names that are strings or documentation.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 let s:syng_multiline = 'comment\c'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 " Regex of syntax group names that are line comment.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 let s:syng_linecom = 'linecomment\c'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 " Expression used to check whether we should skip a match with searchpair().
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'"
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 " Regex that defines continuation lines, not including (, {, or [.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)' . s:line_term
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 " Regex that defines continuation lines.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 " TODO: this needs to deal with if ...: and so on
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 let s:msl_regex = '\%([\\*+/.:([]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)' . s:line_term
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 " Regex that defines blocks.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 let s:var_stmt = '^\s*var'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 let s:comma_first = '^\s*,'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 let s:comma_last = ',\s*$'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 let s:ternary = '^\s\+[?|:]'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 let s:ternary_q = '^\s\+?'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 " 2. Auxiliary Functions {{{1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 " ======================
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 " Check if the character at lnum:col is inside a string, comment, or is ascii.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 function s:IsInStringOrComment(lnum, col)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 " Check if the character at lnum:col is inside a string.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 function s:IsInString(lnum, col)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 " Check if the character at lnum:col is inside a multi-line comment.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 function s:IsInMultilineComment(lnum, col)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 " Check if the character at lnum:col is a line comment.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 function s:IsLineComment(lnum, col)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_linecom
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 " Find line above 'lnum' that isn't empty, in a comment, or in a string.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 function s:PrevNonBlankNonString(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 let in_block = 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 let lnum = prevnonblank(a:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 while lnum > 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 " Go in and out of blocks comments as necessary.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 " If the line isn't empty (with opt. comment) or in a string, end search.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 let line = getline(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 if line =~ '/\*'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 if in_block
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 let in_block = 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 break
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 elseif !in_block && line =~ '\*/'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 let in_block = 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 elseif !in_block && line !~ '^\s*\%(//\).*$' && !(s:IsInStringOrComment(lnum, 1) && s:IsInStringOrComment(lnum, strlen(line)))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 break
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 let lnum = prevnonblank(lnum - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 endwhile
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 return lnum
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 " Find line above 'lnum' that started the continuation 'lnum' may be part of.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 function s:GetMSL(lnum, in_one_line_scope)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 " Start on the line we're at and use its indent.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 let msl = a:lnum
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 let lnum = s:PrevNonBlankNonString(a:lnum - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 while lnum > 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 " If we have a continuation line, or we're in a string, use line as MSL.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 " Otherwise, terminate search as we have found our MSL already.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 let line = getline(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 let col = match(line, s:msl_regex) + 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 let msl = lnum
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 " Don't use lines that are part of a one line scope as msl unless the
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 " flag in_one_line_scope is set to 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 "
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 if a:in_one_line_scope
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 break
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 end
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 let msl_one_line = s:Match(lnum, s:one_line_scope_regex)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 if msl_one_line == 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 break
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 let lnum = s:PrevNonBlankNonString(lnum - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 endwhile
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 return msl
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 function s:RemoveTrailingComments(content)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 let single = '\/\/\(.*\)\s*$'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 let multi = '\/\*\(.*\)\*\/\s*$'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 return substitute(substitute(a:content, single, '', ''), multi, '', '')
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 " Find if the string is inside var statement (but not the first string)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 function s:InMultiVarStatement(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 let lnum = s:PrevNonBlankNonString(a:lnum - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 " let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name')
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 " loop through previous expressions to find a var statement
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 while lnum > 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 let line = getline(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 " if the line is a js keyword
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 if (line =~ s:js_keywords)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 " check if the line is a var stmt
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 " if the line has a comma first or comma last then we can assume that we
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 " are in a multiple var statement
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 if (line =~ s:var_stmt)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 return lnum
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 " other js keywords, not a var
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 return 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 let lnum = s:PrevNonBlankNonString(lnum - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 endwhile
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 " beginning of program, not a var
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 return 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 " Find line above with beginning of the var statement or returns 0 if it's not
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 " this statement
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 function s:GetVarIndent(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 let lvar = s:InMultiVarStatement(a:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 let prev_lnum = s:PrevNonBlankNonString(a:lnum - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 if lvar
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 let line = s:RemoveTrailingComments(getline(prev_lnum))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 " if the previous line doesn't end in a comma, return to regular indent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 if (line !~ s:comma_last)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 return indent(prev_lnum) - &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 return indent(lvar) + &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 return -1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 " Check if line 'lnum' has more opening brackets than closing ones.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 function s:LineHasOpeningBrackets(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 let open_0 = 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 let open_2 = 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 let open_4 = 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 let line = getline(a:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 let pos = match(line, '[][(){}]', 0)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 while pos != -1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 if !s:IsInStringOrComment(a:lnum, pos + 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 let idx = stridx('(){}[]', line[pos])
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 if idx % 2 == 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 let open_{idx} = open_{idx} + 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 let open_{idx - 1} = open_{idx - 1} - 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 let pos = match(line, '[][(){}]', pos + 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 endwhile
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 function s:Match(lnum, regex)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 let col = match(getline(a:lnum), a:regex) + 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 function s:IndentWithContinuation(lnum, ind, width)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 " Set up variables to use and search for MSL to the previous line.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 let p_lnum = a:lnum
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 let lnum = s:GetMSL(a:lnum, 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 let line = getline(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 " If the previous line wasn't a MSL and is continuation return its indent.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 " TODO: the || s:IsInString() thing worries me a bit.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 if p_lnum != lnum
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 return a:ind
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 " Set up more variables now that we know we aren't continuation bound.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 let msl_ind = indent(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 " If the previous line ended with [*+/.-=], start a continuation that
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 " indents an extra level.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 if s:Match(lnum, s:continuation_regex)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 if lnum == p_lnum
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 return msl_ind + a:width
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 return msl_ind
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 return a:ind
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 function s:InOneLineScope(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 let msl = s:GetMSL(a:lnum, 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 if msl > 0 && s:Match(msl, s:one_line_scope_regex)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 return msl
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 return 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 function s:ExitingOneLineScope(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 let msl = s:GetMSL(a:lnum, 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 if msl > 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 " if the current line is in a one line scope ..
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 if s:Match(msl, s:one_line_scope_regex)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 return 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 let prev_msl = s:GetMSL(msl - 1, 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 if s:Match(prev_msl, s:one_line_scope_regex)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 return prev_msl
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 return 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 " 3. GetSolidityIndent Function {{{1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 " =========================
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 function GetSolidityIndent()
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 " 3.1. Setup {{{2
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 " ----------
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 " Set up variables for restoring position in file. Could use v:lnum here.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 let vcol = col('.')
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 " 3.2. Work on the current line {{{2
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 " -----------------------------
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 let ind = -1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 " Get the current line.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 let line = getline(v:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 " previous nonblank line number
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 let prevline = prevnonblank(v:lnum - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 " If we got a closing bracket on an empty line, find its match and indent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 " according to it. For parentheses we indent to its column - 1, for the
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 " others we indent to the containing line's MSL's level. Return -1 if fail.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 let col = matchend(line, '^\s*[],})]')
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 if col > 0 && !s:IsInStringOrComment(v:lnum, col)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 call cursor(v:lnum, col)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 let lvar = s:InMultiVarStatement(v:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 if lvar
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 let prevline_contents = s:RemoveTrailingComments(getline(prevline))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 " check for comma first
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 if (line[col - 1] =~ ',')
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 " if the previous line ends in comma or semicolon don't indent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 if (prevline_contents =~ '[;,]\s*$')
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 return indent(s:GetMSL(line('.'), 0))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 " get previous line indent, if it's comma first return prevline indent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 elseif (prevline_contents =~ s:comma_first)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 return indent(prevline)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 " otherwise we indent 1 level
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 return indent(lvar) + &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 if line[col-1]==')' && col('.') != col('$') - 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 let ind = virtcol('.')-1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 let ind = indent(s:GetMSL(line('.'), 0))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 return ind
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 " If the line is comma first, dedent 1 level
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 if (getline(prevline) =~ s:comma_first)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 return indent(prevline) - &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 if (line =~ s:ternary)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 if (getline(prevline) =~ s:ternary_q)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 return indent(prevline)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 return indent(prevline) + &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 " If we are in a multi-line comment, cindent does the right thing.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 return cindent(v:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 " Check for multiple var assignments
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 " let var_indent = s:GetVarIndent(v:lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 " if var_indent >= 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 " return var_indent
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 " endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 " 3.3. Work on the previous line. {{{2
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 " -------------------------------
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 " If the line is empty and the previous nonblank line was a multi-line
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 " comment, use that comment's indent. Deduct one char to account for the
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 " space in ' */'.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 if line =~ '^\s*$' && s:IsInMultilineComment(prevline, 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 return indent(prevline) - 1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 " Find a non-blank, non-multi-line string line above the current line.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 let lnum = s:PrevNonBlankNonString(v:lnum - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 " If the line is empty and inside a string, use the previous line.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 if line =~ '^\s*$' && lnum != prevline
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 return indent(prevnonblank(v:lnum))
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 " At the start of the file use zero indent.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 if lnum == 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 return 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 " Set up variables for current line.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 let line = getline(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 let ind = indent(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 " If the previous line ended with a block opening, add a level of indent.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 if s:Match(lnum, s:block_regex)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 return indent(s:GetMSL(lnum, 0)) + &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 " If the previous line contained an opening bracket, and we are still in it,
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 " add indent depending on the bracket type.
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 if line =~ '[[({]'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 let counts = s:LineHasOpeningBrackets(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 if col('.') + 1 == col('$')
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 return ind + &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 return virtcol('.')
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 elseif counts[1] == '1' || counts[2] == '1'
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 return ind + &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 call cursor(v:lnum, vcol)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 end
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 " 3.4. Work on the MSL line. {{{2
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 " --------------------------
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 let ind_con = ind
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 let ind = s:IndentWithContinuation(lnum, ind_con, &sw)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 " }}}2
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 "
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 "
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 let ols = s:InOneLineScope(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 if ols > 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 let ind = ind + &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 else
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 let ols = s:ExitingOneLineScope(lnum)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 while ols > 0 && ind > 0
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 let ind = ind - &sw
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 let ols = s:InOneLineScope(ols - 1)
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 endwhile
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 endif
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 return ind
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 endfunction
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 " }}}1
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 let &cpo = s:cpo_save
1e91e26ceebf Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 unlet s:cpo_save