annotate runtime/indent/jsonc.vim @ 31077:6a2b04cd0213 v9.0.0873

patch 9.0.0873: using freed memory when executing mapclear at more prompt Commit: https://github.com/vim/vim/commit/bf533e4e88ebac8b8fec6d3e12dadc476ce9a1df Author: Bram Moolenaar <Bram@vim.org> Date: Sun Nov 13 20:43:19 2022 +0000 patch 9.0.0873: using freed memory when executing mapclear at more prompt Problem: Using freed memory when executing mapclear at the more prompt. Solution: Do not clear mappings while listing them. (closes https://github.com/vim/vim/issues/11438)
author Bram Moolenaar <Bram@vim.org>
date Sun, 13 Nov 2022 21:45:03 +0100
parents 84c7dc0fdcd2
children 5c220cf30f1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25161
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Vim indent file
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 " Language: JSONC (JSON with Comments)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 " Original Author: Izhak Jakov <izhak724@gmail.com>
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 " Acknowledgement: Based off of vim-json maintained by Eli Parra <eli@elzr.com>
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 " https://github.com/elzr/vim-json
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 " Last Change: 2021-07-01
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 " 0. Initialization {{{1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 " =================
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 " Only load this indent file when no other was loaded.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 if exists("b:did_indent")
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 finish
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 let b:did_indent = 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 setlocal nosmartindent
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 " Now, set up our indentation expression and keys that trigger it.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 setlocal indentexpr=GetJSONCIndent()
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 setlocal indentkeys=0{,0},0),0[,0],!^F,o,O,e
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 " Only define the function once.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 if exists("*GetJSONCIndent")
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 finish
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 let s:cpo_save = &cpo
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 set cpo&vim
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 " 1. Variables {{{1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 " ============
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 " Regex that defines blocks.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 let s:block_regex = '\%({\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 " 2. Auxiliary Functions {{{1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 " ======================
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 " Check if the character at lnum:col is inside a string.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 function s:IsInString(lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'jsonString'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 endfunction
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 " Find line above 'lnum' that isn't empty, or in a string.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 function s:PrevNonBlankNonString(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 let lnum = prevnonblank(a:lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 while lnum > 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 " If the line isn't empty or in a string, end search.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 let line = getline(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 if !(s:IsInString(lnum, 1) && s:IsInString(lnum, strlen(line)))
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 break
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 let lnum = prevnonblank(lnum - 1)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 endwhile
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 return lnum
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 endfunction
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 " Check if line 'lnum' has more opening brackets than closing ones.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 function s:LineHasOpeningBrackets(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 let open_0 = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 let open_2 = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 let open_4 = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 let line = getline(a:lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 let pos = match(line, '[][(){}]', 0)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 while pos != -1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 let idx = stridx('(){}[]', line[pos])
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 if idx % 2 == 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 let open_{idx} = open_{idx} + 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 else
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 let open_{idx - 1} = open_{idx - 1} - 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 let pos = match(line, '[][(){}]', pos + 1)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 endwhile
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 endfunction
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 function s:Match(lnum, regex)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 let col = match(getline(a:lnum), a:regex) + 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 return col > 0 && !s:IsInString(a:lnum, col) ? col : 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 endfunction
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 " 3. GetJSONCIndent Function {{{1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 " =========================
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 function GetJSONCIndent()
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 if !exists("s:inside_comment")
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 let s:inside_comment = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 " 3.1. Setup {{{2
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 " ----------
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 " Set up variables for restoring position in file. Could use v:lnum here.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 let vcol = col('.')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 " 3.2. Work on the current line {{{2
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 " -----------------------------
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 " Get the current line.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 let line = getline(v:lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 let ind = -1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 if s:inside_comment == 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 " TODO iterate through all the matches in a line
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 let col = matchend(line, '\/\*')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 if col > 0 && !s:IsInString(v:lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 let s:inside_comment = 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 " If we're in the middle of a comment
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 if s:inside_comment == 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 let col = matchend(line, '\*\/')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 if col > 0 && !s:IsInString(v:lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 let s:inside_comment = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 return ind
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 if line =~ '^\s*//'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 return ind
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 " If we got a closing bracket on an empty line, find its match and indent
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 " according to it.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 let col = matchend(line, '^\s*[]}]')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 if col > 0 && !s:IsInString(v:lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 call cursor(v:lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 let bs = strpart('{}[]', stridx('}]', line[col - 1]) * 2, 2)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 let pairstart = escape(bs[0], '[')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 let pairend = escape(bs[1], ']')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 let pairline = searchpair(pairstart, '', pairend, 'bW')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 if pairline > 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 let ind = indent(pairline)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 else
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 let ind = virtcol('.') - 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 return ind
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 " If we are in a multi-line string, don't do anything to it.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 if s:IsInString(v:lnum, matchend(line, '^\s*') + 1)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 return indent('.')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 " 3.3. Work on the previous line. {{{2
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 " -------------------------------
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 let lnum = prevnonblank(v:lnum - 1)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 if lnum == 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 return 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 " Set up variables for current line.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 let line = getline(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 let ind = indent(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 " If the previous line ended with a block opening, add a level of indent.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 " if s:Match(lnum, s:block_regex)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 " return indent(lnum) + shiftwidth()
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 " endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 " If the previous line contained an opening bracket, and we are still in it,
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 " add indent depending on the bracket type.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 if line =~ '[[({]'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 let counts = s:LineHasOpeningBrackets(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 if counts[0] == '1' || counts[1] == '1' || counts[2] == '1'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 return ind + shiftwidth()
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 else
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 call cursor(v:lnum, vcol)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 end
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 " }}}2
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 return ind
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 endfunction
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 " }}}1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 let &cpo = s:cpo_save
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 unlet s:cpo_save
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 " vim:set sw=2 sts=2 ts=8 noet: