aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandy Palamar <randy@rnpnr.xyz>2025-12-08 13:09:06 -0700
committerRandy Palamar <randy@rnpnr.xyz>2025-12-09 09:52:14 -0700
commit6c519e91c684838bebcc6d49d894af956f6815b4 (patch)
tree0bf7da238ca7f66d769b1924cababcf6c50e5ea3
parent82865164562201d6a21b25c32273e75b65e2c7a2 (diff)
downloadvis-6c519e91c684838bebcc6d49d894af956f6815b4.tar.gz
vis-6c519e91c684838bebcc6d49d894af956f6815b4.tar.xz
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
-rw-r--r--vis-lua.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/vis-lua.c b/vis-lua.c
index 7986503..e226d18 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -2675,6 +2675,17 @@ static int file_delete(lua_State *L) {
}
/***
+ * 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.
*
* For large files this is probably faster than @{lines}.
@@ -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 },