@@ -89,6 +89,9 @@ let s:ruby_indent_keywords =
89
89
\ ' \|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' .
90
90
\ ' \<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>'
91
91
92
+ " Def without an end clause: def method_call(...) = <expression>
93
+ let s: ruby_endless_def = ' \<def\s\+\k\+[!?]\=\%((.*)\|\s\)\s*='
94
+
92
95
" Regex used for words that, at the start of a line, remove a level of indent.
93
96
let s: ruby_deindent_keywords =
94
97
\ ' ^\s*\zs\<\%(ensure\|else\|rescue\|elsif\|when\|end\):\@!\>'
@@ -108,10 +111,26 @@ let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue:\@!\>
108
111
" Regex that defines the end-match for the 'end' keyword.
109
112
let s: end_end_regex = ' \%(^\|[^.:@$]\)\@<=\<end:\@!\>'
110
113
111
- " Expression used for searchpair() call for finding match for 'end' keyword.
112
- let s: end_skip_expr = s: skip_expr .
113
- \ ' || (expand("<cword>") == "do"' .
114
- \ ' && getline(".") =~ "^\\s*\\<\\(while\\|until\\|for\\):\\@!\\>")'
114
+ " Expression used for searchpair() call for finding a match for an 'end' keyword.
115
+ function ! s: EndSkipExpr ()
116
+ if eval (s: skip_expr )
117
+ return 1
118
+ elseif expand (' <cword>' ) == ' do'
119
+ \ && getline (" ." ) = ~ ' ^\s*\<\(while\|until\|for\):\@!\>'
120
+ return 1
121
+ elseif getline (' .' ) = ~ s: ruby_endless_def
122
+ return 1
123
+ elseif getline (' .' ) = ~ ' \<def\s\+\k\+[!?]\=([^)]*$'
124
+ " Then it's a `def method(` with a possible `) =` later
125
+ call search (' \<def\s\+\k\+\zs(' , ' W' , line (' .' ))
126
+ normal ! %
127
+ return getline (' .' ) = ~ ' )\s*='
128
+ else
129
+ return 0
130
+ endif
131
+ endfunction
132
+
133
+ let s: end_skip_expr = function (' s:EndSkipExpr' )
115
134
116
135
" Regex that defines continuation lines, not including (, {, or [.
117
136
let s: non_bracket_continuation_regex =
@@ -571,6 +590,11 @@ function! s:AfterUnbalancedBracket(pline_info) abort
571
590
call cursor (info.plnum, closing.pos + 1 )
572
591
normal ! %
573
592
593
+ if strpart (info.pline, closing.pos) = ~ ' ^)\s*='
594
+ " special case: the closing `) =` of an endless def
595
+ return indent (s: GetMSL (line (' .' )))
596
+ endif
597
+
574
598
if s: Match (line (' .' ), s: ruby_indent_keywords )
575
599
return indent (' .' ) + info.sw
576
600
else
@@ -609,7 +633,7 @@ function! s:AfterIndentKeyword(pline_info) abort
609
633
let info = a: pline_info
610
634
let col = s: Match (info.plnum, s: ruby_indent_keywords )
611
635
612
- if col > 0
636
+ if col > 0 && s: Match (info.plnum, s: ruby_endless_def ) <= 0
613
637
call cursor (info.plnum, col )
614
638
let ind = virtcol (' .' ) - 1 + info.sw
615
639
" TODO: make this better (we need to count them) (or, if a searchpair
@@ -656,7 +680,7 @@ function! s:IndentingKeywordInMSL(msl_info) abort
656
680
" TODO: this does not take into account contrived things such as
657
681
" module Foo; class Bar; end
658
682
let col = s: Match (info.plnum_msl, s: ruby_indent_keywords )
659
- if col > 0
683
+ if col > 0 && s: Match (info.plnum_msl, s: ruby_endless_def ) <= 0
660
684
let ind = indent (info.plnum_msl) + info.sw
661
685
if s: Match (info.plnum_msl, s: end_end_regex )
662
686
let ind = ind - info.sw
0 commit comments