annotate runtime/indent/erlang.vim @ 4555:b2946c06d1b6 v7.3.1025

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