annotate runtime/indent/falcon.vim @ 18890:623afba3566a v8.2.0006

patch 8.2.0006: test using long file name may fail Commit: https://github.com/vim/vim/commit/6e43b30a854d9aca451a794d368443b90f259a7e Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 14 17:53:27 2019 +0100 patch 8.2.0006: test using long file name may fail Problem: Test using long file name may fail. (Vladimir Lomov) Solution: Limit the name length. (Christian Brabandt, closes https://github.com/vim/vim/issues/5358)
author Bram Moolenaar <Bram@vim.org>
date Sat, 14 Dec 2019 18:00:04 +0100
parents 8b334e4cb97f
children 6dd88e45d47d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " Vim indent file
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 " Language: Falcon
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 " Maintainer: Steven Oliver <oliver.steven@gmail.com>
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 " Website: https://steveno@github.com/steveno/falconpl-vim.git
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
5 " Credits: This is, to a great extent, a copy n' paste of ruby.vim.
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
7 " 1. Setup {{{1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
8 " ============
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 " Only load this indent file when no other was loaded.
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 if exists("b:did_indent")
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 finish
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 let b:did_indent = 1
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 setlocal nosmartindent
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 " Setup indent function and when to use it
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
19 setlocal indentexpr=FalconGetIndent(v:lnum)
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 setlocal indentkeys=0{,0},0),0],!^F,o,O,e
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 setlocal indentkeys+==~case,=~catch,=~default,=~elif,=~else,=~end,=~\"
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 " Define the appropriate indent function but only once
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 if exists("*FalconGetIndent")
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25 finish
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 let s:cpo_save = &cpo
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 set cpo&vim
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
31 " 2. Variables {{{1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
32 " ============
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 " Regex of syntax group names that are strings AND comments
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 let s:syng_strcom = '\<falcon\%(String\|StringEscape\|Comment\)\>'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 " Regex of syntax group names that are strings
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 let s:syng_string = '\<falcon\%(String\|StringEscape\)\>'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
40 " Regex that defines blocks.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
41 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
42 " Note that there's a slight problem with this regex and s:continuation_regex.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
43 " Code like this will be matched by both:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
44 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
45 " method_call do |(a, b)|
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
46 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
47 " The reason is that the pipe matches a hanging "|" operator.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
48 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
49 let s:block_regex =
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
50 \ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|\s*(*\s*\%([*@&]\=\h\w*,\=\s*\)\%(,\s*(*\s*[*@&]\=\h\w*\s*)*\s*\)*|\)\=\s*\%(#.*\)\=$'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
51
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
52 let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
53
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
54 " Regex that defines continuation lines.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
55 " TODO: this needs to deal with if ...: and so on
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
56 let s:continuation_regex =
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
57 \ '\%(%\@<![({[\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
58
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
59 " Regex that defines bracket continuations
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
60 let s:bracket_continuation_regex = '%\@<!\%([({[]\)\s*\%(#.*\)\=$'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
61
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
62 " Regex that defines continuation lines, not including (, {, or [.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
63 let s:non_bracket_continuation_regex = '\%([\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
64
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 " Keywords to indent on
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 let s:falcon_indent_keywords = '^\s*\(case\|catch\|class\|enum\|default\|elif\|else' .
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 \ '\|for\|function\|if.*"[^"]*:.*"\|if \(\(:\)\@!.\)*$\|loop\|object\|select' .
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 \ '\|switch\|try\|while\|\w*\s*=\s*\w*([$\)'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 " Keywords to deindent on
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 let s:falcon_deindent_keywords = '^\s*\(case\|catch\|default\|elif\|else\|end\)'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
73 " 3. Functions {{{1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
74 " ============
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
76 " Check if the character at lnum:col is inside a string, comment, or is ascii.
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 function s:IsInStringOrComment(lnum, col)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 endfunction
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
81 " Check if the character at lnum:col is inside a string.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
82 function s:IsInString(lnum, col)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
83 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
84 endfunction
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
85
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
86 " Check if the character at lnum:col is inside a string delimiter
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
87 function s:IsInStringDelimiter(lnum, col)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
88 return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'falconStringDelimiter'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
89 endfunction
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
91 " Find line above 'lnum' that isn't empty, in a comment, or in a string.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
92 function s:PrevNonBlankNonString(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
93 let in_block = 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
94 let lnum = prevnonblank(a:lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
95 while lnum > 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
96 " Go in and out of blocks comments as necessary.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
97 " If the line isn't empty (with opt. comment) or in a string, end search.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
98 let line = getline(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
99 if line =~ '^=begin'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
100 if in_block
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
101 let in_block = 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
102 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
103 break
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
104 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
105 elseif !in_block && line =~ '^=end'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
106 let in_block = 1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
107 elseif !in_block && line !~ '^\s*#.*$' && !(s:IsInStringOrComment(lnum, 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
108 \ && s:IsInStringOrComment(lnum, strlen(line)))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
109 break
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
110 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
111 let lnum = prevnonblank(lnum - 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
112 endwhile
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
113 return lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
114 endfunction
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
116 " Find line above 'lnum' that started the continuation 'lnum' may be part of.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
117 function s:GetMSL(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
118 " Start on the line we're at and use its indent.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
119 let msl = a:lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
120 let msl_body = getline(msl)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
121 let lnum = s:PrevNonBlankNonString(a:lnum - 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
122 while lnum > 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
123 " If we have a continuation line, or we're in a string, use line as MSL.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
124 " Otherwise, terminate search as we have found our MSL already.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
125 let line = getline(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
126
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
127 if s:Match(line, s:non_bracket_continuation_regex) &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
128 \ s:Match(msl, s:non_bracket_continuation_regex)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
129 " If the current line is a non-bracket continuation and so is the
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
130 " previous one, keep its indent and continue looking for an MSL.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
131 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
132 " Example:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
133 " method_call one,
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
134 " two,
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
135 " three
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
136 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
137 let msl = lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
138 elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
139 \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
140 " If the current line is a bracket continuation or a block-starter, but
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
141 " the previous is a non-bracket one, respect the previous' indentation,
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
142 " and stop here.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
143 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
144 " Example:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
145 " method_call one,
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
146 " two {
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
147 " three
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
148 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
149 return lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
150 elseif s:Match(lnum, s:bracket_continuation_regex) &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
151 \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
152 " If both lines are bracket continuations (the current may also be a
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
153 " block-starter), use the current one's and stop here
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
154 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
155 " Example:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
156 " method_call(
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
157 " other_method_call(
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
158 " foo
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
159 return msl
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
160 elseif s:Match(lnum, s:block_regex) &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
161 \ !s:Match(msl, s:continuation_regex) &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
162 \ !s:Match(msl, s:block_continuation_regex)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
163 " If the previous line is a block-starter and the current one is
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
164 " mostly ordinary, use the current one as the MSL.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
165 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
166 " Example:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
167 " method_call do
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
168 " something
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
169 " something_else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
170 return msl
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
171 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
172 let col = match(line, s:continuation_regex) + 1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
173 if (col > 0 && !s:IsInStringOrComment(lnum, col))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
174 \ || s:IsInString(lnum, strlen(line))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
175 let msl = lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
176 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
177 break
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
178 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
179 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
180
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
181 let msl_body = getline(msl)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
182 let lnum = s:PrevNonBlankNonString(lnum - 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
183 endwhile
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
184 return msl
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
185 endfunction
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
186
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
187 " Check if line 'lnum' has more opening brackets than closing ones.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
188 function s:ExtraBrackets(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
189 let opening = {'parentheses': [], 'braces': [], 'brackets': []}
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
190 let closing = {'parentheses': [], 'braces': [], 'brackets': []}
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
192 let line = getline(a:lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
193 let pos = match(line, '[][(){}]', 0)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
194
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
195 " Save any encountered opening brackets, and remove them once a matching
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
196 " closing one has been found. If a closing bracket shows up that doesn't
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
197 " close anything, save it for later.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
198 while pos != -1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
199 if !s:IsInStringOrComment(a:lnum, pos + 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
200 if line[pos] == '('
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
201 call add(opening.parentheses, {'type': '(', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
202 elseif line[pos] == ')'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
203 if empty(opening.parentheses)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
204 call add(closing.parentheses, {'type': ')', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
205 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
206 let opening.parentheses = opening.parentheses[0:-2]
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
207 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
208 elseif line[pos] == '{'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
209 call add(opening.braces, {'type': '{', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
210 elseif line[pos] == '}'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
211 if empty(opening.braces)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
212 call add(closing.braces, {'type': '}', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
213 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
214 let opening.braces = opening.braces[0:-2]
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
215 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
216 elseif line[pos] == '['
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
217 call add(opening.brackets, {'type': '[', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
218 elseif line[pos] == ']'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
219 if empty(opening.brackets)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
220 call add(closing.brackets, {'type': ']', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
221 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
222 let opening.brackets = opening.brackets[0:-2]
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
223 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
224 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
225 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
226
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
227 let pos = match(line, '[][(){}]', pos + 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
228 endwhile
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
229
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
230 " Find the rightmost brackets, since they're the ones that are important in
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
231 " both opening and closing cases
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
232 let rightmost_opening = {'type': '(', 'pos': -1}
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
233 let rightmost_closing = {'type': ')', 'pos': -1}
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
234
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
235 for opening in opening.parentheses + opening.braces + opening.brackets
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
236 if opening.pos > rightmost_opening.pos
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
237 let rightmost_opening = opening
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
238 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
239 endfor
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
240
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
241 for closing in closing.parentheses + closing.braces + closing.brackets
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
242 if closing.pos > rightmost_closing.pos
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
243 let rightmost_closing = closing
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
244 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
245 endfor
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
246
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
247 return [rightmost_opening, rightmost_closing]
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
248 endfunction
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
249
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
250 function s:Match(lnum, regex)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
251 let col = match(getline(a:lnum), '\C'.a:regex) + 1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
252 return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
253 endfunction
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
254
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
255 function s:MatchLast(lnum, regex)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
256 let line = getline(a:lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
257 let col = match(line, '.*\zs' . a:regex)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
258 while col != -1 && s:IsInStringOrComment(a:lnum, col)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
259 let line = strpart(line, 0, col)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
260 let col = match(line, '.*' . a:regex)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
261 endwhile
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
262 return col + 1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
263 endfunction
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
264
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
265 " 4. FalconGetIndent Routine {{{1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
266 " ============
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
267
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
268 function FalconGetIndent(...)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
269 " For the current line, use the first argument if given, else v:lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
270 let clnum = a:0 ? a:1 : v:lnum
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 " Use zero indent at the top of the file
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
273 if clnum == 0
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 return 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
276
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
277 let line = getline(clnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
278 let ind = -1
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
280 " If we got a closing bracket on an empty line, find its match and indent
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
281 " according to it. For parentheses we indent to its column - 1, for the
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
282 " others we indent to the containing line's MSL's level. Return -1 if fail.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
283 let col = matchend(line, '^\s*[]})]')
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
284 if col > 0 && !s:IsInStringOrComment(clnum, col)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
285 call cursor(clnum, col)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
286 let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
287 if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
288 if line[col-1]==')' && col('.') != col('$') - 1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
289 let ind = virtcol('.') - 1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
290 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
291 let ind = indent(s:GetMSL(line('.')))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
292 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
293 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
294 return ind
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
296
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
297 " If we have a deindenting keyword, find its match and indent to its level.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
298 " TODO: this is messy
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
299 if s:Match(clnum, s:falcon_deindent_keywords)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
300 call cursor(clnum, 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
301 if searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
302 \ s:end_skip_expr) > 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
303 let msl = s:GetMSL(line('.'))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
304 let line = getline(line('.'))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
305
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
306 if strpart(line, 0, col('.') - 1) =~ '=\s*$' &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
307 \ strpart(line, col('.') - 1, 2) !~ 'do'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
308 let ind = virtcol('.') - 1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
309 elseif getline(msl) =~ '=\s*\(#.*\)\=$'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
310 let ind = indent(line('.'))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
311 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
312 let ind = indent(msl)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
313 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
314 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
315 return ind
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
318 " If we are in a multi-line string or line-comment, don't do anything to it.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
319 if s:IsInString(clnum, matchend(line, '^\s*') + 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
320 return indent('.')
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
321 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
322
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
323 " Find a non-blank, non-multi-line string line above the current line.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
324 let lnum = s:PrevNonBlankNonString(clnum - 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
325
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
326 " If the line is empty and inside a string, use the previous line.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
327 if line =~ '^\s*$' && lnum != prevnonblank(clnum - 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
328 return indent(prevnonblank(clnum))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
329 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
330
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
331 " At the start of the file use zero indent.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
332 if lnum == 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
333 return 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
334 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
335
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
336 " Set up variables for the previous line.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
337 let line = getline(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
338 let ind = indent(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
339
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
340 " If the previous line ended with a block opening, add a level of indent.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
341 if s:Match(lnum, s:block_regex)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
342 return indent(s:GetMSL(lnum)) + shiftwidth()
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
343 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
344
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
345 " If it contained hanging closing brackets, find the rightmost one, find its
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
346 " match and indent according to that.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
347 if line =~ '[[({]' || line =~ '[])}]\s*\%(#.*\)\=$'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
348 let [opening, closing] = s:ExtraBrackets(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
349
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
350 if opening.pos != -1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
351 if opening.type == '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
352 if col('.') + 1 == col('$')
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
353 return ind + shiftwidth()
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
354 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
355 return virtcol('.')
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
356 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
357 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
358 let nonspace = matchend(line, '\S', opening.pos + 1) - 1
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
359 return nonspace > 0 ? nonspace : ind + shiftwidth()
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
360 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
361 elseif closing.pos != -1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
362 call cursor(lnum, closing.pos + 1)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
363 normal! %
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
364
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
365 if s:Match(line('.'), s:falcon_indent_keywords)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
366 return indent('.') + shiftwidth()
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
367 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
368 return indent('.')
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
369 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
370 else
15194
8b334e4cb97f Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
371 call cursor(clnum, 0) " FIXME: column was vcol
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
372 end
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
373 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
374
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
375 " If the previous line ended with an "end", match that "end"s beginning's
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
376 " indent.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
377 let col = s:Match(lnum, '\%(^\|[^.:@$]\)\<end\>\s*\%(#.*\)\=$')
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
378 if col > 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
379 call cursor(lnum, col)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
380 if searchpair(s:end_start_regex, '', s:end_end_regex, 'bW',
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
381 \ s:end_skip_expr) > 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
382 let n = line('.')
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
383 let ind = indent('.')
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
384 let msl = s:GetMSL(n)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
385 if msl != n
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
386 let ind = indent(msl)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
387 end
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
388 return ind
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
389 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
390 end
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
391
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
392 let col = s:Match(lnum, s:falcon_indent_keywords)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
393 if col > 0
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
394 call cursor(lnum, col)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
395 let ind = virtcol('.') - 1 + shiftwidth()
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
396 " TODO: make this better (we need to count them) (or, if a searchpair
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
397 " fails, we know that something is lacking an end and thus we indent a
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
398 " level
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
399 if s:Match(lnum, s:end_end_regex)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
400 let ind = indent('.')
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
401 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
402 return ind
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
403 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
404
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
405 " Set up variables to use and search for MSL to the previous line.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
406 let p_lnum = lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
407 let lnum = s:GetMSL(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
408
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
409 " If the previous line wasn't a MSL and is continuation return its indent.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
410 " TODO: the || s:IsInString() thing worries me a bit.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
411 if p_lnum != lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
412 if s:Match(p_lnum, s:non_bracket_continuation_regex) || s:IsInString(p_lnum,strlen(line))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
413 return ind
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
414 endif
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
415 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
416
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
417 " Set up more variables, now that we know we wasn't continuation bound.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
418 let line = getline(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
419 let msl_ind = indent(lnum)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
420
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
421 " If the MSL line had an indenting keyword in it, add a level of indent.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
422 " TODO: this does not take into account contrived things such as
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
423 " module Foo; class Bar; end
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
424 if s:Match(lnum, s:falcon_indent_keywords)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
425 let ind = msl_ind + shiftwidth()
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
426 if s:Match(lnum, s:end_end_regex)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
427 let ind = ind - shiftwidth()
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
428 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
429 return ind
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
430 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
431
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
432 " If the previous line ended with [*+/.,-=], but wasn't a block ending or a
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
433 " closing bracket, indent one extra level.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
434 if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\([\])}]\|end\)')
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
435 if lnum == p_lnum
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
436 let ind = msl_ind + shiftwidth()
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
437 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
438 let ind = msl_ind
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
439 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
440 return ind
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
441 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
442
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
443 return ind
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
444 endfunction
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
445
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
446 " }}}1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4186
diff changeset
447
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2596
diff changeset
448 let &cpo = s:cpo_save
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2596
diff changeset
449 unlet s:cpo_save
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2596
diff changeset
450
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
451 " vim: set sw=4 sts=4 et tw=80 :