Merge pull request #14318 from chentau/extmark_luado

extmark: splice extmarks on :luado
This commit is contained in:
Björn Linse 2021-04-13 15:00:42 +02:00 committed by GitHub
commit c9817603cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -17,6 +17,7 @@
#include "nvim/api/vim.h" #include "nvim/api/vim.h"
#include "nvim/msgpack_rpc/channel.h" #include "nvim/msgpack_rpc/channel.h"
#include "nvim/vim.h" #include "nvim/vim.h"
#include "nvim/extmark.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/ex_cmds2.h" #include "nvim/ex_cmds2.h"
#include "nvim/map.h" #include "nvim/map.h"
@ -1243,13 +1244,16 @@ void ex_luado(exarg_T *const eap)
break; break;
} }
lua_pushvalue(lstate, -1); lua_pushvalue(lstate, -1);
lua_pushstring(lstate, (const char *)ml_get_buf(curbuf, l, false)); const char *old_line = (const char *)ml_get_buf(curbuf, l, false);
lua_pushstring(lstate, old_line);
lua_pushnumber(lstate, (lua_Number)l); lua_pushnumber(lstate, (lua_Number)l);
if (lua_pcall(lstate, 2, 1, 0)) { if (lua_pcall(lstate, 2, 1, 0)) {
nlua_error(lstate, _("E5111: Error calling lua: %.*s")); nlua_error(lstate, _("E5111: Error calling lua: %.*s"));
break; break;
} }
if (lua_isstring(lstate, -1)) { if (lua_isstring(lstate, -1)) {
size_t old_line_len = STRLEN(old_line);
size_t new_line_len; size_t new_line_len;
const char *const new_line = lua_tolstring(lstate, -1, &new_line_len); const char *const new_line = lua_tolstring(lstate, -1, &new_line_len);
char *const new_line_transformed = xmemdupz(new_line, new_line_len); char *const new_line_transformed = xmemdupz(new_line, new_line_len);
@ -1259,7 +1263,7 @@ void ex_luado(exarg_T *const eap)
} }
} }
ml_replace(l, (char_u *)new_line_transformed, false); ml_replace(l, (char_u *)new_line_transformed, false);
changed_bytes(l, 0); inserted_bytes(l, 0, (int)old_line_len, (int)new_line_len);
} }
lua_pop(lstate, 1); lua_pop(lstate, 1);
} }

View File

@ -871,6 +871,24 @@ describe('lua: nvim_buf_attach on_bytes', function()
end) end)
it(":luado", function()
local check_events = setup_eventcheck(verify, {"abc", "12345"})
command(".luado return 'a'")
check_events {
{ "test1", "bytes", 1, 3, 0, 0, 0, 0, 3, 3, 0, 1, 1 };
}
command("luado return 10")
check_events {
{ "test1", "bytes", 1, 4, 0, 0, 0, 0, 1, 1, 0, 2, 2 };
{ "test1", "bytes", 1, 5, 1, 0, 3, 0, 5, 5, 0, 2, 2 };
}
end)
teardown(function() teardown(function()
os.remove "Xtest-reload" os.remove "Xtest-reload"
os.remove "Xtest-undofile" os.remove "Xtest-undofile"