diff options
author | luukvbaal <luukvbaal@gmail.com> | 2024-11-17 19:21:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-17 10:21:50 -0800 |
commit | e025f5a5b30a1ef92e88fed0f0c548d2240d30c0 (patch) | |
tree | 9ae569b85a6f1506a402556e44b6b6a81485efbc /src/nvim/lua/executor.c | |
parent | 6ea45031d5841d3227c545f213d0903b951e40be (diff) | |
download | rneovim-e025f5a5b30a1ef92e88fed0f0c548d2240d30c0.tar.gz rneovim-e025f5a5b30a1ef92e88fed0f0c548d2240d30c0.tar.bz2 rneovim-e025f5a5b30a1ef92e88fed0f0c548d2240d30c0.zip |
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().
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 39 |
1 files changed, 4 insertions, 35 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 15f70fb725..c4fa8b0fff 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -954,41 +954,10 @@ static void nlua_common_free_all_mem(lua_State *lstate) static void nlua_print_event(void **argv) { - char *str = argv[0]; - const size_t len = (size_t)(intptr_t)argv[1] - 1; // exclude final NUL - - for (size_t i = 0; i < len;) { - if (got_int) { - break; - } - const size_t start = i; - while (i < len) { - switch (str[i]) { - case NUL: - str[i] = NL; - i++; - continue; - case NL: - // TODO(bfredl): use proper multiline msg? Probably should implement - // print() in lua in terms of nvim_message(), when it is available. - str[i] = NUL; - i++; - break; - default: - i++; - continue; - } - break; - } - msg(str + start, 0); - if (msg_silent == 0) { - msg_didout = true; // Make blank lines work properly - } - } - if (len && str[len - 1] == NUL) { // Last was newline - msg("", 0); - } - xfree(str); + HlMessage msg = KV_INITIAL_VALUE; + HlMessageChunk chunk = { { .data = argv[0], .size = (size_t)(intptr_t)argv[1] - 1 }, 0 }; + kv_push(msg, chunk); + msg_multihl(msg, "lua_print", true); } /// Print as a Vim message |