Skip to content

Commit 04e7f95

Browse files
committed
Add support for indenting method chaining
Support indenting chained method calls: local colon_out = self.kitchen :getContents() :getCheese() :enjoyCheese(self :mouth() :open() :extendTongue()) :eatCheese() :digestCheese() local dot_out = self.kitchen .getContents() .getCheese() .enjoyCheese(self .mouth() .open() .extendTongue()) .eatCheese() .digestCheese()
1 parent c7c5b70 commit 04e7f95

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

indent/lua.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ let s:close_patt = '\C\%(\<\%(end\|until\)\>\|)\|}\)'
2929
let s:anon_func_start = '\S\+\s*[({].*\<function\s*(.*)\s*$'
3030
let s:anon_func_end = '\<end\%(\s*[)}]\)\+'
3131

32+
let s:chained_func_call = "^\\v\\s*[:.]\\w+[({\"']"
33+
3234
" Expression used to check whether we should skip a match with searchpair().
3335
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~# 'luaComment\\|luaString'"
3436

@@ -98,6 +100,16 @@ function GetLuaIndent()
98100
let i += 1
99101
endif
100102

103+
" if the current line chains a function call to previous unchained line
104+
if contents_prev !~# s:chained_func_call && contents_cur =~# s:chained_func_call
105+
let i += 1
106+
endif
107+
108+
" if the current line chains a function call to previous unchained line
109+
if contents_prev =~# s:chained_func_call && contents_cur !~# s:chained_func_call
110+
let i -= 1
111+
endif
112+
101113
" special case: call(with, {anon = function() -- should indent only once
102114
if i > 1 && contents_prev =~# s:anon_func_start
103115
let i = 1

0 commit comments

Comments
 (0)