diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2020-08-14 17:00:19 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2020-08-14 17:05:14 +0200 |
| commit | 4eac3196449db433cfe921eef30818d3cf114b62 (patch) | |
| tree | 66da04487ef7f58008c16345ccb4bcb7227626de /vis-lua.c | |
| parent | 84c26208176238a5116b44ac3b6115bab64d48d5 (diff) | |
| download | vis-4eac3196449db433cfe921eef30818d3cf114b62.tar.gz vis-4eac3196449db433cfe921eef30818d3cf114b62.tar.xz | |
vis-lua: make file.modified assignable
We fake a modification by doing an insertion followed by a deletion
which does not actually change the buffer content.
Close #855
Diffstat (limited to 'vis-lua.c')
| -rw-r--r-- | vis-lua.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -2100,6 +2100,27 @@ static int file_index(lua_State *L) { return index_common(L); } +static int file_newindex(lua_State *L) { + File *file = obj_ref_check(L, 1, VIS_LUA_TYPE_FILE); + + if (lua_isstring(L, 2)) { + const char *key = lua_tostring(L, 2); + + if (strcmp(key, "modified") == 0) { + bool modified = lua_isboolean(L, 3) && lua_toboolean(L, 3); + if (modified) { + text_insert(file->text, 0, " ", 1); + text_delete(file->text, 0, 1); + } else { + text_save(file->text, NULL); + } + return 0; + } + } + + return newindex_common(L); +} + /*** * Insert data at position. * @function insert @@ -2281,7 +2302,7 @@ static int file_text_object(lua_State *L) { static const struct luaL_Reg file_funcs[] = { { "__index", file_index }, - { "__newindex", newindex_common }, + { "__newindex", file_newindex }, { "insert", file_insert }, { "delete", file_delete }, { "lines_iterator", file_lines_iterator }, |
