From adc0700dc4589e59de2c17a2f8cfc2ba2fb1181f Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 3 Oct 2026 13:20:33 +0200 Subject: fix(lua): regression with `print()` in headless mode This is a bunch of hacks so we can override msg_puts_printf specifically while still allowing redirecting and "normal" message flow to happen, as this still has observable side-effects (even with no screen attached, screenstring() is still valid..) fixes #42218 --- src/nvim/lua/executor.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/nvim/lua/executor.c') diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index a0b982ab0f..d076e53062 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1119,17 +1119,13 @@ static void nlua_common_free_all_mem(lua_State *lstate) static void nlua_print_event(void **argv) { msg_ext_no_fast(); - if (msg_use_printf() && on_print.type == kCallbackNone) { - msg_start(); // flush incomplete message - printf("%.*s\n", (int)(intptr_t)argv[1] - 1, (char *)argv[0]); - xfree(argv[0]); - } else { - HlMessage msg = KV_INITIAL_VALUE; - HlMessageChunk chunk = { { .data = argv[0], .size = (size_t)(intptr_t)argv[1] - 1 }, 0 }; - kv_push(msg, chunk); - bool needs_clear = false; - msg_multihl(NIL, msg, "lua_print", true, false, NULL, &needs_clear); - } + bool raw = msg_use_printf() && !redirecting() && on_print.type == kCallbackNone; + + HlMessage msg = KV_INITIAL_VALUE; + HlMessageChunk chunk = { { .data = argv[0], .size = (size_t)(intptr_t)argv[1] - 1 }, 0 }; + kv_push(msg, chunk); + bool needs_clear = false; + msg_multihl(NIL, msg, "lua_print", true, false, NULL, &needs_clear, raw); } /// Implements Lua print() as a Nvim message. -- cgit