annotate runtime/indent/jsonc.vim @ 34907:8c9e43278b2c v9.1.0314

patch 9.1.0314: Vim9: Can define a class in a function Commit: https://github.com/vim/vim/commit/c51578fed8f21cf3c1ff72bbb599dca2db02be84 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Apr 13 17:58:09 2024 +0200 patch 9.1.0314: Vim9: Can define a class in a function Problem: Vim9: Can define a class in a function (Doug Kearns) Solution: Give an error for a class defined in a function, slightly reword some public error messages (Yegappan Lakshmanan) fixes: #13184 fixes: #13326 closes: #14537 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 13 Apr 2024 18:15:03 +0200
parents 5c220cf30f1f
children
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
33052
5c220cf30f1f runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents: 25161
diff changeset
7 " 2023 Aug 28 by Vim Project (undo_indent)
25161
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 " 0. Initialization {{{1
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
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 " Only load this indent file when no other was loaded.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 if exists("b:did_indent")
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 finish
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 let b:did_indent = 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 setlocal nosmartindent
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 " Now, set up our indentation expression and keys that trigger it.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 setlocal indentexpr=GetJSONCIndent()
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 setlocal indentkeys=0{,0},0),0[,0],!^F,o,O,e
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23
33052
5c220cf30f1f runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents: 25161
diff changeset
24 let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
5c220cf30f1f runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents: 25161
diff changeset
25
25161
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 " Only define the function once.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 if exists("*GetJSONCIndent")
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 finish
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 endif
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 let s:cpo_save = &cpo
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 set cpo&vim
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 " 1. Variables {{{1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 " ============
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 " Regex that defines blocks.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 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
40
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 " 2. Auxiliary Functions {{{1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 " ======================
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 " Check if the character at lnum:col is inside a string.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 function s:IsInString(lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'jsonString'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 endfunction
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 " Find line above 'lnum' that isn't empty, or in a string.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 function s:PrevNonBlankNonString(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 let lnum = prevnonblank(a:lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 while lnum > 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 " If the line isn't empty or in a string, end search.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 let line = getline(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 if !(s:IsInString(lnum, 1) && s:IsInString(lnum, strlen(line)))
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 break
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 let lnum = prevnonblank(lnum - 1)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 endwhile
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 return lnum
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 endfunction
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 " Check if line 'lnum' has more opening brackets than closing ones.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 function s:LineHasOpeningBrackets(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 let open_0 = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 let open_2 = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 let open_4 = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 let line = getline(a:lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 let pos = match(line, '[][(){}]', 0)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 while pos != -1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 let idx = stridx('(){}[]', line[pos])
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 if idx % 2 == 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 let open_{idx} = open_{idx} + 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 else
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 let open_{idx - 1} = open_{idx - 1} - 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 let pos = match(line, '[][(){}]', pos + 1)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 endwhile
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 endfunction
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 function s:Match(lnum, regex)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 let col = match(getline(a:lnum), a:regex) + 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 return col > 0 && !s:IsInString(a:lnum, col) ? col : 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 endfunction
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 " 3. GetJSONCIndent Function {{{1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 " =========================
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 function GetJSONCIndent()
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 if !exists("s:inside_comment")
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 let s:inside_comment = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 endif
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 " 3.1. Setup {{{2
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 " ----------
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 " 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
99 let vcol = col('.')
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 " 3.2. Work on the current line {{{2
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 " -----------------------------
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 " Get the current line.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 let line = getline(v:lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 let ind = -1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 if s:inside_comment == 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 " TODO iterate through all the matches in a line
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 let col = matchend(line, '\/\*')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 if col > 0 && !s:IsInString(v:lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 let s:inside_comment = 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 " If we're in the middle of a comment
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 if s:inside_comment == 1
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 let col = matchend(line, '\*\/')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 if col > 0 && !s:IsInString(v:lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 let s:inside_comment = 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 endif
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 if line =~ '^\s*//'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 return ind
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 " 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
128 " according to it.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 let col = matchend(line, '^\s*[]}]')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 if col > 0 && !s:IsInString(v:lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 call cursor(v:lnum, col)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 let bs = strpart('{}[]', stridx('}]', line[col - 1]) * 2, 2)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 let pairstart = escape(bs[0], '[')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 let pairend = escape(bs[1], ']')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 let pairline = searchpair(pairstart, '', pairend, 'bW')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 if pairline > 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 let ind = indent(pairline)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 else
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 let ind = virtcol('.') - 1
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 return ind
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 " 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
149 if s:IsInString(v:lnum, matchend(line, '^\s*') + 1)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 return indent('.')
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 endif
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 " 3.3. Work on the previous line. {{{2
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
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 let lnum = prevnonblank(v:lnum - 1)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 if lnum == 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 return 0
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 " Set up variables for current line.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 let line = getline(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 let ind = indent(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 " 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
167 " if s:Match(lnum, s:block_regex)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 " return indent(lnum) + shiftwidth()
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 " endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 " 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
172 " add indent depending on the bracket type.
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 if line =~ '[[({]'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 let counts = s:LineHasOpeningBrackets(lnum)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 if counts[0] == '1' || counts[1] == '1' || counts[2] == '1'
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 return ind + shiftwidth()
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 else
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 call cursor(v:lnum, vcol)
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 end
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 endif
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 " }}}2
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 return ind
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 endfunction
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 " }}}1
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 let &cpo = s:cpo_save
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 unlet s:cpo_save
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191
84c7dc0fdcd2 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 " vim:set sw=2 sts=2 ts=8 noet: