feat(ex_cmds): ranged :lua #27167

:{range}lua executes the specified lines in the current buffer as
Lua code, regardless of its extension or 'filetype'.

Close #27103
This commit is contained in:
luukvbaal
2024-01-27 02:00:50 +01:00
committed by GitHub
parent 0892c080d1
commit c2433589dc
6 changed files with 48 additions and 5 deletions

View File

@@ -55,6 +55,12 @@ describe(':lua command', function()
)
end)
it('throws catchable errors', function()
for _, cmd in ipairs({ 'lua', '1lua chunk' }) do
eq(
'Vim(lua):E475: Invalid argument: exactly one of {chunk} and {range} required',
pcall_err(command, cmd)
)
end
eq(
[[Vim(lua):E5107: Error loading lua [string ":lua"]:0: unexpected symbol near ')']],
pcall_err(command, 'lua ()')
@@ -192,6 +198,25 @@ describe(':lua command', function()
exec_capture('=x(false)')
)
end)
it('works with range in current buffer', function()
local screen = Screen.new(40, 10)
screen:attach()
api.nvim_buf_set_lines(0, 0, 0, 0, { 'function x() print "hello" end', 'x()' })
feed(':1,2lua<CR>')
screen:expect {
grid = [[
function x() print "hello" end |
x() |
^ |
{1:~ }|*6
hello |
]],
attr_ids = {
[1] = { foreground = Screen.colors.Blue, bold = true },
},
}
end)
end)
describe(':luado command', function()