fix(messages): proper multiline Lua print() messages #31205

Problem:  Separate message emitted for each newline present in Lua
          print() arguments.
Solution: Make msg_multiline() handle NUL bytes. Refactor print() to use
          msg_multiline(). Refactor vim.print() to use print().
This commit is contained in:
luukvbaal
2024-11-17 19:21:50 +01:00
committed by GitHub
parent 6ea45031d5
commit e025f5a5b3
9 changed files with 64 additions and 77 deletions

View File

@@ -1151,21 +1151,16 @@ end
--- @param ... any
--- @return any # given arguments.
function vim.print(...)
if vim.in_fast_event() then
print(...)
return ...
end
local msg = {}
for i = 1, select('#', ...) do
local o = select(i, ...)
if type(o) == 'string' then
vim.api.nvim_out_write(o)
table.insert(msg, o)
else
vim.api.nvim_out_write(vim.inspect(o, { newline = '\n', indent = ' ' }))
table.insert(msg, vim.inspect(o, { newline = '\n', indent = ' ' }))
end
vim.api.nvim_out_write('\n')
end
print(table.concat(msg, '\n'))
return ...
end