aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchentau <tchen1998@gmail.com>2021-04-07 22:45:08 -0700
committerchentau <tchen1998@gmail.com>2021-04-12 11:33:50 -0700
commitff43d9597e26d202051f977fe57058797b9f1c99 (patch)
treecfc8c593eb611373b824f2c5fa4e5ca1be7a4a2d
parentdde89730b453fd2b84860e58bb8893c92417128b (diff)
downloadrneovim-ff43d9597e26d202051f977fe57058797b9f1c99.tar.gz
rneovim-ff43d9597e26d202051f977fe57058797b9f1c99.tar.bz2
rneovim-ff43d9597e26d202051f977fe57058797b9f1c99.zip
extmark: splice extmarks on :luado
-rw-r--r--src/nvim/lua/executor.c8
-rw-r--r--test/functional/lua/buffer_updates_spec.lua18
2 files changed, 24 insertions, 2 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 03d178467b..eae73b337c 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -16,6 +16,7 @@
#include "nvim/api/vim.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/vim.h"
+#include "nvim/extmark.h"
#include "nvim/ex_getln.h"
#include "nvim/ex_cmds2.h"
#include "nvim/message.h"
@@ -1213,13 +1214,16 @@ void ex_luado(exarg_T *const eap)
break;
}
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);
if (lua_pcall(lstate, 2, 1, 0)) {
nlua_error(lstate, _("E5111: Error calling lua: %.*s"));
break;
}
if (lua_isstring(lstate, -1)) {
+ size_t old_line_len = STRLEN(old_line);
+
size_t 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);
@@ -1229,7 +1233,7 @@ void ex_luado(exarg_T *const eap)
}
}
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);
}
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 6d7d9b4d8b..e79a5b7673 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -802,6 +802,24 @@ describe('lua: nvim_buf_attach on_bytes', function()
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()
os.remove "Xtest-reload"
os.remove "Xtest-undofile"