annotate runtime/indent/erlang.vim @ 27577:40d844af56a5 v8.2.4315

patch 8.2.4315: put in Visual mode not fully tested Commit: https://github.com/vim/vim/commit/6bf821e8abe1da24e5d0624f032d7eda745756e8 Author: zeertzjq <zeertzjq@outlook.com> Date: Mon Feb 7 10:33:20 2022 +0000 patch 8.2.4315: put in Visual mode not fully tested Problem: Put in Visual mode not fully tested. Solution: Add a few more test cases. (closes https://github.com/vim/vim/issues/9708)
author Bram Moolenaar <Bram@vim.org>
date Mon, 07 Feb 2022 11:45:03 +0100
parents 11b656e74444
children f68f43043842
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1 " Vim indent file
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
2 " Language: Erlang (http://www.erlang.org)
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
3 " Author: Csaba Hoch <csaba.hoch@gmail.com>
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
4 " Contributors: Edwin Fine <efine145_nospam01 at usa dot net>
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
5 " Pawel 'kTT' Salata <rockplayer.pl@gmail.com>
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
6 " Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
7 " Last Update: 2020-Jun-11
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
8 " License: Vim license
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
9 " URL: https://github.com/vim-erlang/vim-erlang-runtime
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
10
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
11 " Note About Usage:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
12 " This indentation script works best with the Erlang syntax file created by
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
13 " Kreąimir Marľić (Kresimir Marzic) and maintained by Csaba Hoch.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
14
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
15 " Notes About Implementation:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
16 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
17 " - LTI = Line to indent.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
18 " - The index of the first line is 1, but the index of the first column is 0.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
19
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
20
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
21 " Initialization {{{1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
22 " ==============
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
23
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
24 " Only load this indent file when no other was loaded
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
25 " Vim 7 or later is needed
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
26 if exists("b:did_indent") || version < 700
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
27 finish
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
28 else
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
29 let b:did_indent = 1
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
30 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
31
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
32 setlocal indentexpr=ErlangIndent()
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
33 setlocal indentkeys+=0=end,0=of,0=catch,0=after,0=when,0=),0=],0=},0=>>
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
34
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
35 " Only define the functions once
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
36 if exists("*ErlangIndent")
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
37 finish
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
38 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
39
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
40 let s:cpo_save = &cpo
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
41 set cpo&vim
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
42
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
43 " Logging library {{{1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
44 " ===============
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
45
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
46 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
47 " Logs the given string using the ErlangIndentLog function if it exists.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
48 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
49 " s: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
50 function! s:Log(s)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
51 if exists("*ErlangIndentLog")
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
52 call ErlangIndentLog(a:s)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
53 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
54 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
55
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
56 " Line tokenizer library {{{1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
57 " ======================
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
58
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
59 " Indtokens are "indentation tokens". See their exact format in the
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 22328
diff changeset
60 " documentation of the s:GetTokensFromLine function.
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
61
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
62 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
63 " Calculate the new virtual column after the given segment of a line.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
64 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
65 " line: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
66 " first_index: integer -- the index of the first character of the segment
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
67 " last_index: integer -- the index of the last character of the segment
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
68 " vcol: integer -- the virtual column of the first character of the token
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
69 " tabstop: integer -- the value of the 'tabstop' option to be used
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
70 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
71 " vcol: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
72 " Example:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
73 " " index: 0 12 34567
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
74 " " vcol: 0 45 89
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
75 " s:CalcVCol("\t'\tx', b", 1, 4, 4) -> 10
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
76 function! s:CalcVCol(line, first_index, last_index, vcol, tabstop)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
77
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 22328
diff changeset
78 " We copy the relevant segment of the line, otherwise if the line were
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
79 " e.g. `"\t", term` then the else branch below would consume the `", term`
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
80 " part at once.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
81 let line = a:line[a:first_index : a:last_index]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
82
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
83 let i = 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
84 let last_index = a:last_index - a:first_index
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
85 let vcol = a:vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
86
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
87 while 0 <= i && i <= last_index
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
88
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
89 if line[i] ==# "\t"
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
90 " Example (when tabstop == 4):
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
91 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
92 " vcol + tab -> next_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
93 " 0 + tab -> 4
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
94 " 1 + tab -> 4
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
95 " 2 + tab -> 4
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
96 " 3 + tab -> 4
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
97 " 4 + tab -> 8
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
98 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
99 " next_i - i == the number of tabs
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
100 let next_i = matchend(line, '\t*', i + 1)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
101 let vcol = (vcol / a:tabstop + (next_i - i)) * a:tabstop
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
102 call s:Log('new vcol after tab: '. vcol)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
103 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
104 let next_i = matchend(line, '[^\t]*', i + 1)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
105 let vcol += next_i - i
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
106 call s:Log('new vcol after other: '. vcol)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
107 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
108 let i = next_i
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
109 endwhile
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
110
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
111 return vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
112 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
113
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
114 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
115 " Go through the whole line and return the tokens in the line.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
116 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
117 " line: string -- the line to be examined
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
118 " string_continuation: bool
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
119 " atom_continuation: bool
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
120 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
121 " indtokens = [indtoken]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
122 " indtoken = [token, vcol, col]
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
123 " token = string (examples: 'begin', '<quoted_atom>', '}')
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
124 " vcol = integer (the virtual column of the first character of the token;
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
125 " counting starts from 0)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
126 " col = integer (counting starts from 0)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
127 function! s:GetTokensFromLine(line, string_continuation, atom_continuation,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
128 \tabstop)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
129
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
130 let linelen = strlen(a:line) " The length of the line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
131 let i = 0 " The index of the current character in the line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
132 let vcol = 0 " The virtual column of the current character
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
133 let indtokens = []
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
134
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
135 if a:string_continuation
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
136 let i = matchend(a:line, '^\%([^"\\]\|\\.\)*"', 0)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
137 if i ==# -1
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
138 call s:Log(' Whole line is string continuation -> ignore')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
139 return []
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
140 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
141 let vcol = s:CalcVCol(a:line, 0, i - 1, 0, a:tabstop)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
142 call add(indtokens, ['<string_end>', vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
143 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
144 elseif a:atom_continuation
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
145 let i = matchend(a:line, "^\\%([^'\\\\]\\|\\\\.\\)*'", 0)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
146 if i ==# -1
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
147 call s:Log(' Whole line is quoted atom continuation -> ignore')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
148 return []
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
149 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
150 let vcol = s:CalcVCol(a:line, 0, i - 1, 0, a:tabstop)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
151 call add(indtokens, ['<quoted_atom_end>', vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
152 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
153 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
154
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
155 while 0 <= i && i < linelen
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
156
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
157 let next_vcol = ''
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
158
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
159 " Spaces
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
160 if a:line[i] ==# ' '
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
161 let next_i = matchend(a:line, ' *', i + 1)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
162
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
163 " Tabs
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
164 elseif a:line[i] ==# "\t"
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
165 let next_i = matchend(a:line, '\t*', i + 1)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
166
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
167 " See example in s:CalcVCol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
168 let next_vcol = (vcol / a:tabstop + (next_i - i)) * a:tabstop
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
169
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
170 " Comment
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
171 elseif a:line[i] ==# '%'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
172 let next_i = linelen
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
173
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
174 " String token: "..."
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
175 elseif a:line[i] ==# '"'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
176 let next_i = matchend(a:line, '\%([^"\\]\|\\.\)*"', i + 1)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
177 if next_i ==# -1
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
178 call add(indtokens, ['<string_start>', vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
179 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
180 let next_vcol = s:CalcVCol(a:line, i, next_i - 1, vcol, a:tabstop)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
181 call add(indtokens, ['<string>', vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
182 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
183
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
184 " Quoted atom token: '...'
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
185 elseif a:line[i] ==# "'"
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
186 let next_i = matchend(a:line, "\\%([^'\\\\]\\|\\\\.\\)*'", i + 1)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
187 if next_i ==# -1
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
188 call add(indtokens, ['<quoted_atom_start>', vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
189 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
190 let next_vcol = s:CalcVCol(a:line, i, next_i - 1, vcol, a:tabstop)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
191 call add(indtokens, ['<quoted_atom>', vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
192 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
193
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
194 " Keyword or atom or variable token or number
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
195 elseif a:line[i] =~# '[a-zA-Z_@0-9]'
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
196 let next_i = matchend(a:line,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
197 \'[[:alnum:]_@:]*\%(\s*#\s*[[:alnum:]_@:]*\)\=',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
198 \i + 1)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
199 call add(indtokens, [a:line[(i):(next_i - 1)], vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
200
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
201 " Character token: $<char> (as in: $a)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
202 elseif a:line[i] ==# '$'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
203 call add(indtokens, ['$.', vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
204 let next_i = i + 2
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
205
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
206 " Dot token: .
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
207 elseif a:line[i] ==# '.'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
208
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
209 let next_i = i + 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
210
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
211 if i + 1 ==# linelen || a:line[i + 1] =~# '[[:blank:]%]'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
212 " End of clause token: . (as in: f() -> ok.)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
213 call add(indtokens, ['<end_of_clause>', vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
214
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
215 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
216 " Possibilities:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
217 " - Dot token in float: . (as in: 3.14)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
218 " - Dot token in record: . (as in: #myrec.myfield)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
219 call add(indtokens, ['.', vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
220 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
221
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
222 " Equal sign
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
223 elseif a:line[i] ==# '='
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
224 " This is handled separately so that "=<<" will be parsed as
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
225 " ['=', '<<'] instead of ['=<', '<']. Although Erlang parses it
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
226 " currently in the latter way, that may be fixed some day.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
227 call add(indtokens, [a:line[i], vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
228 let next_i = i + 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
229
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
230 " Three-character tokens
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
231 elseif i + 1 < linelen &&
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
232 \ index(['=:=', '=/='], a:line[i : i + 1]) != -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
233 call add(indtokens, [a:line[i : i + 1], vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
234 let next_i = i + 2
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
235
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
236 " Two-character tokens
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
237 elseif i + 1 < linelen &&
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
238 \ index(['->', '<<', '>>', '||', '==', '/=', '=<', '>=', '++', '--',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
239 \ '::'],
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
240 \ a:line[i : i + 1]) != -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
241 call add(indtokens, [a:line[i : i + 1], vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
242 let next_i = i + 2
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
243
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
244 " Other character: , ; < > ( ) [ ] { } # + - * / : ? = ! |
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
245 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
246 call add(indtokens, [a:line[i], vcol, i])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
247 let next_i = i + 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
248
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
249 endif
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
250
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
251 if next_vcol ==# ''
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
252 let vcol += next_i - i
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
253 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
254 let vcol = next_vcol
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
255 endif
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
256
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
257 let i = next_i
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
258
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
259 endwhile
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
260
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
261 return indtokens
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
262
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
263 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
264
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
265 " TODO: doc, handle "not found" case
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
266 function! s:GetIndtokenAtCol(indtokens, col)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
267 let i = 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
268 while i < len(a:indtokens)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
269 if a:indtokens[i][2] ==# a:col
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
270 return [1, i]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
271 elseif a:indtokens[i][2] > a:col
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
272 return [0, s:IndentError('No token at col ' . a:col . ', ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
273 \'indtokens = ' . string(a:indtokens),
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
274 \'', '')]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
275 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
276 let i += 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
277 endwhile
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
278 return [0, s:IndentError('No token at col ' . a:col . ', ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
279 \'indtokens = ' . string(a:indtokens),
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
280 \'', '')]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
281 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
282
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
283 " Stack library {{{1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
284 " =============
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
285
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
286 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
287 " Push a token onto the parser's stack.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
288 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
289 " stack: [token]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
290 " token: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
291 function! s:Push(stack, token)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
292 call s:Log(' Stack Push: "' . a:token . '" into ' . string(a:stack))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
293 call insert(a:stack, a:token)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
294 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
295
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
296 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
297 " Pop a token from the parser's stack.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
298 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
299 " stack: [token]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
300 " token: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
301 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
302 " token: string -- the removed element
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
303 function! s:Pop(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
304 let head = remove(a:stack, 0)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
305 call s:Log(' Stack Pop: "' . head . '" from ' . string(a:stack))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
306 return head
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
307 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
308
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
309 " Library for accessing and storing tokenized lines {{{1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
310 " =================================================
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
311
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
312 " The Erlang token cache: an `lnum -> indtokens` dictionary that stores the
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
313 " tokenized lines.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
314 let s:all_tokens = {}
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
315 let s:file_name = ''
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
316 let s:last_changedtick = -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
317
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
318 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
319 " Clear the Erlang token cache if we have a different file or the file has
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
320 " been changed since the last indentation.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
321 function! s:ClearTokenCacheIfNeeded()
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
322 let file_name = expand('%:p')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
323 if file_name != s:file_name ||
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
324 \ b:changedtick != s:last_changedtick
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
325 let s:file_name = file_name
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
326 let s:last_changedtick = b:changedtick
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
327 let s:all_tokens = {}
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
328 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
329 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
330
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
331 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
332 " Return the tokens of line `lnum`, if that line is not empty. If it is
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
333 " empty, find the first non-empty line in the given `direction` and return
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
334 " the tokens of that line.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
335 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
336 " lnum: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
337 " direction: 'up' | 'down'
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
338 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
339 " result: [] -- the result is an empty list if we hit the beginning or end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
340 " of the file
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
341 " | [lnum, indtokens]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
342 " lnum: integer -- the index of the non-empty line that was found and
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
343 " tokenized
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
344 " indtokens: [indtoken] -- the tokens of line `lnum`
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
345 function! s:TokenizeLine(lnum, direction)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
346
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
347 call s:Log('Tokenizing starts from line ' . a:lnum)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
348 if a:direction ==# 'up'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
349 let lnum = prevnonblank(a:lnum)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
350 else " a:direction ==# 'down'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
351 let lnum = nextnonblank(a:lnum)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
352 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
353
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
354 " We hit the beginning or end of the file
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
355 if lnum ==# 0
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
356 let indtokens = []
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
357 call s:Log(' We hit the beginning or end of the file.')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
358
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
359 " The line has already been parsed
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
360 elseif has_key(s:all_tokens, lnum)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
361 let indtokens = s:all_tokens[lnum]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
362 call s:Log('Cached line ' . lnum . ': ' . getline(lnum))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
363 call s:Log(" Tokens in the line:\n - " . join(indtokens, "\n - "))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
364
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
365 " The line should be parsed now
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
366 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
367
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
368 " Parse the line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
369 let line = getline(lnum)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
370 let string_continuation = s:IsLineStringContinuation(lnum)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
371 let atom_continuation = s:IsLineAtomContinuation(lnum)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
372 let indtokens = s:GetTokensFromLine(line, string_continuation,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
373 \atom_continuation, &tabstop)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
374 let s:all_tokens[lnum] = indtokens
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
375 call s:Log('Tokenizing line ' . lnum . ': ' . line)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
376 call s:Log(" Tokens in the line:\n - " . join(indtokens, "\n - "))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
377
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
378 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
379
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
380 return [lnum, indtokens]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
381 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
382
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
383 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
384 " As a helper function for PrevIndToken and NextIndToken, the FindIndToken
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
385 " function finds the first line with at least one token in the given
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
386 " direction.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
387 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
388 " lnum: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
389 " direction: 'up' | 'down'
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
390 " Returns:
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
391 " result: [[], 0, 0]
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
392 " -- the result is an empty list if we hit the beginning or end of
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
393 " the file
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
394 " | [indtoken, lnum, i]
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
395 " -- the content, lnum and token index of the next (or previous)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
396 " indtoken
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
397 function! s:FindIndToken(lnum, dir)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
398 let lnum = a:lnum
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
399 while 1
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
400 let lnum += (a:dir ==# 'up' ? -1 : 1)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
401 let [lnum, indtokens] = s:TokenizeLine(lnum, a:dir)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
402 if lnum ==# 0
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
403 " We hit the beginning or end of the file
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
404 return [[], 0, 0]
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
405 elseif !empty(indtokens)
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
406 " We found a non-empty line. If we were moving up, we return the last
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
407 " token of this line. Otherwise we return the first token if this line.
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
408 let i = (a:dir ==# 'up' ? len(indtokens) - 1 : 0)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
409 return [indtokens[i], lnum, i]
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
410 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
411 endwhile
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
412 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
413
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
414 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
415 " Find the token that directly precedes the given token.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
416 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
417 " lnum: integer -- the line of the given token
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
418 " i: the index of the given token within line `lnum`
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
419 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
420 " result = [] -- the result is an empty list if the given token is the first
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
421 " token of the file
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
422 " | indtoken
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
423 function! s:PrevIndToken(lnum, i)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
424 call s:Log(' PrevIndToken called: lnum=' . a:lnum . ', i =' . a:i)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
425
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
426 " If the current line has a previous token, return that
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
427 if a:i > 0
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
428 return [s:all_tokens[a:lnum][a:i - 1], a:lnum, a:i - 1]
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
429 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
430 return s:FindIndToken(a:lnum, 'up')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
431 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
432 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
433
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
434 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
435 " Find the token that directly succeeds the given token.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
436 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
437 " lnum: integer -- the line of the given token
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
438 " i: the index of the given token within line `lnum`
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
439 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
440 " result = [] -- the result is an empty list if the given token is the last
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
441 " token of the file
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
442 " | indtoken
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
443 function! s:NextIndToken(lnum, i)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
444 call s:Log(' NextIndToken called: lnum=' . a:lnum . ', i =' . a:i)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
445
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
446 " If the current line has a next token, return that
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
447 if len(s:all_tokens[a:lnum]) > a:i + 1
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
448 return [s:all_tokens[a:lnum][a:i + 1], a:lnum, a:i + 1]
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
449 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
450 return s:FindIndToken(a:lnum, 'down')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
451 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
452 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
453
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
454 " ErlangCalcIndent helper functions {{{1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
455 " =================================
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
456
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
457 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
458 " This function is called when the parser encounters a syntax error.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
459 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
460 " If we encounter a syntax error, we return
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
461 " g:erlang_unexpected_token_indent, which is -1 by default. This means that
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
462 " the indentation of the LTI will not be changed.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
463 " Parameter:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
464 " msg: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
465 " token: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
466 " stack: [token]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
467 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
468 " indent: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
469 function! s:IndentError(msg, token, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
470 call s:Log('Indent error: ' . a:msg . ' -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
471 call s:Log(' Token = ' . a:token . ', ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
472 \' stack = ' . string(a:stack))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
473 return g:erlang_unexpected_token_indent
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
474 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
475
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
476 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
477 " This function is called when the parser encounters an unexpected token,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
478 " and the parser will return the number given back by UnexpectedToken.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
479 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
480 " If we encounter an unexpected token, we return
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
481 " g:erlang_unexpected_token_indent, which is -1 by default. This means that
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
482 " the indentation of the LTI will not be changed.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
483 " Parameter:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
484 " token: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
485 " stack: [token]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
486 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
487 " indent: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
488 function! s:UnexpectedToken(token, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
489 call s:Log(' Unexpected token ' . a:token . ', stack = ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
490 \string(a:stack) . ' -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
491 return g:erlang_unexpected_token_indent
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
492 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
493
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
494 if !exists('g:erlang_unexpected_token_indent')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
495 let g:erlang_unexpected_token_indent = -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
496 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
497
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
498 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
499 " Return whether the given line starts with a string continuation.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
500 " Parameter:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
501 " lnum: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
502 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
503 " result: bool
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
504 " Example:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
505 " f() -> % IsLineStringContinuation = false
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
506 " "This is a % IsLineStringContinuation = false
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
507 " multiline % IsLineStringContinuation = true
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
508 " string". % IsLineStringContinuation = true
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
509 function! s:IsLineStringContinuation(lnum)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
510 if has('syntax_items')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
511 return synIDattr(synID(a:lnum, 1, 0), 'name') =~# '^erlangString'
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
512 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
513 return 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
514 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
515 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
516
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
517 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
518 " Return whether the given line starts with an atom continuation.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
519 " Parameter:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
520 " lnum: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
521 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
522 " result: bool
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
523 " Example:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
524 " 'function with % IsLineAtomContinuation = true, but should be false
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
525 " weird name'() -> % IsLineAtomContinuation = true
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
526 " ok. % IsLineAtomContinuation = false
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
527 function! s:IsLineAtomContinuation(lnum)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
528 if has('syntax_items')
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
529 let syn_name = synIDattr(synID(a:lnum, 1, 0), 'name')
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
530 return syn_name =~# '^erlangQuotedAtom' ||
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
531 \ syn_name =~# '^erlangQuotedRecord'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
532 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
533 return 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
534 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
535 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
536
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
537 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
538 " Return whether the 'catch' token (which should be the `i`th token in line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
539 " `lnum`) is standalone or part of a try-catch block, based on the preceding
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
540 " token.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
541 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
542 " lnum: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
543 " i: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
544 " Return:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
545 " is_standalone: bool
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
546 function! s:IsCatchStandalone(lnum, i)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
547 call s:Log(' IsCatchStandalone called: lnum=' . a:lnum . ', i=' . a:i)
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
548 let [prev_indtoken, _, _] = s:PrevIndToken(a:lnum, a:i)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
549
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
550 " If we hit the beginning of the file, it is not a catch in a try block
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
551 if prev_indtoken == []
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
552 return 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
553 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
554
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
555 let prev_token = prev_indtoken[0]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
556
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
557 if prev_token =~# '^[A-Z_@0-9]'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
558 let is_standalone = 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
559 elseif prev_token =~# '[a-z]'
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
560 if index(['after', 'and', 'andalso', 'band', 'begin', 'bnot', 'bor', 'bsl',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
561 \ 'bsr', 'bxor', 'case', 'catch', 'div', 'not', 'or', 'orelse',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
562 \ 'rem', 'try', 'xor'], prev_token) != -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
563 " If catch is after these keywords, it is standalone
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
564 let is_standalone = 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
565 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
566 " If catch is after another keyword (e.g. 'end') or an atom, it is
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
567 " part of try-catch.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
568 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
569 " Keywords:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
570 " - may precede 'catch': end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
571 " - may not precede 'catch': fun if of receive when
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
572 " - unused: cond let query
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
573 let is_standalone = 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
574 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
575 elseif index([')', ']', '}', '<string>', '<string_end>', '<quoted_atom>',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
576 \ '<quoted_atom_end>', '$.'], prev_token) != -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
577 let is_standalone = 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
578 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
579 " This 'else' branch includes the following tokens:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
580 " -> == /= =< < >= > =:= =/= + - * / ++ -- :: < > ; ( [ { ? = ! . |
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
581 let is_standalone = 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
582 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
583
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
584 call s:Log(' "catch" preceded by "' . prev_token . '" -> catch ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
585 \(is_standalone ? 'is standalone' : 'belongs to try-catch'))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
586 return is_standalone
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
587
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
588 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
589
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
590 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
591 " This function is called when a begin-type element ('begin', 'case',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
592 " '[', '<<', etc.) is found. It asks the caller to return if the stack
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
593 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
594 " stack: [token]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
595 " token: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
596 " curr_vcol: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
597 " stored_vcol: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
598 " sw: integer -- number of spaces to be used after the begin element as
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
599 " indentation
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
600 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
601 " result: [should_return, indent]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
602 " should_return: bool -- if true, the caller should return `indent` to Vim
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
603 " indent -- integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
604 function! s:BeginElementFoundIfEmpty(stack, token, curr_vcol, stored_vcol, sw)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
605 if empty(a:stack)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
606 if a:stored_vcol ==# -1
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 22328
diff changeset
607 call s:Log(' "' . a:token . '" directly precedes LTI -> return')
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
608 return [1, a:curr_vcol + a:sw]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
609 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
610 call s:Log(' "' . a:token .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
611 \'" token (whose expression includes LTI) found -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
612 return [1, a:stored_vcol]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
613 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
614 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
615 return [0, 0]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
616 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
617 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
618
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
619 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
620 " This function is called when a begin-type element ('begin', 'case', '[',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
621 " '<<', etc.) is found, and in some cases when 'after' and 'when' is found.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
622 " It asks the caller to return if the stack is already empty.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
623 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
624 " stack: [token]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
625 " token: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
626 " curr_vcol: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
627 " stored_vcol: integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
628 " end_token: end token that belongs to the begin element found (e.g. if the
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
629 " begin element is 'begin', the end token is 'end')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
630 " sw: integer -- number of spaces to be used after the begin element as
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
631 " indentation
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
632 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
633 " result: [should_return, indent]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
634 " should_return: bool -- if true, the caller should return `indent` to Vim
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
635 " indent -- integer
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
636 function! s:BeginElementFound(stack, token, curr_vcol, stored_vcol, end_token, sw)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
637
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
638 " Return 'return' if the stack is empty
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
639 let [ret, res] = s:BeginElementFoundIfEmpty(a:stack, a:token, a:curr_vcol,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
640 \a:stored_vcol, a:sw)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
641 if ret | return [ret, res] | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
642
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
643 if a:stack[0] ==# a:end_token
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
644 call s:Log(' "' . a:token . '" pops "' . a:end_token . '"')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
645 call s:Pop(a:stack)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
646 if !empty(a:stack) && a:stack[0] ==# 'align_to_begin_element'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
647 call s:Pop(a:stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
648 if empty(a:stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
649 return [1, a:curr_vcol]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
650 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
651 return [1, s:UnexpectedToken(a:token, a:stack)]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
652 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
653 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
654 return [0, 0]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
655 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
656 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
657 return [1, s:UnexpectedToken(a:token, a:stack)]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
658 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
659 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
660
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
661 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
662 " This function is called when we hit the beginning of a file or an
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
663 " end-of-clause token -- i.e. when we found the beginning of the current
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
664 " clause.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
665 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
666 " If the stack contains an '->' or 'when', this means that we can return
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
667 " now, since we were looking for the beginning of the clause.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
668 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
669 " stack: [token]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
670 " token: string
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
671 " stored_vcol: integer
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
672 " lnum: the line number of the "end of clause" mark (or 0 if we hit the
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
673 " beginning of the file)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
674 " i: the index of the "end of clause" token within its own line
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
675 " Returns:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
676 " result: [should_return, indent]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
677 " should_return: bool -- if true, the caller should return `indent` to Vim
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
678 " indent -- integer
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
679 function! s:BeginningOfClauseFound(stack, token, stored_vcol, lnum, i)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
680 if !empty(a:stack) && a:stack[0] ==# 'when'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
681 call s:Log(' BeginningOfClauseFound: "when" found in stack')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
682 call s:Pop(a:stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
683 if empty(a:stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
684 call s:Log(' Stack is ["when"], so LTI is in a guard -> return')
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
685 return [1, a:stored_vcol + shiftwidth() + 2]
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
686 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
687 return [1, s:UnexpectedToken(a:token, a:stack)]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
688 endif
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
689 elseif !empty(a:stack) && a:stack[0] ==# '->'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
690 call s:Log(' BeginningOfClauseFound: "->" found in stack')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
691 call s:Pop(a:stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
692 if empty(a:stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
693 call s:Log(' Stack is ["->"], so LTI is in function body -> return')
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
694 return [1, a:stored_vcol + shiftwidth()]
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
695 elseif a:stack[0] ==# ';'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
696 call s:Pop(a:stack)
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
697
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
698 if !empty(a:stack)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
699 return [1, s:UnexpectedToken(a:token, a:stack)]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
700 endif
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
701
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
702 if a:lnum ==# 0
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
703 " Set lnum and i to be NextIndToken-friendly
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
704 let lnum = 1
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
705 let i = -1
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
706 else
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
707 let lnum = a:lnum
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
708 let i = a:i
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
709 endif
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
710
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
711 " Are we after a "-spec func() ...;" clause?
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
712 let [next1_indtoken, next1_lnum, next1_i] = s:NextIndToken(lnum, i)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
713 if !empty(next1_indtoken) && next1_indtoken[0] =~# '-'
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
714 let [next2_indtoken, next2_lnum, next2_i] =
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
715 \s:NextIndToken(next1_lnum, next1_i)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
716 if !empty(next2_indtoken) && next2_indtoken[0] =~# 'spec'
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
717 let [next3_indtoken, next3_lnum, next3_i] =
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
718 \s:NextIndToken(next2_lnum, next2_i)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
719 if !empty(next3_indtoken)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
720 let [next4_indtoken, next4_lnum, next4_i] =
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
721 \s:NextIndToken(next3_lnum, next3_i)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
722 if !empty(next4_indtoken)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
723 " Yes, we are.
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
724 call s:Log(' Stack is ["->", ";"], so LTI is in a "-spec" ' .
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
725 \'attribute -> return')
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
726 return [1, next4_indtoken[1]]
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
727 endif
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
728 endif
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
729 endif
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
730 endif
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
731
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
732 call s:Log(' Stack is ["->", ";"], so LTI is in a function head ' .
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
733 \'-> return')
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
734 return [1, a:stored_vcol]
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
735
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
736 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
737 return [1, s:UnexpectedToken(a:token, a:stack)]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
738 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
739 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
740 return [0, 0]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
741 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
742 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
743
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
744 let g:erlang_indent_searchpair_timeout = 2000
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
745
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
746 " TODO
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
747 function! s:SearchPair(lnum, curr_col, start, middle, end)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
748 call cursor(a:lnum, a:curr_col + 1)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
749 let [lnum_new, col1_new] =
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
750 \searchpairpos(a:start, a:middle, a:end, 'bW',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
751 \'synIDattr(synID(line("."), col("."), 0), "name") ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
752 \'=~? "string\\|quotedatom\\|todo\\|comment\\|' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
753 \'erlangmodifier"',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
754 \0, g:erlang_indent_searchpair_timeout)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
755 return [lnum_new, col1_new - 1]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
756 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
757
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
758 function! s:SearchEndPair(lnum, curr_col)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
759 return s:SearchPair(
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
760 \ a:lnum, a:curr_col,
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
761 \ '\C\<\%(case\|try\|begin\|receive\|if\)\>\|' .
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
762 \ '\<fun\>\%(\s\|\n\|%.*$\|[A-Z_@][a-zA-Z_@]*\)*(',
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
763 \ '',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
764 \ '\<end\>')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
765 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
766
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
767 " ErlangCalcIndent {{{1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
768 " ================
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
769
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
770 " Purpose:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
771 " Calculate the indentation of the given line.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
772 " Parameters:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
773 " lnum: integer -- index of the line for which the indentation should be
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
774 " calculated
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
775 " stack: [token] -- initial stack
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
776 " Return:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
777 " indent: integer -- if -1, that means "don't change the indentation";
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
778 " otherwise it means "indent the line with `indent`
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
779 " number of spaces or equivalent tabs"
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
780 function! s:ErlangCalcIndent(lnum, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
781 let res = s:ErlangCalcIndent2(a:lnum, a:stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
782 call s:Log("ErlangCalcIndent returned: " . res)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
783 return res
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
784 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
785
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
786 function! s:ErlangCalcIndent2(lnum, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
787
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
788 let lnum = a:lnum
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
789 let stored_vcol = -1 " Virtual column of the first character of the token that
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
790 " we currently think we might align to.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
791 let mode = 'normal'
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
792 let stack = a:stack
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
793 let semicolon_abscol = ''
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
794
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
795 " Walk through the lines of the buffer backwards (starting from the
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
796 " previous line) until we can decide how to indent the current line.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
797 while 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
798
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
799 let [lnum, indtokens] = s:TokenizeLine(lnum, 'up')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
800
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
801 " Hit the start of the file
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
802 if lnum ==# 0
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
803 let [ret, res] = s:BeginningOfClauseFound(stack, 'beginning_of_file',
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
804 \stored_vcol, 0, 0)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
805 if ret | return res | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
806
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
807 return 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
808 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
809
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
810 let i = len(indtokens) - 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
811 let last_token_of_line = 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
812
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
813 while i >= 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
814
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
815 let [token, curr_vcol, curr_col] = indtokens[i]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
816 call s:Log(' Analyzing the following token: ' . string(indtokens[i]))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
817
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
818 if len(stack) > 256 " TODO: magic number
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
819 return s:IndentError('Stack too long', token, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
820 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
821
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
822 if token ==# '<end_of_clause>'
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
823 let [ret, res] = s:BeginningOfClauseFound(stack, token, stored_vcol,
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
824 \lnum, i)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
825 if ret | return res | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
826
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
827 if stored_vcol ==# -1
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 22328
diff changeset
828 call s:Log(' End of clause directly precedes LTI -> return')
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
829 return 0
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
830 else
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
831 call s:Log(' End of clause (but not end of line) -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
832 return stored_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
833 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
834
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
835 elseif stack == ['prev_term_plus']
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
836 if token =~# '[a-zA-Z_@#]' ||
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
837 \ token ==# '<string>' || token ==# '<string_start>' ||
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
838 \ token ==# '<quoted_atom>' || token ==# '<quoted_atom_start>'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
839 call s:Log(' previous token found: curr_vcol + plus = ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
840 \curr_vcol . " + " . plus)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
841 return curr_vcol + plus
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
842 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
843
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
844 elseif token ==# 'begin'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
845 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
846 \stored_vcol, 'end', shiftwidth())
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
847 if ret | return res | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
848
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
849 " case EXPR of BRANCHES end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
850 " try EXPR catch BRANCHES end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
851 " try EXPR after BODY end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
852 " try EXPR catch BRANCHES after BODY end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
853 " try EXPR of BRANCHES catch BRANCHES end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
854 " try EXPR of BRANCHES after BODY end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
855 " try EXPR of BRANCHES catch BRANCHES after BODY end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
856 " receive BRANCHES end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
857 " receive BRANCHES after BRANCHES end
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
858
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
859 " This branch is not Emacs-compatible
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
860 elseif (index(['of', 'receive', 'after', 'if'], token) != -1 ||
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
861 \ (token ==# 'catch' && !s:IsCatchStandalone(lnum, i))) &&
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
862 \ !last_token_of_line &&
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
863 \ (empty(stack) || stack ==# ['when'] || stack ==# ['->'] ||
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
864 \ stack ==# ['->', ';'])
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
865
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
866 " If we are after of/receive, but these are not the last
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
867 " tokens of the line, we want to indent like this:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
868 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
869 " % stack == []
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
870 " receive stored_vcol,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
871 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
872 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
873 " % stack == ['->', ';']
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
874 " receive stored_vcol ->
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
875 " B;
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
876 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
877 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
878 " % stack == ['->']
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
879 " receive stored_vcol ->
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
880 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
881 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
882 " % stack == ['when']
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
883 " receive stored_vcol when
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
884 " LTI
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
885
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
886 " stack = [] => LTI is a condition
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
887 " stack = ['->'] => LTI is a branch
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
888 " stack = ['->', ';'] => LTI is a condition
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
889 " stack = ['when'] => LTI is a guard
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
890 if empty(stack) || stack == ['->', ';']
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
891 call s:Log(' LTI is in a condition after ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
892 \'"of/receive/after/if/catch" -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
893 return stored_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
894 elseif stack == ['->']
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
895 call s:Log(' LTI is in a branch after ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
896 \'"of/receive/after/if/catch" -> return')
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
897 return stored_vcol + shiftwidth()
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
898 elseif stack == ['when']
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
899 call s:Log(' LTI is in a guard after ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
900 \'"of/receive/after/if/catch" -> return')
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
901 return stored_vcol + shiftwidth()
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
902 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
903 return s:UnexpectedToken(token, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
904 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
905
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
906 elseif index(['case', 'if', 'try', 'receive'], token) != -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
907
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
908 " stack = [] => LTI is a condition
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
909 " stack = ['->'] => LTI is a branch
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
910 " stack = ['->', ';'] => LTI is a condition
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
911 " stack = ['when'] => LTI is in a guard
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
912 if empty(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
913 " pass
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
914 elseif (token ==# 'case' && stack[0] ==# 'of') ||
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
915 \ (token ==# 'if') ||
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
916 \ (token ==# 'try' && (stack[0] ==# 'of' ||
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
917 \ stack[0] ==# 'catch' ||
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
918 \ stack[0] ==# 'after')) ||
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
919 \ (token ==# 'receive')
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
920
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
921 " From the indentation point of view, the keyword
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
922 " (of/catch/after/end) before the LTI is what counts, so
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
923 " when we reached these tokens, and the stack already had
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
924 " a catch/after/end, we didn't modify it.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
925 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
926 " This way when we reach case/try/receive (i.e. now),
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
927 " there is at most one of/catch/after/end token in the
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
928 " stack.
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
929 if token ==# 'case' || token ==# 'try' ||
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
930 \ (token ==# 'receive' && stack[0] ==# 'after')
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
931 call s:Pop(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
932 endif
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
933
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
934 if empty(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
935 call s:Log(' LTI is in a condition; matching ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
936 \'"case/if/try/receive" found')
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
937 let stored_vcol = curr_vcol + shiftwidth()
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
938 elseif stack[0] ==# 'align_to_begin_element'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
939 call s:Pop(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
940 let stored_vcol = curr_vcol
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
941 elseif len(stack) > 1 && stack[0] ==# '->' && stack[1] ==# ';'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
942 call s:Log(' LTI is in a condition; matching ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
943 \'"case/if/try/receive" found')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
944 call s:Pop(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
945 call s:Pop(stack)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
946 let stored_vcol = curr_vcol + shiftwidth()
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
947 elseif stack[0] ==# '->'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
948 call s:Log(' LTI is in a branch; matching ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
949 \'"case/if/try/receive" found')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
950 call s:Pop(stack)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
951 let stored_vcol = curr_vcol + 2 * shiftwidth()
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
952 elseif stack[0] ==# 'when'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
953 call s:Log(' LTI is in a guard; matching ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
954 \'"case/if/try/receive" found')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
955 call s:Pop(stack)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
956 let stored_vcol = curr_vcol + 2 * shiftwidth() + 2
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
957 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
958
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
959 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
960
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
961 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
962 \stored_vcol, 'end', shiftwidth())
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
963 if ret | return res | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
964
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
965 elseif token ==# 'fun'
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
966 let [next_indtoken, next_lnum, next_i] = s:NextIndToken(lnum, i)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
967 call s:Log(' Next indtoken = ' . string(next_indtoken))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
968
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
969 if !empty(next_indtoken) && next_indtoken[0] =~# '^[A-Z_@]'
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
970 " The "fun" is followed by a variable, so we might have a named fun:
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
971 " "fun Fun() -> ok end". Thus we take the next token to decide
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
972 " whether this is a function definition ("fun()") or just a function
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
973 " reference ("fun Mod:Fun").
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
974 let [next_indtoken, _, _] = s:NextIndToken(next_lnum, next_i)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
975 call s:Log(' Next indtoken = ' . string(next_indtoken))
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
976 endif
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
977
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
978 if !empty(next_indtoken) && next_indtoken[0] ==# '('
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
979 " We have an anonymous function definition
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
980 " (e.g. "fun () -> ok end")
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
981
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
982 " stack = [] => LTI is a condition
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
983 " stack = ['->'] => LTI is a branch
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
984 " stack = ['->', ';'] => LTI is a condition
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
985 " stack = ['when'] => LTI is in a guard
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
986 if empty(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
987 call s:Log(' LTI is in a condition; matching "fun" found')
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
988 let stored_vcol = curr_vcol + shiftwidth()
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
989 elseif len(stack) > 1 && stack[0] ==# '->' && stack[1] ==# ';'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
990 call s:Log(' LTI is in a condition; matching "fun" found')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
991 call s:Pop(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
992 call s:Pop(stack)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
993 elseif stack[0] ==# '->'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
994 call s:Log(' LTI is in a branch; matching "fun" found')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
995 call s:Pop(stack)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
996 let stored_vcol = curr_vcol + 2 * shiftwidth()
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
997 elseif stack[0] ==# 'when'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
998 call s:Log(' LTI is in a guard; matching "fun" found')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
999 call s:Pop(stack)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
1000 let stored_vcol = curr_vcol + 2 * shiftwidth() + 2
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1001 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1002
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1003 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
1004 \stored_vcol, 'end', shiftwidth())
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1005 if ret | return res | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1006 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1007 " Pass: we have a function reference (e.g. "fun f/0")
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1008 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1009
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1010 elseif token ==# '['
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1011 " Emacs compatibility
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1012 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1013 \stored_vcol, ']', 1)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1014 if ret | return res | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1015
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1016 elseif token ==# '<<'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1017 " Emacs compatibility
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1018 let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1019 \stored_vcol, '>>', 2)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1020 if ret | return res | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1021
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1022 elseif token ==# '(' || token ==# '{'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1023
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1024 let end_token = (token ==# '(' ? ')' :
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1025 \token ==# '{' ? '}' : 'error')
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1026
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1027 if empty(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1028 " We found the opening paren whose block contains the LTI.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1029 let mode = 'inside'
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1030 elseif stack[0] ==# end_token
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1031 call s:Log(' "' . token . '" pops "' . end_token . '"')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1032 call s:Pop(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1033
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1034 if !empty(stack) && stack[0] ==# 'align_to_begin_element'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1035 " We found the opening paren whose closing paren
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1036 " starts LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1037 let mode = 'align_to_begin_element'
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1038 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1039 " We found the opening pair for a closing paren that
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1040 " was already in the stack.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1041 let mode = 'outside'
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1042 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1043 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1044 return s:UnexpectedToken(token, stack)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1045 endif
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1046
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1047 if mode ==# 'inside' || mode ==# 'align_to_begin_element'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1048
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1049 if last_token_of_line && i != 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1050 " Examples: {{{
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1051 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1052 " mode == 'inside':
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1053 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1054 " my_func(
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1055 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1056 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1057 " [Variable, {
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1058 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1059 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1060 " mode == 'align_to_begin_element':
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1061 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1062 " my_func(
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1063 " Params
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1064 " ) % LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1065 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1066 " [Variable, {
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1067 " Terms
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1068 " } % LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1069 " }}}
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1070 let stack = ['prev_term_plus']
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1071 let plus = (mode ==# 'inside' ? 2 : 1)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1072 call s:Log(' "' . token .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1073 \'" token found at end of line -> find previous token')
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1074 elseif mode ==# 'align_to_begin_element'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1075 " Examples: {{{
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1076 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1077 " mode == 'align_to_begin_element' && !last_token_of_line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1078 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1079 " my_func(stored_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1080 " ) % LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1081 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1082 " [Variable, {stored_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1083 " } % LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1084 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1085 " mode == 'align_to_begin_element' && i == 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1086 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1087 " (
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1088 " stored_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1089 " ) % LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1090 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1091 " {
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1092 " stored_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1093 " } % LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1094 " }}}
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1095 call s:Log(' "' . token . '" token (whose closing token ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1096 \'starts LTI) found -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1097 return curr_vcol
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1098 elseif stored_vcol ==# -1
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1099 " Examples: {{{
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1100 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1101 " mode == 'inside' && stored_vcol == -1 && !last_token_of_line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1102 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1103 " my_func(
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1104 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1105 " [Variable, {
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1106 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1107 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1108 " mode == 'inside' && stored_vcol == -1 && i == 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1109 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1110 " (
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1111 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1112 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1113 " {
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1114 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1115 " }}}
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1116 call s:Log(' "' . token .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1117 \'" token (which directly precedes LTI) found -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1118 return curr_vcol + 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1119 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1120 " Examples: {{{
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1121 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1122 " mode == 'inside' && stored_vcol != -1 && !last_token_of_line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1123 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1124 " my_func(stored_vcol,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1125 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1126 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1127 " [Variable, {stored_vcol,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1128 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1129 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1130 " mode == 'inside' && stored_vcol != -1 && i == 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1131 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1132 " (stored_vcol,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1133 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1134 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1135 " {stored_vcol,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1136 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1137 " }}}
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1138 call s:Log(' "' . token .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1139 \'" token (whose block contains LTI) found -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1140 return stored_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1141 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1142 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1143
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1144 elseif index(['end', ')', ']', '}', '>>'], token) != -1
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1145
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1146 " If we can be sure that there is synchronization in the Erlang
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1147 " syntax, we use searchpair to make the script quicker. Otherwise we
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1148 " just push the token onto the stack and keep parsing.
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1149
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1150 " No synchronization -> no searchpair optimization
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1151 if !exists('b:erlang_syntax_synced')
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1152 call s:Push(stack, token)
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1153
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1154 " We don't have searchpair optimization for '>>'
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1155 elseif token ==# '>>'
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1156 call s:Push(stack, token)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1157
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1158 elseif token ==# 'end'
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1159 let [lnum_new, col_new] = s:SearchEndPair(lnum, curr_col)
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1160
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1161 if lnum_new ==# 0
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1162 return s:IndentError('Matching token for "end" not found',
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1163 \token, stack)
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1164 else
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1165 if lnum_new != lnum
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1166 call s:Log(' Tokenize for "end" <<<<')
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1167 let [lnum, indtokens] = s:TokenizeLine(lnum_new, 'up')
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1168 call s:Log(' >>>> Tokenize for "end"')
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1169 endif
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1170
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1171 let [success, i] = s:GetIndtokenAtCol(indtokens, col_new)
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1172 if !success | return i | endif
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1173 let [token, curr_vcol, curr_col] = indtokens[i]
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1174 call s:Log(' Match for "end" in line ' . lnum_new . ': ' .
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1175 \string(indtokens[i]))
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1176 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1177
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1178 else " token is one of the following: ')', ']', '}'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1179
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1180 call s:Push(stack, token)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1181
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1182 " We have to escape '[', because this string will be interpreted as a
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1183 " regexp
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1184 let open_paren = (token ==# ')' ? '(' :
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1185 \token ==# ']' ? '\[' :
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1186 \ '{')
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1187
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1188 let [lnum_new, col_new] = s:SearchPair(lnum, curr_col,
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1189 \open_paren, '', token)
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1190
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1191 if lnum_new ==# 0
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1192 return s:IndentError('Matching token not found',
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1193 \token, stack)
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1194 else
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1195 if lnum_new != lnum
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1196 call s:Log(' Tokenize the opening paren <<<<')
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1197 let [lnum, indtokens] = s:TokenizeLine(lnum_new, 'up')
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1198 call s:Log(' >>>>')
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1199 endif
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1200
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1201 let [success, i] = s:GetIndtokenAtCol(indtokens, col_new)
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1202 if !success | return i | endif
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1203 let [token, curr_vcol, curr_col] = indtokens[i]
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1204 call s:Log(' Match in line ' . lnum_new . ': ' .
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1205 \string(indtokens[i]))
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1206
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1207 " Go back to the beginning of the loop and handle the opening paren
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1208 continue
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1209 endif
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1210 endif
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1211
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1212 elseif token ==# ';'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1213
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1214 if empty(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1215 call s:Push(stack, ';')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1216 elseif index([';', '->', 'when', 'end', 'after', 'catch'],
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1217 \stack[0]) != -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1218 " Pass:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1219 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1220 " - If the stack top is another ';', then one ';' is
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1221 " enough.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1222 " - If the stack top is an '->' or a 'when', then we
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1223 " should keep that, because they signify the type of the
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1224 " LTI (branch, condition or guard).
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1225 " - From the indentation point of view, the keyword
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1226 " (of/catch/after/end) before the LTI is what counts, so
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1227 " if the stack already has a catch/after/end, we don't
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1228 " modify it. This way when we reach case/try/receive,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1229 " there will be at most one of/catch/after/end token in
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1230 " the stack.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1231 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1232 return s:UnexpectedToken(token, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1233 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1234
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1235 elseif token ==# '->'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1236
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1237 if empty(stack) && !last_token_of_line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1238 call s:Log(' LTI is in expression after arrow -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1239 return stored_vcol
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1240 elseif empty(stack) || stack[0] ==# ';' || stack[0] ==# 'end'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1241 " stack = [';'] -> LTI is either a branch or in a guard
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1242 " stack = ['->'] -> LTI is a condition
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1243 " stack = ['->', ';'] -> LTI is a branch
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1244 call s:Push(stack, '->')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1245 elseif index(['->', 'when', 'end', 'after', 'catch'], stack[0]) != -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1246 " Pass:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1247 "
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1248 " - If the stack top is another '->', then one '->' is
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1249 " enough.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1250 " - If the stack top is a 'when', then we should keep
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1251 " that, because this signifies that LTI is a in a guard.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1252 " - From the indentation point of view, the keyword
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1253 " (of/catch/after/end) before the LTI is what counts, so
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1254 " if the stack already has a catch/after/end, we don't
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1255 " modify it. This way when we reach case/try/receive,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1256 " there will be at most one of/catch/after/end token in
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1257 " the stack.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1258 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1259 return s:UnexpectedToken(token, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1260 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1261
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1262 elseif token ==# 'when'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1263
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1264 " Pop all ';' from the top of the stack
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1265 while !empty(stack) && stack[0] ==# ';'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1266 call s:Pop(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1267 endwhile
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1268
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1269 if empty(stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1270 if semicolon_abscol != ''
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1271 let stored_vcol = semicolon_abscol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1272 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1273 if !last_token_of_line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1274 " Example:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1275 " when A,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1276 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1277 let [ret, res] = s:BeginElementFoundIfEmpty(stack, token, curr_vcol,
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
1278 \stored_vcol, shiftwidth())
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1279 if ret | return res | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1280 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1281 " Example:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1282 " when
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1283 " LTI
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1284 call s:Push(stack, token)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1285 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1286 elseif index(['->', 'when', 'end', 'after', 'catch'], stack[0]) != -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1287 " Pass:
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1288 " - If the stack top is another 'when', then one 'when' is
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1289 " enough.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1290 " - If the stack top is an '->' or a 'when', then we
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1291 " should keep that, because they signify the type of the
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1292 " LTI (branch, condition or guard).
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1293 " - From the indentation point of view, the keyword
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1294 " (of/catch/after/end) before the LTI is what counts, so
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1295 " if the stack already has a catch/after/end, we don't
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1296 " modify it. This way when we reach case/try/receive,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1297 " there will be at most one of/catch/after/end token in
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1298 " the stack.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1299 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1300 return s:UnexpectedToken(token, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1301 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1302
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1303 elseif token ==# 'of' || token ==# 'after' ||
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1304 \ (token ==# 'catch' && !s:IsCatchStandalone(lnum, i))
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1305
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1306 if token ==# 'after'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1307 " If LTI is between an 'after' and the corresponding
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1308 " 'end', then let's return
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1309 let [ret, res] = s:BeginElementFoundIfEmpty(stack, token, curr_vcol,
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 5277
diff changeset
1310 \stored_vcol, shiftwidth())
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1311 if ret | return res | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1312 endif
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1313
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1314 if empty(stack) || stack[0] ==# '->' || stack[0] ==# 'when'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1315 call s:Push(stack, token)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1316 elseif stack[0] ==# 'catch' || stack[0] ==# 'after' || stack[0] ==# 'end'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1317 " Pass: From the indentation point of view, the keyword
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1318 " (of/catch/after/end) before the LTI is what counts, so
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1319 " if the stack already has a catch/after/end, we don't
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1320 " modify it. This way when we reach case/try/receive,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1321 " there will be at most one of/catch/after/end token in
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1322 " the stack.
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1323 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1324 return s:UnexpectedToken(token, stack)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1325 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1326
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1327 elseif token ==# '||' && empty(stack) && !last_token_of_line
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1328
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1329 call s:Log(' LTI is in expression after "||" -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1330 return stored_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1331
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1332 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1333 call s:Log(' Misc token, stack unchanged = ' . string(stack))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1334
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1335 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1336
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1337 if empty(stack) || stack[0] ==# '->' || stack[0] ==# 'when'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1338 let stored_vcol = curr_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1339 let semicolon_abscol = ''
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1340 call s:Log(' Misc token when the stack is empty or has "->" ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1341 \'-> setting stored_vcol to ' . stored_vcol)
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1342 elseif stack[0] ==# ';'
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1343 let semicolon_abscol = curr_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1344 call s:Log(' Setting semicolon-stored_vcol to ' . stored_vcol)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1345 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1346
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1347 let i -= 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1348 call s:Log(' Token processed. stored_vcol=' . stored_vcol)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1349
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1350 let last_token_of_line = 0
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1351
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1352 endwhile " iteration on tokens in a line
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1353
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1354 call s:Log(' Line analyzed. stored_vcol=' . stored_vcol)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1355
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1356 if empty(stack) && stored_vcol != -1 &&
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1357 \ (!empty(indtokens) && indtokens[0][0] != '<string_end>' &&
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1358 \ indtokens[0][0] != '<quoted_atom_end>')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1359 call s:Log(' Empty stack at the beginning of the line -> return')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1360 return stored_vcol
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1361 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1362
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1363 let lnum -= 1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1364
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1365 endwhile " iteration on lines
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1366
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1367 endfunction
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1368
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1369 " ErlangIndent function {{{1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1370 " =====================
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1371
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1372 function! ErlangIndent()
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1373
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1374 call s:ClearTokenCacheIfNeeded()
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1375
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1376 let currline = getline(v:lnum)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1377 call s:Log('Indenting line ' . v:lnum . ': ' . currline)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1378
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1379 if s:IsLineStringContinuation(v:lnum) || s:IsLineAtomContinuation(v:lnum)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1380 call s:Log('String or atom continuation found -> ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1381 \'leaving indentation unchanged')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1382 return -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1383 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1384
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1385 " If the line starts with the comment, and so is the previous non-blank line
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1386 if currline =~# '^\s*%'
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1387 let lnum = prevnonblank(v:lnum - 1)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1388 if lnum ==# 0
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1389 call s:Log('First non-empty line of the file -> return 0.')
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1390 return 0
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1391 else
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1392 let ml = matchlist(getline(lnum), '^\(\s*\)%')
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1393 " If the previous line also starts with a comment, then return the same
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1394 " indentation that line has. Otherwise exit from this special "if" and
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1395 " don't care that the current line is a comment.
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1396 if !empty(ml)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1397 let new_col = s:CalcVCol(ml[1], 0, len(ml[1]) - 1, 0, &tabstop)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1398 call s:Log('Comment line after another comment line -> ' .
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1399 \'use same indent: ' . new_col)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1400 return new_col
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1401 endif
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1402 endif
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1403 endif
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1404
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1405 let ml = matchlist(currline,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1406 \'^\(\s*\)\(\%(end\|of\|catch\|after\)\>\|[)\]}]\|>>\)')
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1407
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1408 " If the line has a special beginning, but not a standalone catch
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1409 if !empty(ml) && !(ml[2] ==# 'catch' && s:IsCatchStandalone(v:lnum, 0))
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1410
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1411 let curr_col = len(ml[1])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1412
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1413 " If we can be sure that there is synchronization in the Erlang
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1414 " syntax, we use searchpair to make the script quicker.
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1415 if ml[2] ==# 'end' && exists('b:erlang_syntax_synced')
4780
2b11ac90d9e9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4437
diff changeset
1416
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1417 let [lnum, col] = s:SearchEndPair(v:lnum, curr_col)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1418
5277
42bf9264e64e Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4780
diff changeset
1419 if lnum ==# 0
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1420 return s:IndentError('Matching token for "end" not found',
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1421 \'end', [])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1422 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1423 call s:Log(' Tokenize for "end" <<<<')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1424 let [lnum, indtokens] = s:TokenizeLine(lnum, 'up')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1425 call s:Log(' >>>> Tokenize for "end"')
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1426
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1427 let [success, i] = s:GetIndtokenAtCol(indtokens, col)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1428 if !success | return i | endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1429 let [token, curr_vcol, curr_col] = indtokens[i]
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1430 call s:Log(' Match for "end" in line ' . lnum . ': ' .
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1431 \string(indtokens[i]))
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1432 return curr_vcol
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1433 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1434
3281
af1e8a1714c2 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
1435 else
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1436
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1437 call s:Log(" Line type = 'end'")
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1438 let new_col = s:ErlangCalcIndent(v:lnum - 1,
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1439 \[ml[2], 'align_to_begin_element'])
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1440 endif
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1441 else
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1442 call s:Log(" Line type = 'normal'")
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1443
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1444 let new_col = s:ErlangCalcIndent(v:lnum - 1, [])
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1445 if currline =~# '^\s*when\>'
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1446 let new_col += 2
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1447 endif
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1448 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1449
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1450 if new_col < -1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1451 call s:Log('WARNING: returning new_col == ' . new_col)
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1452 return g:erlang_unexpected_token_indent
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1453 endif
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1454
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1455 return new_col
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1456
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1457 endfunction
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1458
22328
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1459 " ErlangShowTokensInLine functions {{{1
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1460 " ================================
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1461
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1462 " These functions are useful during development.
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1463
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1464 function! ErlangShowTokensInLine(line)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1465 echo "Line: " . a:line
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1466 let indtokens = s:GetTokensFromLine(a:line, 0, 0, &tabstop)
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1467 echo "Tokens:"
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1468 for it in indtokens
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1469 echo it
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1470 endfor
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1471 endfunction
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1472
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1473 function! ErlangShowTokensInCurrentLine()
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1474 return ErlangShowTokensInLine(getline('.'))
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1475 endfunction
75ff30a78189 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
1476
4437
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1477 " Cleanup {{{1
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1478 " =======
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1479
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1480 let &cpo = s:cpo_save
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1481 unlet s:cpo_save
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1482
eb6ab7e78925 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3281
diff changeset
1483 " vim: sw=2 et fdm=marker