annotate runtime/indent/ruby.vim @ 34215:8b0648002604 v9.1.0056

patch 9.1.0056: wrong number of trailing spaces inserted after blockwise put Commit: https://github.com/vim/vim/commit/6638ec8afa9875ff565020536954c424d5f6f27d Author: VanaIgr <vanaigranov@gmail.com> Date: Thu Jan 25 21:50:41 2024 +0100 patch 9.1.0056: wrong number of trailing spaces inserted after blockwise put Problem: Incorrect number of trailing spaces inserted for multibyte characters when pasting a blockwise register in blockwise visual mode (VanaIgr) Solution: Skip over trailing UTF-8 bytes when computing the number of trailing spaces (VanaIgr) When pasting in blockwise visual mode, and the register type is <CTRL-V>, Vim aligns the text after the replaced area by inserting spaces after pasted lines that are shorter than the longest line. When a shorter line contains multibyte characters, each trailing UTF-8 byte's width is counted in addition to the width of the character itself. Each trailing byte counts as being 4 cells wide (since it would be displayed as <xx>). closes: #13909 Signed-off-by: VanaIgr <vanaigranov@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 25 Jan 2024 22:15:02 +0100
parents d3d82d3f6006
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
843
9f279ebda751 updated for version 7.0f01
vimboss
parents: 557
diff changeset
2 " Language: Ruby
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
3 " Maintainer: Andrew Radev <andrey.radev@gmail.com>
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
4 " Previous Maintainer: Nikolai Weibull <now at bitwi.se>
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
5 " URL: https://github.com/vim-ruby/vim-ruby
843
9f279ebda751 updated for version 7.0f01
vimboss
parents: 557
diff changeset
6 " Release Coordinator: Doug Kearns <dougkearns@gmail.com>
33098
d3d82d3f6006 runtime(ruby): Update syntax, indent and ftplugin files
Christian Brabandt <cb@256bit.org>
parents: 28246
diff changeset
7 " Last Change: 2022 Jun 30
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
8
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
9 " 0. Initialization {{{1
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
10 " =================
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
18 if !exists('g:ruby_indent_access_modifier_style')
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
19 " Possible values: "normal", "indent", "outdent"
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
20 let g:ruby_indent_access_modifier_style = 'normal'
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
21 endif
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
22
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
23 if !exists('g:ruby_indent_assignment_style')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
24 " Possible values: "variable", "hanging"
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
25 let g:ruby_indent_assignment_style = 'hanging'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
26 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
27
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
28 if !exists('g:ruby_indent_block_style')
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
29 " Possible values: "expression", "do"
23931
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
30 let g:ruby_indent_block_style = 'do'
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
31 endif
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
32
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
33 if !exists('g:ruby_indent_hanging_elements')
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
34 " Non-zero means hanging indents are enabled, zero means disabled
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
35 let g:ruby_indent_hanging_elements = 1
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
36 endif
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
37
843
9f279ebda751 updated for version 7.0f01
vimboss
parents: 557
diff changeset
38 setlocal nosmartindent
9f279ebda751 updated for version 7.0f01
vimboss
parents: 557
diff changeset
39
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
40 " Now, set up our indentation expression and keys that trigger it.
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
41 setlocal indentexpr=GetRubyIndent(v:lnum)
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
42 setlocal indentkeys=0{,0},0),0],!^F,o,O,e,:,.
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
43 setlocal indentkeys+==end,=else,=elsif,=when,=in\ ,=ensure,=rescue,==begin,==end
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
44 setlocal indentkeys+==private,=protected,=public
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
46 let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
47
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 if exists("*GetRubyIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
53 let s:cpo_save = &cpo
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
54 set cpo&vim
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
55
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
56 " 1. Variables {{{1
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
57 " ============
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
58
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
59 " Syntax group names that are strings.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
60 let s:syng_string =
18857
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
61 \ ['String', 'Interpolation', 'InterpolationDelimiter', 'StringEscape']
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
62
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
63 " Syntax group names that are strings or documentation.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
64 let s:syng_stringdoc = s:syng_string + ['Documentation']
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
65
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
66 " Syntax group names that are or delimit strings/symbols/regexes or are comments.
18857
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
67 let s:syng_strcom = s:syng_stringdoc + [
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
68 \ 'Character',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
69 \ 'Comment',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
70 \ 'HeredocDelimiter',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
71 \ 'PercentRegexpDelimiter',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
72 \ 'PercentStringDelimiter',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
73 \ 'PercentSymbolDelimiter',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
74 \ 'Regexp',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
75 \ 'RegexpCharClass',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
76 \ 'RegexpDelimiter',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
77 \ 'RegexpEscape',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
78 \ 'StringDelimiter',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
79 \ 'Symbol',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
80 \ 'SymbolDelimiter',
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
81 \ ]
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
82
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
83 " Expression used to check whether we should skip a match with searchpair().
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
84 let s:skip_expr =
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
85 \ 'index(map('.string(s:syng_strcom).',"hlID(''ruby''.v:val)"), synID(line("."),col("."),1)) >= 0'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
86
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
87 " Regex used for words that, at the start of a line, add a level of indent.
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
88 let s:ruby_indent_keywords =
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
89 \ '^\s*\zs\<\%(module\|class\|if\|for' .
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
90 \ '\|while\|until\|else\|elsif\|case\|when\|in\|unless\|begin\|ensure\|rescue' .
18857
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
91 \ '\|\%(\K\k*[!?]\?\s\+\)\=def\):\@!\>' .
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
92 \ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' .
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
93 \ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
94
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
95 " Def without an end clause: def method_call(...) = <expression>
33098
d3d82d3f6006 runtime(ruby): Update syntax, indent and ftplugin files
Christian Brabandt <cb@256bit.org>
parents: 28246
diff changeset
96 let s:ruby_endless_def = '\<def\s\+\%(\k\+\.\)\=\k\+[!?]\=\%((.*)\|\s\)\s*='
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
97
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
98 " Regex used for words that, at the start of a line, remove a level of indent.
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
99 let s:ruby_deindent_keywords =
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
100 \ '^\s*\zs\<\%(ensure\|else\|rescue\|elsif\|when\|in\|end\):\@!\>'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
101
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
102 " Regex that defines the start-match for the 'end' keyword.
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
103 "let s:end_start_regex = '\%(^\|[^.]\)\<\%(module\|class\|def\|if\|for\|while\|until\|case\|unless\|begin\|do\)\>'
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
104 " TODO: the do here should be restricted somewhat (only at end of line)?
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
105 let s:end_start_regex =
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
106 \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' .
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
107 \ '\<\%(module\|class\|if\|for\|while\|until\|case\|unless\|begin' .
18857
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
108 \ '\|\%(\K\k*[!?]\?\s\+\)\=def\):\@!\>' .
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
109 \ '\|\%(^\|[^.:@$]\)\@<=\<do:\@!\>'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
110
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
111 " Regex that defines the middle-match for the 'end' keyword.
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
112 let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue:\@!\>\|when\|\%(\%(^\|;\)\s*\)\@<=\<in\|elsif\):\@!\>'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
113
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
114 " Regex that defines the end-match for the 'end' keyword.
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
115 let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\<end:\@!\>'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
116
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
117 " Expression used for searchpair() call for finding a match for an 'end' keyword.
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
118 function! s:EndSkipExpr()
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
119 if eval(s:skip_expr)
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
120 return 1
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
121 elseif expand('<cword>') == 'do'
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
122 \ && getline(".") =~ '^\s*\<\(while\|until\|for\):\@!\>'
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
123 return 1
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
124 elseif getline('.') =~ s:ruby_endless_def
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
125 return 1
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
126 elseif getline('.') =~ '\<def\s\+\k\+[!?]\=([^)]*$'
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
127 " Then it's a `def method(` with a possible `) =` later
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
128 call search('\<def\s\+\k\+\zs(', 'W', line('.'))
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
129 normal! %
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
130 return getline('.') =~ ')\s*='
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
131 else
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
132 return 0
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
133 endif
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
134 endfunction
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
135
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
136 let s:end_skip_expr = function('s:EndSkipExpr')
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
137
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
138 " Regex that defines continuation lines, not including (, {, or [.
10272
57b2b8268d3a commit https://github.com/vim/vim/commit/4575876dc865d4160f20d61bd822fbe7cafbec41
Christian Brabandt <cb@256bit.org>
parents: 10048
diff changeset
139 let s:non_bracket_continuation_regex =
57b2b8268d3a commit https://github.com/vim/vim/commit/4575876dc865d4160f20d61bd822fbe7cafbec41
Christian Brabandt <cb@256bit.org>
parents: 10048
diff changeset
140 \ '\%([\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|:\@<![^[:alnum:]:][|&?]\|||\|&&\)\s*\%(#.*\)\=$'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
141
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
142 " Regex that defines continuation lines.
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
143 let s:continuation_regex =
10272
57b2b8268d3a commit https://github.com/vim/vim/commit/4575876dc865d4160f20d61bd822fbe7cafbec41
Christian Brabandt <cb@256bit.org>
parents: 10048
diff changeset
144 \ '\%(%\@<![({[\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|:\@<![^[:alnum:]:][|&?]\|||\|&&\)\s*\%(#.*\)\=$'
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
145
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
146 " Regex that defines continuable keywords
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
147 let s:continuable_regex =
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
148 \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' .
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
149 \ '\<\%(if\|for\|while\|until\|unless\):\@!\>'
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
150
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
151 " Regex that defines bracket continuations
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
152 let s:bracket_continuation_regex = '%\@<!\%([({[]\)\s*\%(#.*\)\=$'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
153
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
154 " Regex that defines dot continuations
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
155 let s:dot_continuation_regex = '%\@<!\.\s*\%(#.*\)\=$'
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
156
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
157 " Regex that defines backslash continuations
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
158 let s:backslash_continuation_regex = '%\@<!\\\s*$'
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
159
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
160 " Regex that defines end of bracket continuation followed by another continuation
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
161 let s:bracket_switch_continuation_regex = '^\([^(]\+\zs).\+\)\+'.s:continuation_regex
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
162
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
163 " Regex that defines the first part of a splat pattern
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
164 let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
165
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
166 " Regex that describes all indent access modifiers
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
167 let s:access_modifier_regex = '\C^\s*\%(public\|protected\|private\)\s*\%(#.*\)\=$'
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
168
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
169 " Regex that describes the indent access modifiers (excludes public)
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
170 let s:indent_access_modifier_regex = '\C^\s*\%(protected\|private\)\s*\%(#.*\)\=$'
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
171
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
172 " Regex that defines blocks.
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
173 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
174 " Note that there's a slight problem with this regex and s:continuation_regex.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
175 " Code like this will be matched by both:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
176 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
177 " method_call do |(a, b)|
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
178 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
179 " The reason is that the pipe matches a hanging "|" operator.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
180 "
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
181 let s:block_regex =
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
182 \ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|[^|]*|\)\=\s*\%(#.*\)\=$'
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
183
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
184 let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
185
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
186 " Regex that describes a leading operator (only a method call's dot for now)
18857
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
187 let s:leading_operator_regex = '^\s*\%(&\=\.\)'
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
188
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
189 " 2. GetRubyIndent Function {{{1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
190 " =========================
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
191
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
192 function! GetRubyIndent(...) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
193 " 2.1. Setup {{{2
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
194 " ----------
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
195
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
196 let indent_info = {}
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
197
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
198 " The value of a single shift-width
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
199 if exists('*shiftwidth')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
200 let indent_info.sw = shiftwidth()
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
201 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
202 let indent_info.sw = &sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
203 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
204
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
205 " For the current line, use the first argument if given, else v:lnum
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
206 let indent_info.clnum = a:0 ? a:1 : v:lnum
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
207 let indent_info.cline = getline(indent_info.clnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
208
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
209 " Set up variables for restoring position in file. Could use clnum here.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
210 let indent_info.col = col('.')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
211
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
212 " 2.2. Work on the current line {{{2
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
213 " -----------------------------
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
214 let indent_callback_names = [
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
215 \ 's:AccessModifier',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
216 \ 's:ClosingBracketOnEmptyLine',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
217 \ 's:BlockComment',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
218 \ 's:DeindentingKeyword',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
219 \ 's:MultilineStringOrLineComment',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
220 \ 's:ClosingHeredocDelimiter',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
221 \ 's:LeadingOperator',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
222 \ ]
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
223
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
224 for callback_name in indent_callback_names
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
225 " Decho "Running: ".callback_name
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
226 let indent = call(function(callback_name), [indent_info])
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
227
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
228 if indent >= 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
229 " Decho "Match: ".callback_name." indent=".indent." info=".string(indent_info)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
230 return indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
231 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
232 endfor
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
233
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
234 " 2.3. Work on the previous line. {{{2
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
235 " -------------------------------
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
236
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
237 " Special case: we don't need the real s:PrevNonBlankNonString for an empty
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
238 " line inside a string. And that call can be quite expensive in that
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
239 " particular situation.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
240 let indent_callback_names = [
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
241 \ 's:EmptyInsideString',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
242 \ ]
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
243
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
244 for callback_name in indent_callback_names
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
245 " Decho "Running: ".callback_name
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
246 let indent = call(function(callback_name), [indent_info])
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
247
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
248 if indent >= 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
249 " Decho "Match: ".callback_name." indent=".indent." info=".string(indent_info)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
250 return indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
251 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
252 endfor
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
253
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
254 " Previous line number
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
255 let indent_info.plnum = s:PrevNonBlankNonString(indent_info.clnum - 1)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
256 let indent_info.pline = getline(indent_info.plnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
257
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
258 let indent_callback_names = [
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
259 \ 's:StartOfFile',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
260 \ 's:AfterAccessModifier',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
261 \ 's:ContinuedLine',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
262 \ 's:AfterBlockOpening',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
263 \ 's:AfterHangingSplat',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
264 \ 's:AfterUnbalancedBracket',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
265 \ 's:AfterLeadingOperator',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
266 \ 's:AfterEndKeyword',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
267 \ 's:AfterIndentKeyword',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
268 \ ]
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
269
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
270 for callback_name in indent_callback_names
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
271 " Decho "Running: ".callback_name
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
272 let indent = call(function(callback_name), [indent_info])
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
273
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
274 if indent >= 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
275 " Decho "Match: ".callback_name." indent=".indent." info=".string(indent_info)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
276 return indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
277 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
278 endfor
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
279
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
280 " 2.4. Work on the MSL line. {{{2
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
281 " --------------------------
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
282 let indent_callback_names = [
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
283 \ 's:PreviousNotMSL',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
284 \ 's:IndentingKeywordInMSL',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
285 \ 's:ContinuedHangingOperator',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
286 \ ]
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
287
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
288 " Most Significant line based on the previous one -- in case it's a
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25056
diff changeset
289 " continuation of something above
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
290 let indent_info.plnum_msl = s:GetMSL(indent_info.plnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
291
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
292 for callback_name in indent_callback_names
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
293 " Decho "Running: ".callback_name
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
294 let indent = call(function(callback_name), [indent_info])
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
295
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
296 if indent >= 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
297 " Decho "Match: ".callback_name." indent=".indent." info=".string(indent_info)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
298 return indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
299 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
300 endfor
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
301
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
302 " }}}2
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
303
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
304 " By default, just return the previous line's indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
305 " Decho "Default case matched"
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
306 return indent(indent_info.plnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
307 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
308
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
309 " 3. Indenting Logic Callbacks {{{1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
310 " ============================
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
311
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
312 function! s:AccessModifier(cline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
313 let info = a:cline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
314
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
315 " If this line is an access modifier keyword, align according to the closest
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
316 " class declaration.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
317 if g:ruby_indent_access_modifier_style == 'indent'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
318 if s:Match(info.clnum, s:access_modifier_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
319 let class_lnum = s:FindContainingClass()
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
320 if class_lnum > 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
321 return indent(class_lnum) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
322 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
323 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
324 elseif g:ruby_indent_access_modifier_style == 'outdent'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
325 if s:Match(info.clnum, s:access_modifier_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
326 let class_lnum = s:FindContainingClass()
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
327 if class_lnum > 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
328 return indent(class_lnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
329 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
330 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
331 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
332
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
333 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
334 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
335
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
336 function! s:ClosingBracketOnEmptyLine(cline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
337 let info = a:cline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
338
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
339 " If we got a closing bracket on an empty line, find its match and indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
340 " according to it. For parentheses we indent to its column - 1, for the
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
341 " others we indent to the containing line's MSL's level. Return -1 if fail.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
342 let col = matchend(info.cline, '^\s*[]})]')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
343
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
344 if col > 0 && !s:IsInStringOrComment(info.clnum, col)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
345 call cursor(info.clnum, col)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
346 let closing_bracket = info.cline[col - 1]
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
347 let bracket_pair = strpart('(){}[]', stridx(')}]', closing_bracket) * 2, 2)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
348
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
349 if searchpair(escape(bracket_pair[0], '\['), '', bracket_pair[1], 'bW', s:skip_expr) > 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
350 if closing_bracket == ')' && col('.') != col('$') - 1
23931
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
351 if g:ruby_indent_hanging_elements
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
352 let ind = virtcol('.') - 1
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
353 else
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
354 let ind = indent(line('.'))
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
355 end
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
356 elseif g:ruby_indent_block_style == 'do'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
357 let ind = indent(line('.'))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
358 else " g:ruby_indent_block_style == 'expression'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
359 let ind = indent(s:GetMSL(line('.')))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
360 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
361 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
362
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
363 return ind
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
364 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
365
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
366 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
367 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
368
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
369 function! s:BlockComment(cline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
370 " If we have a =begin or =end set indent to first column.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
371 if match(a:cline_info.cline, '^\s*\%(=begin\|=end\)$') != -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
372 return 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
373 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
374 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
375 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
376
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
377 function! s:DeindentingKeyword(cline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
378 let info = a:cline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
379
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
380 " If we have a deindenting keyword, find its match and indent to its level.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
381 " TODO: this is messy
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
382 if s:Match(info.clnum, s:ruby_deindent_keywords)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
383 call cursor(info.clnum, 1)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
384
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
385 if searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
386 \ s:end_skip_expr) > 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
387 let msl = s:GetMSL(line('.'))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
388 let line = getline(line('.'))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
389
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
390 if s:IsAssignment(line, col('.')) &&
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
391 \ strpart(line, col('.') - 1, 2) !~ 'do'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
392 " assignment to case/begin/etc, on the same line
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
393 if g:ruby_indent_assignment_style == 'hanging'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
394 " hanging indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
395 let ind = virtcol('.') - 1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
396 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
397 " align with variable
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
398 let ind = indent(line('.'))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
399 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
400 elseif g:ruby_indent_block_style == 'do'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
401 " align to line of the "do", not to the MSL
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
402 let ind = indent(line('.'))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
403 elseif getline(msl) =~ '=\s*\(#.*\)\=$'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
404 " in the case of assignment to the MSL, align to the starting line,
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
405 " not to the MSL
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
406 let ind = indent(line('.'))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
407 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
408 " align to the MSL
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
409 let ind = indent(msl)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
410 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
411 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
412 return ind
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
413 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
414
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
415 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
416 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
417
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
418 function! s:MultilineStringOrLineComment(cline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
419 let info = a:cline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
420
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
421 " If we are in a multi-line string or line-comment, don't do anything to it.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
422 if s:IsInStringOrDocumentation(info.clnum, matchend(info.cline, '^\s*') + 1)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
423 return indent(info.clnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
424 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
425 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
426 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
427
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
428 function! s:ClosingHeredocDelimiter(cline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
429 let info = a:cline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
430
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
431 " If we are at the closing delimiter of a "<<" heredoc-style string, set the
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
432 " indent to 0.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
433 if info.cline =~ '^\k\+\s*$'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
434 \ && s:IsInStringDelimiter(info.clnum, 1)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
435 \ && search('\V<<'.info.cline, 'nbW') > 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
436 return 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
437 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
438
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
439 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
440 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
441
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
442 function! s:LeadingOperator(cline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
443 " If the current line starts with a leading operator, add a level of indent.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
444 if s:Match(a:cline_info.clnum, s:leading_operator_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
445 return indent(s:GetMSL(a:cline_info.clnum)) + a:cline_info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
446 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
447 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
448 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
449
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
450 function! s:EmptyInsideString(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
451 " If the line is empty and inside a string (the previous line is a string,
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
452 " too), use the previous line's indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
453 let info = a:pline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
454
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
455 let plnum = prevnonblank(info.clnum - 1)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
456 let pline = getline(plnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
457
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
458 if info.cline =~ '^\s*$'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
459 \ && s:IsInStringOrComment(plnum, 1)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
460 \ && s:IsInStringOrComment(plnum, strlen(pline))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
461 return indent(plnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
462 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
463 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
464 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
465
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
466 function! s:StartOfFile(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
467 " At the start of the file use zero indent.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
468 if a:pline_info.plnum == 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
469 return 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
470 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
471 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
472 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
473
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
474 function! s:AfterAccessModifier(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
475 let info = a:pline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
476
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
477 if g:ruby_indent_access_modifier_style == 'indent'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
478 " If the previous line was a private/protected keyword, add a
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
479 " level of indent.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
480 if s:Match(info.plnum, s:indent_access_modifier_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
481 return indent(info.plnum) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
482 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
483 elseif g:ruby_indent_access_modifier_style == 'outdent'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
484 " If the previous line was a private/protected/public keyword, add
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
485 " a level of indent, since the keyword has been out-dented.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
486 if s:Match(info.plnum, s:access_modifier_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
487 return indent(info.plnum) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
488 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
489 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
490 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
491 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
492
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
493 " Example:
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
494 "
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
495 " if foo || bar ||
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
496 " baz || bing
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
497 " puts "foo"
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
498 " end
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
499 "
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
500 function! s:ContinuedLine(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
501 let info = a:pline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
502
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
503 let col = s:Match(info.plnum, s:ruby_indent_keywords)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
504 if s:Match(info.plnum, s:continuable_regex) &&
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
505 \ s:Match(info.plnum, s:continuation_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
506 if col > 0 && s:IsAssignment(info.pline, col)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
507 if g:ruby_indent_assignment_style == 'hanging'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
508 " hanging indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
509 let ind = col - 1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
510 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
511 " align with variable
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
512 let ind = indent(info.plnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
513 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
514 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
515 let ind = indent(s:GetMSL(info.plnum))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
516 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
517 return ind + info.sw + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
518 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
519 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
520 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
521
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
522 function! s:AfterBlockOpening(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
523 let info = a:pline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
524
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
525 " If the previous line ended with a block opening, add a level of indent.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
526 if s:Match(info.plnum, s:block_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
527 if g:ruby_indent_block_style == 'do'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
528 " don't align to the msl, align to the "do"
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
529 let ind = indent(info.plnum) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
530 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
531 let plnum_msl = s:GetMSL(info.plnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
532
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
533 if getline(plnum_msl) =~ '=\s*\(#.*\)\=$'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
534 " in the case of assignment to the msl, align to the starting line,
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
535 " not to the msl
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
536 let ind = indent(info.plnum) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
537 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
538 let ind = indent(plnum_msl) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
539 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
540 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
541
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
542 return ind
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
543 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
544
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
545 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
546 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
547
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
548 function! s:AfterLeadingOperator(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
549 " If the previous line started with a leading operator, use its MSL's level
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
550 " of indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
551 if s:Match(a:pline_info.plnum, s:leading_operator_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
552 return indent(s:GetMSL(a:pline_info.plnum))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
553 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
554 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
555 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
556
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
557 function! s:AfterHangingSplat(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
558 let info = a:pline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
559
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
560 " If the previous line ended with the "*" of a splat, add a level of indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
561 if info.pline =~ s:splat_regex
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
562 return indent(info.plnum) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
563 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
564 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
565 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
566
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
567 function! s:AfterUnbalancedBracket(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
568 let info = a:pline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
569
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
570 " If the previous line contained unclosed opening brackets and we are still
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
571 " in them, find the rightmost one and add indent depending on the bracket
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
572 " type.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
573 "
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
574 " If it contained hanging closing brackets, find the rightmost one, find its
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
575 " match and indent according to that.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
576 if info.pline =~ '[[({]' || info.pline =~ '[])}]\s*\%(#.*\)\=$'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
577 let [opening, closing] = s:ExtraBrackets(info.plnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
578
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
579 if opening.pos != -1
23931
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
580 if !g:ruby_indent_hanging_elements
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
581 return indent(info.plnum) + info.sw
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
582 elseif opening.type == '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
583 if col('.') + 1 == col('$')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
584 return indent(info.plnum) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
585 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
586 return virtcol('.')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
587 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
588 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
589 let nonspace = matchend(info.pline, '\S', opening.pos + 1) - 1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
590 return nonspace > 0 ? nonspace : indent(info.plnum) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
591 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
592 elseif closing.pos != -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
593 call cursor(info.plnum, closing.pos + 1)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
594 normal! %
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
595
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
596 if strpart(info.pline, closing.pos) =~ '^)\s*='
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
597 " special case: the closing `) =` of an endless def
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
598 return indent(s:GetMSL(line('.')))
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
599 endif
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
600
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
601 if s:Match(line('.'), s:ruby_indent_keywords)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
602 return indent('.') + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
603 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
604 return indent(s:GetMSL(line('.')))
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
605 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
606 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
607 call cursor(info.clnum, info.col)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
608 end
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
609 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
610
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
611 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
612 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
613
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
614 function! s:AfterEndKeyword(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
615 let info = a:pline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
616 " If the previous line ended with an "end", match that "end"s beginning's
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
617 " indent.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
618 let col = s:Match(info.plnum, '\%(^\|[^.:@$]\)\<end\>\s*\%(#.*\)\=$')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
619 if col > 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
620 call cursor(info.plnum, col)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
621 if searchpair(s:end_start_regex, '', s:end_end_regex, 'bW',
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
622 \ s:end_skip_expr) > 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
623 let n = line('.')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
624 let ind = indent('.')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
625 let msl = s:GetMSL(n)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
626 if msl != n
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
627 let ind = indent(msl)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
628 end
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
629 return ind
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
630 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
631 end
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
632 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
633 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
634
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
635 function! s:AfterIndentKeyword(pline_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
636 let info = a:pline_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
637 let col = s:Match(info.plnum, s:ruby_indent_keywords)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
638
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
639 if col > 0 && s:Match(info.plnum, s:ruby_endless_def) <= 0
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
640 call cursor(info.plnum, col)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
641 let ind = virtcol('.') - 1 + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
642 " TODO: make this better (we need to count them) (or, if a searchpair
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
643 " fails, we know that something is lacking an end and thus we indent a
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
644 " level
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
645 if s:Match(info.plnum, s:end_end_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
646 let ind = indent('.')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
647 elseif s:IsAssignment(info.pline, col)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
648 if g:ruby_indent_assignment_style == 'hanging'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
649 " hanging indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
650 let ind = col + info.sw - 1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
651 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
652 " align with variable
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
653 let ind = indent(info.plnum) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
654 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
655 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
656 return ind
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
657 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
658
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
659 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
660 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
661
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
662 function! s:PreviousNotMSL(msl_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
663 let info = a:msl_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
664
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
665 " If the previous line wasn't a MSL
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
666 if info.plnum != info.plnum_msl
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
667 " If previous line ends bracket and begins non-bracket continuation decrease indent by 1.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
668 if s:Match(info.plnum, s:bracket_switch_continuation_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
669 " TODO (2016-10-07) Wrong/unused? How could it be "1"?
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
670 return indent(info.plnum) - 1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
671 " If previous line is a continuation return its indent.
23931
5b37a0bf7e3a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 18857
diff changeset
672 elseif s:Match(info.plnum, s:non_bracket_continuation_regex)
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
673 return indent(info.plnum)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
674 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
675 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
676
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
677 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
678 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
679
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
680 function! s:IndentingKeywordInMSL(msl_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
681 let info = a:msl_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
682 " If the MSL line had an indenting keyword in it, add a level of indent.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
683 " TODO: this does not take into account contrived things such as
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
684 " module Foo; class Bar; end
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
685 let col = s:Match(info.plnum_msl, s:ruby_indent_keywords)
28246
e3d6184b89fa Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
686 if col > 0 && s:Match(info.plnum_msl, s:ruby_endless_def) <= 0
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
687 let ind = indent(info.plnum_msl) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
688 if s:Match(info.plnum_msl, s:end_end_regex)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
689 let ind = ind - info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
690 elseif s:IsAssignment(getline(info.plnum_msl), col)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
691 if g:ruby_indent_assignment_style == 'hanging'
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
692 " hanging indent
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
693 let ind = col + info.sw - 1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
694 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
695 " align with variable
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
696 let ind = indent(info.plnum_msl) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
697 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
698 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
699 return ind
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
700 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
701 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
702 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
703
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
704 function! s:ContinuedHangingOperator(msl_info) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
705 let info = a:msl_info
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
706
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
707 " If the previous line ended with [*+/.,-=], but wasn't a block ending or a
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
708 " closing bracket, indent one extra level.
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
709 if s:Match(info.plnum_msl, s:non_bracket_continuation_regex) && !s:Match(info.plnum_msl, '^\s*\([\])}]\|end\)')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
710 if info.plnum_msl == info.plnum
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
711 let ind = indent(info.plnum_msl) + info.sw
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
712 else
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
713 let ind = indent(info.plnum_msl)
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
714 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
715 return ind
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
716 endif
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
717
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
718 return -1
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
719 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
720
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
721 " 4. Auxiliary Functions {{{1
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
722 " ======================
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
723
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
724 function! s:IsInRubyGroup(groups, lnum, col) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
725 let ids = map(copy(a:groups), 'hlID("ruby".v:val)')
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
726 return index(ids, synID(a:lnum, a:col, 1)) >= 0
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
727 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
728
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
729 " Check if the character at lnum:col is inside a string, comment, or is ascii.
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
730 function! s:IsInStringOrComment(lnum, col) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
731 return s:IsInRubyGroup(s:syng_strcom, a:lnum, a:col)
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
732 endfunction
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
733
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
734 " Check if the character at lnum:col is inside a string.
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
735 function! s:IsInString(lnum, col) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
736 return s:IsInRubyGroup(s:syng_string, a:lnum, a:col)
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
737 endfunction
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
738
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
739 " Check if the character at lnum:col is inside a string or documentation.
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
740 function! s:IsInStringOrDocumentation(lnum, col) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
741 return s:IsInRubyGroup(s:syng_stringdoc, a:lnum, a:col)
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
742 endfunction
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
743
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
744 " Check if the character at lnum:col is inside a string delimiter
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
745 function! s:IsInStringDelimiter(lnum, col) abort
18857
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
746 return s:IsInRubyGroup(
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
747 \ ['HeredocDelimiter', 'PercentStringDelimiter', 'StringDelimiter'],
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
748 \ a:lnum, a:col
70ce979e76bc Update a few runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 15512
diff changeset
749 \ )
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
750 endfunction
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
751
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
752 function! s:IsAssignment(str, pos) abort
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
753 return strpart(a:str, 0, a:pos - 1) =~ '=\s*$'
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
754 endfunction
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
755
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
756 " Find line above 'lnum' that isn't empty, in a comment, or in a string.
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
757 function! s:PrevNonBlankNonString(lnum) abort
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
758 let in_block = 0
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
759 let lnum = prevnonblank(a:lnum)
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
760 while lnum > 0
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
761 " Go in and out of blocks comments as necessary.
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
762 " If the line isn't empty (with opt. comment) or in a string, end search.
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
763 let line = getline(lnum)
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
764 if line =~ '^=begin'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
765 if in_block
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
766 let in_block = 0
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
767 else
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
768 break
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
769 endif
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
770 elseif !in_block && line =~ '^=end'
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
771 let in_block = 1
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
772 elseif !in_block && line !~ '^\s*#.*$' && !(s:IsInStringOrComment(lnum, 1)
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
773 \ && s:IsInStringOrComment(lnum, strlen(line)))
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
774 break
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
775 endif
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
776 let lnum = prevnonblank(lnum - 1)
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
777 endwhile
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
778 return lnum
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
779 endfunction
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
780
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
781 " Find line above 'lnum' that started the continuation 'lnum' may be part of.
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
782 function! s:GetMSL(lnum) abort
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
783 " Start on the line we're at and use its indent.
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
784 let msl = a:lnum
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
785 let lnum = s:PrevNonBlankNonString(a:lnum - 1)
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
786 while lnum > 0
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
787 " If we have a continuation line, or we're in a string, use line as MSL.
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
788 " Otherwise, terminate search as we have found our MSL already.
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
789 let line = getline(lnum)
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
790
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
791 if !s:Match(msl, s:backslash_continuation_regex) &&
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
792 \ s:Match(lnum, s:backslash_continuation_regex)
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
793 " If the current line doesn't end in a backslash, but the previous one
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
794 " does, look for that line's msl
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
795 "
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
796 " Example:
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
797 " foo = "bar" \
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
798 " "baz"
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
799 "
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
800 let msl = lnum
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
801 elseif s:Match(msl, s:leading_operator_regex)
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
802 " If the current line starts with a leading operator, keep its indent
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
803 " and keep looking for an MSL.
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
804 let msl = lnum
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
805 elseif s:Match(lnum, s:splat_regex)
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
806 " If the above line looks like the "*" of a splat, use the current one's
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
807 " indentation.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
808 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
809 " Example:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
810 " Hash[*
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
811 " method_call do
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
812 " something
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
813 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
814 return msl
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
815 elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
816 \ s:Match(msl, s:non_bracket_continuation_regex)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
817 " If the current line is a non-bracket continuation and so is the
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
818 " previous one, keep its indent and continue looking for an MSL.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
819 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
820 " Example:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
821 " method_call one,
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
822 " two,
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
823 " three
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
824 "
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
825 let msl = lnum
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
826 elseif s:Match(lnum, s:dot_continuation_regex) &&
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
827 \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
828 " If the current line is a bracket continuation or a block-starter, but
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
829 " the previous is a dot, keep going to see if the previous line is the
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
830 " start of another continuation.
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
831 "
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
832 " Example:
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
833 " parent.
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
834 " method_call {
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
835 " three
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
836 "
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
837 let msl = lnum
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
838 elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
839 \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
840 " If the current line is a bracket continuation or a block-starter, but
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
841 " the previous is a non-bracket one, respect the previous' indentation,
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
842 " and stop here.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
843 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
844 " Example:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
845 " method_call one,
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
846 " two {
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
847 " three
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
848 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
849 return lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
850 elseif s:Match(lnum, s:bracket_continuation_regex) &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
851 \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
852 " If both lines are bracket continuations (the current may also be a
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
853 " block-starter), use the current one's and stop here
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
854 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
855 " Example:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
856 " method_call(
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
857 " other_method_call(
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
858 " foo
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
859 return msl
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
860 elseif s:Match(lnum, s:block_regex) &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
861 \ !s:Match(msl, s:continuation_regex) &&
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
862 \ !s:Match(msl, s:block_continuation_regex)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
863 " If the previous line is a block-starter and the current one is
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
864 " mostly ordinary, use the current one as the MSL.
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
865 "
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
866 " Example:
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
867 " method_call do
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
868 " something
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
869 " something_else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
870 return msl
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
871 else
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
872 let col = match(line, s:continuation_regex) + 1
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
873 if (col > 0 && !s:IsInStringOrComment(lnum, col))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
874 \ || s:IsInString(lnum, strlen(line))
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
875 let msl = lnum
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
876 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
877 break
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
878 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
879 endif
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
880
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
881 let lnum = s:PrevNonBlankNonString(lnum - 1)
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
882 endwhile
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
883 return msl
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
884 endfunction
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
885
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
886 " Check if line 'lnum' has more opening brackets than closing ones.
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
887 function! s:ExtraBrackets(lnum) abort
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
888 let opening = {'parentheses': [], 'braces': [], 'brackets': []}
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
889 let closing = {'parentheses': [], 'braces': [], 'brackets': []}
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
890
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
891 let line = getline(a:lnum)
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
892 let pos = match(line, '[][(){}]', 0)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
893
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
894 " Save any encountered opening brackets, and remove them once a matching
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
895 " closing one has been found. If a closing bracket shows up that doesn't
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
896 " close anything, save it for later.
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
897 while pos != -1
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
898 if !s:IsInStringOrComment(a:lnum, pos + 1)
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
899 if line[pos] == '('
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
900 call add(opening.parentheses, {'type': '(', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
901 elseif line[pos] == ')'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
902 if empty(opening.parentheses)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
903 call add(closing.parentheses, {'type': ')', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
904 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
905 let opening.parentheses = opening.parentheses[0:-2]
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
906 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
907 elseif line[pos] == '{'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
908 call add(opening.braces, {'type': '{', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
909 elseif line[pos] == '}'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
910 if empty(opening.braces)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
911 call add(closing.braces, {'type': '}', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
912 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
913 let opening.braces = opening.braces[0:-2]
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
914 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
915 elseif line[pos] == '['
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
916 call add(opening.brackets, {'type': '[', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
917 elseif line[pos] == ']'
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
918 if empty(opening.brackets)
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
919 call add(closing.brackets, {'type': ']', 'pos': pos})
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
920 else
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
921 let opening.brackets = opening.brackets[0:-2]
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
922 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
923 endif
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
924 endif
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
925
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
926 let pos = match(line, '[][(){}]', pos + 1)
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
927 endwhile
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
928
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
929 " Find the rightmost brackets, since they're the ones that are important in
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
930 " both opening and closing cases
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
931 let rightmost_opening = {'type': '(', 'pos': -1}
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
932 let rightmost_closing = {'type': ')', 'pos': -1}
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
933
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
934 for opening in opening.parentheses + opening.braces + opening.brackets
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
935 if opening.pos > rightmost_opening.pos
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
936 let rightmost_opening = opening
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
937 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
938 endfor
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
939
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
940 for closing in closing.parentheses + closing.braces + closing.brackets
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
941 if closing.pos > rightmost_closing.pos
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
942 let rightmost_closing = closing
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
943 endif
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
944 endfor
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
945
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
946 return [rightmost_opening, rightmost_closing]
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
947 endfunction
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
948
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
949 function! s:Match(lnum, regex) abort
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
950 let line = getline(a:lnum)
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
951 let offset = match(line, '\C'.a:regex)
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
952 let col = offset + 1
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
953
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
954 while offset > -1 && s:IsInStringOrComment(a:lnum, col)
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
955 let offset = match(line, '\C'.a:regex, offset + 1)
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
956 let col = offset + 1
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
957 endwhile
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
958
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
959 if offset > -1
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
960 return col
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
961 else
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
962 return 0
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
963 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
964 endfunction
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
965
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
966 " Locates the containing class/module's definition line, ignoring nested classes
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
967 " along the way.
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
968 "
15512
f0f06837a699 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
969 function! s:FindContainingClass() abort
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
970 let saved_position = getpos('.')
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
971
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
972 while searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
973 \ s:end_skip_expr) > 0
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
974 if expand('<cword>') =~# '\<class\|module\>'
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
975 let found_lnum = line('.')
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
976 call setpos('.', saved_position)
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
977 return found_lnum
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
978 endif
10272
57b2b8268d3a commit https://github.com/vim/vim/commit/4575876dc865d4160f20d61bd822fbe7cafbec41
Christian Brabandt <cb@256bit.org>
parents: 10048
diff changeset
979 endwhile
10048
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
980
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
981 call setpos('.', saved_position)
43efa4f5a8ea commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents: 4869
diff changeset
982 return 0
530
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
983 endfunction
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
984
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
985 " }}}1
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
986
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
987 let &cpo = s:cpo_save
339999b511a0 updated for version 7.0148
vimboss
parents: 7
diff changeset
988 unlet s:cpo_save
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 843
diff changeset
989
4869
a5352e73dc00 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2225
diff changeset
990 " vim:set sw=2 sts=2 ts=8 et: