annotate runtime/indent/julia.vim @ 26540:682ff45f289f v8.2.3799

patch 8.2.3799: edit test hangs or fails Commit: https://github.com/vim/vim/commit/80d60910ff493f7b8ea52156e4c7df7e70a348c6 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 13 19:14:52 2021 +0000 patch 8.2.3799: edit test hangs or fails Problem: Edit test hangs or fails. Solution: Do not rethrow an exception when inside try/catch.
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Dec 2021 20:15:03 +0100
parents 29ec2c198c8d
children 1e9e9d89f0ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25619
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Vim indent file
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 " Language: Julia
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 " Maintainer: Carlo Baldassi <carlobaldassi@gmail.com>
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 " Homepage: https://github.com/JuliaEditorSupport/julia-vim
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 " Last Change: 2016 jun 16
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 " Notes: originally based on Bram Molenaar's indent file for vim
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 setlocal autoindent
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 setlocal indentexpr=GetJuliaIndent()
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 setlocal indentkeys+==end,=else,=catch,=finally,),],}
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 setlocal indentkeys-=0#
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 setlocal indentkeys-=:
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 setlocal indentkeys-=0{
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 setlocal indentkeys-=0}
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 setlocal nosmartindent
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 " Only define the function once.
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 if exists("*GetJuliaIndent")
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 finish
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 let s:skipPatternsBasic = '\<julia\%(Comment\%([LM]\|Delim\)\)\>'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 let s:skipPatterns = '\<julia\%(Comprehension\%(For\|If\)\|RangeKeyword\|Comment\%([LM]\|Delim\)\|\%([bs]\|Shell\|Printf\|Doc\)\?String\|StringPrefixed\|DocStringM\(Raw\)\?\|RegEx\|SymbolS\?\|Macro\|Dotted\)\>'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 function JuliaMatch(lnum, str, regex, st, ...)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 let s = a:st
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 let e = a:0 > 0 ? a:1 : -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 let basic_skip = a:0 > 1 ? a:2 : 'all'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 let skip = basic_skip ==# 'basic' ? s:skipPatternsBasic : s:skipPatterns
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 while 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 let f = match(a:str, '\C' . a:regex, s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 if e >= 0 && f >= e
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 return -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 if f >= 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 let attr = synIDattr(synID(a:lnum,f+1,1),"name")
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 let attrT = synIDattr(synID(a:lnum,f+1,0),"name")
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 if attr =~# skip || attrT =~# skip
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 let s = f+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 endwhile
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 return f
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 endfunction
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 function GetJuliaNestingStruct(lnum, ...)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 " Auxiliary function to inspect the block structure of a line
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 let line = getline(a:lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 let s = a:0 > 0 ? a:1 : 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 let e = a:0 > 1 ? a:2 : -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 let blocks_stack = []
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 let num_closed_blocks = 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 while 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 let fb = JuliaMatch(a:lnum, line, '\<\%(if\|else\%(if\)\?\|while\|for\|try\|catch\|finally\|\%(staged\)\?function\|macro\|begin\|mutable\s\+struct\|\%(mutable\s\+\)\@<!struct\|\%(abstract\|primitive\)\s\+type\|let\|\%(bare\)\?module\|quote\|do\)\>', s, e)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 let fe = JuliaMatch(a:lnum, line, '\<end\>', s, e)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 if fb < 0 && fe < 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 " No blocks found
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 end
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 if fb >= 0 && (fb < fe || fe < 0)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 " The first occurrence is an opening block keyword
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 " Note: some keywords (elseif,else,catch,finally) are both
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 " closing blocks and opening new ones
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 let i = JuliaMatch(a:lnum, line, '\<if\>', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 call add(blocks_stack, 'if')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 let i = JuliaMatch(a:lnum, line, '\<elseif\>', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 if len(blocks_stack) > 0 && blocks_stack[-1] == 'if'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 let blocks_stack[-1] = 'elseif'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 elseif (len(blocks_stack) > 0 && blocks_stack[-1] != 'elseif') || len(blocks_stack) == 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 call add(blocks_stack, 'elseif')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 let num_closed_blocks += 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 let i = JuliaMatch(a:lnum, line, '\<else\>', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 if len(blocks_stack) > 0 && blocks_stack[-1] =~# '\<\%(else\)\=if\>'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 let blocks_stack[-1] = 'else'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 call add(blocks_stack, 'else')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 let num_closed_blocks += 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 let i = JuliaMatch(a:lnum, line, '\<try\>', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 call add(blocks_stack, 'try')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 let i = JuliaMatch(a:lnum, line, '\<catch\>', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 if len(blocks_stack) > 0 && blocks_stack[-1] == 'try'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 let blocks_stack[-1] = 'catch'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 call add(blocks_stack, 'catch')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 let num_closed_blocks += 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 let i = JuliaMatch(a:lnum, line, '\<finally\>', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 if len(blocks_stack) > 0 && (blocks_stack[-1] == 'try' || blocks_stack[-1] == 'catch')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 let blocks_stack[-1] = 'finally'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 call add(blocks_stack, 'finally')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 let num_closed_blocks += 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 let i = JuliaMatch(a:lnum, line, '\<\%(bare\)\?module\>', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 if i == 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 call add(blocks_stack, 'col1module')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 call add(blocks_stack, 'other')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 let i = JuliaMatch(a:lnum, line, '\<\%(while\|for\|function\|macro\|begin\|\%(mutable\s\+\)\?struct\|\%(abstract\|primitive\)\s\+type\|let\|quote\|do\)\>', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 if match(line, '\C\<\%(mutable\|abstract\|primitive\)', i) != -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 let s = i+11
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 call add(blocks_stack, 'other')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 " Note: it should be impossible to get here
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 " The first occurrence is an 'end'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 let s = fe+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 if len(blocks_stack) == 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 let num_closed_blocks += 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 call remove(blocks_stack, -1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 " Note: it should be impossible to get here
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 endwhile
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 let num_open_blocks = len(blocks_stack) - count(blocks_stack, 'col1module')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 return [num_open_blocks, num_closed_blocks]
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 endfunction
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 function GetJuliaNestingBrackets(lnum, c)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 " Auxiliary function to inspect the brackets structure of a line
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 let line = getline(a:lnum)[0 : (a:c - 1)]
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 let s = 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 let brackets_stack = []
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 let last_closed_bracket = -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 while 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 let fb = JuliaMatch(a:lnum, line, '[([{]', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 let fe = JuliaMatch(a:lnum, line, '[])}]', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 if fb < 0 && fe < 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 " No brackets found
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 end
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 if fb >= 0 && (fb < fe || fe < 0)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 " The first occurrence is an opening bracket
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 let i = JuliaMatch(a:lnum, line, '(', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 call add(brackets_stack, ['par',i])
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 let i = JuliaMatch(a:lnum, line, '\[', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 call add(brackets_stack, ['sqbra',i])
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 let i = JuliaMatch(a:lnum, line, '{', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 if i >= 0 && i == fb
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 call add(brackets_stack, ['curbra',i])
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 " Note: it should be impossible to get here
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 " The first occurrence is a closing bracket
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 let i = JuliaMatch(a:lnum, line, ')', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 if i >= 0 && i == fe
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'par'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 call remove(brackets_stack, -1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 let last_closed_bracket = i + 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 let i = JuliaMatch(a:lnum, line, ']', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 if i >= 0 && i == fe
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'sqbra'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 call remove(brackets_stack, -1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 let last_closed_bracket = i + 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 let i = JuliaMatch(a:lnum, line, '}', s)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 if i >= 0 && i == fe
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 let s = i+1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'curbra'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 call remove(brackets_stack, -1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 let last_closed_bracket = i + 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 " Note: it should be impossible to get here
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 " Note: it should be impossible to get here
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 endwhile
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 let first_open_bracket = -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 let last_open_bracket = -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 let infuncargs = 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 if len(brackets_stack) > 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 let first_open_bracket = brackets_stack[0][1]
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 let last_open_bracket = brackets_stack[-1][1]
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 if brackets_stack[-1][0] == 'par' && IsFunctionArgPar(a:lnum, last_open_bracket+1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 let infuncargs = 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 return [first_open_bracket, last_open_bracket, last_closed_bracket, infuncargs]
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 endfunction
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 let s:bracketBlocks = '\<julia\%(\%(\%(Printf\)\?Par\|SqBra\%(Idx\)\?\|CurBra\)Block\|ParBlockInRange\|StringVars\%(Par\|SqBra\|CurBra\)\|Dollar\%(Par\|SqBra\)\|QuotedParBlockS\?\)\>'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 function IsInBrackets(lnum, c)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 let stack = map(synstack(a:lnum, a:c), 'synIDattr(v:val, "name")')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 call filter(stack, 'v:val =~# s:bracketBlocks')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 return len(stack) > 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 endfunction
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 function IsInDocString(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 let stack = map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 call filter(stack, 'v:val =~# "\\<juliaDocString\\(Delim\\|M\\\(Raw\\)\\?\\)\\?\\>"')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 return len(stack) > 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 endfunction
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 function IsInContinuationImportLine(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 let stack = map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 call filter(stack, 'v:val =~# "\\<juliaImportLine\\>"')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 if len(stack) == 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 return 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 return JuliaMatch(a:lnum, getline(a:lnum), '\<\%(import\|using\|export\)\>', indent(a:lnum)) == -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 endfunction
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 function IsFunctionArgPar(lnum, c)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 if a:c == 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 return 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 let stack = map(synstack(a:lnum, a:c-1), 'synIDattr(v:val, "name")')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 return len(stack) >= 2 && stack[-2] ==# 'juliaFunctionDef'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 endfunction
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 function JumpToMatch(lnum, last_closed_bracket)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 " we use the % command to skip back (tries to ues matchit if possible,
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 " otherwise resorts to vim's default, which is buggy but better than
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 " nothing)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 call cursor(a:lnum, a:last_closed_bracket)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 let percmap = maparg("%", "n")
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 if exists("g:loaded_matchit") && percmap =~# 'Match\%(it\|_wrapper\)'
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 normal %
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 normal! %
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 end
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 endfunction
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 " Auxiliary function to find a line which does not start in the middle of a
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 " multiline bracketed expression, to be used as reference for block
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 " indentation.
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 function LastBlockIndent(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 let lnum = a:lnum
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 let ind = 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 while lnum > 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 let ind = indent(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 if ind == 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 return [lnum, 0]
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 if !IsInBrackets(lnum, 1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 let lnum = prevnonblank(lnum - 1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 endwhile
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 return [max([lnum,1]), ind]
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 endfunction
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 function GetJuliaIndent()
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 " Do not alter doctrings indentation
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 if IsInDocString(v:lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 return -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 " Find a non-blank line above the current line.
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 let lnum = prevnonblank(v:lnum - 1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 " At the start of the file use zero indent.
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 if lnum == 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 return 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 let ind = -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 let st = -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 let lim = -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 " Multiline bracketed expressions take precedence
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 let align_brackets = get(g:, "julia_indent_align_brackets", 1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 let align_funcargs = get(g:, "julia_indent_align_funcargs", 0)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 let c = len(getline(lnum)) + 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 while IsInBrackets(lnum, c)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 let [first_open_bracket, last_open_bracket, last_closed_bracket, infuncargs] = GetJuliaNestingBrackets(lnum, c)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 " First scenario: the previous line has a hanging open bracket:
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 " set the indentation to match the opening bracket (plus an extra space)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 " unless we're in a function arguments list or alignment is disabled, in
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 " which case we just add an extra indent
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 if last_open_bracket != -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 if (!infuncargs && align_brackets) || (infuncargs && align_funcargs)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 let st = last_open_bracket
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 let ind = virtcol([lnum, st + 1])
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 let ind = indent(lnum) + shiftwidth()
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 " Second scenario: some multiline bracketed expression was closed in the
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 " previous line. But since we know we are still in a bracketed expression,
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 " we need to find the line where the bracket was opened
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 elseif last_closed_bracket != -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 call JumpToMatch(lnum, last_closed_bracket)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 if line(".") == lnum
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 " something wrong here, give up
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 let ind = indent(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 let lnum = line(".")
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 let c = col(".") - 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 if c == 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 " uhm, give up
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 let ind = 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 " we skipped a bracket set, keep searching for an opening bracket
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 let lim = c
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 continue
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 " Third scenario: nothing special: keep the indentation
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 let ind = indent(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 " Does the current line start with a closing bracket? Then depending on
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 " the situation we align it with the opening one, or we let the rest of
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 " the code figure it out (the case in which we're closing a function
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 " argument list is special-cased)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 if JuliaMatch(v:lnum, getline(v:lnum), '[])}]', indent(v:lnum)) == indent(v:lnum) && ind > 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 if !align_brackets && !align_funcargs
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 call JumpToMatch(v:lnum, indent(v:lnum))
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 return indent(line("."))
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 elseif (align_brackets && getline(v:lnum)[indent(v:lnum)] != ')') || align_funcargs
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 return ind - 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 else " must be a ')' and align_brackets==1 and align_funcargs==0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 call JumpToMatch(v:lnum, indent(v:lnum))
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 if IsFunctionArgPar(line("."), col("."))
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 let ind = -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 return ind - 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 endwhile
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 if ind == -1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 " We are not in a multiline bracketed expression. Thus we look for a
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 " previous line to use as a reference
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 let [lnum,ind] = LastBlockIndent(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 let c = len(getline(lnum)) + 1
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 if IsInBrackets(lnum, c)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 let [first_open_bracket, last_open_bracket, last_closed_bracket, infuncargs] = GetJuliaNestingBrackets(lnum, c)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 let lim = first_open_bracket
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 end
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 " Analyse the reference line
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(lnum, st, lim)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 " Increase indentation for each newly opened block in the reference line
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 let ind += shiftwidth() * num_open_blocks
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 " Analyse the current line
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(v:lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 " Decrease indentation for each closed block in the current line
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 let ind -= shiftwidth() * num_closed_blocks
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 " Additional special case: multiline import/using/export statements
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 let prevline = getline(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 " Are we in a multiline import/using/export statement, right below the
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 " opening line?
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 if IsInContinuationImportLine(v:lnum) && !IsInContinuationImportLine(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 if get(g:, 'julia_indent_align_import', 1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 " if the opening line has a colon followed by non-comments, use it as
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 " reference point
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 let cind = JuliaMatch(lnum, prevline, ':', indent(lnum), lim)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 if cind >= 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 let nonwhiteind = JuliaMatch(lnum, prevline, '\S', cind+1, -1, 'basic')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 if nonwhiteind >= 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 " return match(prevline, '\S', cind+1) " a bit overkill...
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 return cind + 2
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 else
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 " if the opening line is not a naked import/using/export statement, use
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 " it as reference
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 let iind = JuliaMatch(lnum, prevline, '\<import\|using\|export\>', indent(lnum), lim)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 if iind >= 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 " assuming whitespace after using... so no `using(XYZ)` please!
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 let nonwhiteind = JuliaMatch(lnum, prevline, '\S', iind+6, -1, 'basic')
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 if nonwhiteind >= 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 return match(prevline, '\S', iind+6)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 let ind += shiftwidth()
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 " Or did we just close a multiline import/using/export statement?
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 elseif !IsInContinuationImportLine(v:lnum) && IsInContinuationImportLine(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 " find the starting line of the statement
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 let ilnum = 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 for iln in range(lnum-1, 1, -1)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 if !IsInContinuationImportLine(iln)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 let ilnum = iln
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 break
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 endfor
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 if ilnum == 0
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 " something went horribly wrong, give up
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 let ind = indent(lnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 let ind = indent(ilnum)
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 endif
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 return ind
29ec2c198c8d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 endfunction