From 6c519e91c684838bebcc6d49d894af956f6815b4 Mon Sep 17 00:00:00 2001 From: Randy Palamar Date: Mon, 8 Dec 2025 13:09:06 -0700 Subject: vis-lua: add file:snapshot method A number of plugins, for example vis-spellcheck[0], want to perform bulk edits on the file text. They may desire for those edits to be split into multiple undo/redo points. This is achievable by switching the mode between insert and normal mode but that has other side effects. Instead introduce a method of doing this directly. [0]: https://gitlab.com/muhq/vis-spellcheck --- vis-lua.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vis-lua.c b/vis-lua.c index 7986503..e226d18 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -2674,6 +2674,17 @@ static int file_delete(lua_State *L) { return 1; } +/*** + * Create a restore point for undo/redo. + * + * @function snapshot + */ +static int file_snapshot(lua_State *L) { + File *file = obj_ref_check(L, 1, VIS_LUA_TYPE_FILE); + text_snapshot(file->text); + return 0; +} + /*** * Create an iterator over all lines of the file. * @@ -2817,6 +2828,7 @@ static const struct luaL_Reg file_funcs[] = { { "__newindex", file_newindex }, { "insert", file_insert }, { "delete", file_delete }, + { "snapshot", file_snapshot }, { "lines_iterator", file_lines_iterator }, { "content", file_content }, { "mark_set", file_mark_set }, -- cgit v1.2.3