From 0791cac97ee689195e593cfca89c0b63fb721479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 22 Nov 2016 00:15:32 +0100 Subject: vis-lua: introduce pre-save hook The first argument is the file object while the second argument denotes the full path to which it will be written. Path might be `nil` if the file is going to be written to stdout. The Lua function is expected to return a boolean value indicating whether the write operation should proceed or be aborted. --- sam.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sam.c') diff --git a/sam.c b/sam.c index 4bd10d5..1b30258 100644 --- a/sam.c +++ b/sam.c @@ -1295,6 +1295,11 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs return false; } + if (!vis_event_emit(vis, VIS_EVENT_FILE_SAVE_PRE, file, *name) && cmd->flags != '!') { + vis_info_show(vis, "Rejected write to `%s' by pre-save hook", *name); + return false; + } + TextSave *ctx = text_save_begin(text, *name); if (!ctx) { vis_info_show(vis, "Can't write `%s': %s", *name, strerror(errno)); -- cgit v1.2.3