Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions indent/lua.vim
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ function GetLuaIndent()
let i = -1
endif

" special case: end}) -- line after end of call w/ anon func should outdent again
if i >= 0 && contents_prev =~# s:anon_func_end
let i -= 1
endif

" restore cursor
call setpos(".", original_cursor_pos)

Expand Down
118 changes: 118 additions & 0 deletions test/indent.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
Before:
setlocal expandtab shiftwidth=4 tabstop=4

Given lua (chained functions):
if true then
local data = self.kitchen
:getCheese()
:enjoyCheese(self
:getHead()
:getMouth())
end

Do (reindent):
gg=G

Expect lua (indented chained functions):
if true then
local data = self.kitchen
:getCheese()
:enjoyCheese(self
:getHead()
:getMouth())
end

Given lua (chained anonymous function arguments):
if false then
local data = self.kitchen
:eatCheese({fn = function()
return 10
end})
:digestCheese(function()
return 1
end)

self:Func()
end

Do (reindent):
gg=G

Expect lua (indented chained anonymous function arguments):
if false then
local data = self.kitchen
:eatCheese({fn = function()
return 10
end})
:digestCheese(function()
return 1
end)

self:Func()
end


Given lua (anonymous function as third argument):
local p = self.input:getActiveControls(
5,
10,
function(value)
local name_remap = {
axis = {
left = "Left Stick",
},
}
return name_remap[value] or value
end)
print(p)


Do (reindent):
gg=G

Expect lua (function begin/end line up and body indents):
local p = self.input:getActiveControls(
5,
10,
function(value)
local name_remap = {
axis = {
left = "Left Stick",
},
}
return name_remap[value] or value
end)
print(p)


Do (put first arg on call line, reindent):
ggJx=G

Expect lua (function indent matches first newline argument):
local p = self.input:getActiveControls(5,
10,
function(value)
local name_remap = {
axis = {
left = "Left Stick",
},
}
return name_remap[value] or value
end)
print(p)


Do (put all args on one line, reindent):
ggJx3J=G

Expect lua (function indent combines with parens indent):
local p = self.input:getActiveControls(5, 10, function(value)
local name_remap = {
axis = {
left = "Left Stick",
},
}
return name_remap[value] or value
end)
print(p)