annotate runtime/indent/falcon.vim @ 30867:0913cd44fdfa v9.0.0768

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