vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 0098c4005d67cb1c452e90b1e2f2be66bb03c1c9 parent 7711dcd67bf69610b024035f455c8d699d63c1fa Author: Marc André Tanner <mat@brain-dump.org> Date: Tue, 29 Dec 2020 15:56:03 +0100 vis-lua: provide file.permission property These are the permission bits of struct stat's st_mode field at the time of the most recent load/save. Close #861 Diffstat:
| M | vis-lua.c | | | 10 | ++++++++++ |
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/vis-lua.c b/vis-lua.c @@ -2097,6 +2097,10 @@ static const struct luaL_Reg window_selection_funcs[] = { * File state. * @tfield bool modified whether the file contains unsaved changes */ +/*** + * File permission. + * @tfield int permission the file permission bits as of the most recent load/save + */ static int file_index(lua_State *L) { File *file = obj_ref_check(L, 1, VIS_LUA_TYPE_FILE); @@ -2126,6 +2130,12 @@ static int file_index(lua_State *L) { lua_pushboolean(L, text_modified(file->text)); return 1; } + + if (strcmp(key, "permission") == 0) { + struct stat stat = text_stat(file->text); + lua_pushunsigned(L, stat.st_mode & 0777); + return 1; + } } return index_common(L);