annotate runtime/indent/erlang.vim @ 32553:e80fa10e0549 v9.0.1608

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