From 352ee0761ced17612d751bd568c888c78d279e9f Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Fri, 10 May 2024 08:55:56 +0200 Subject: lua: allow changing the displayed file of a window Change the file displayed in a window by writing the new file name to the window's file member. This is useful to change the displayed file during events. Using the edit command during an event caused by a pervious edit command causes a double free. --- vis.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'vis.c') diff --git a/vis.c b/vis.c index 0c05558..dca90c1 100644 --- a/vis.c +++ b/vis.c @@ -505,6 +505,18 @@ bool vis_window_reload(Win *win) { return true; } +bool vis_window_change_file(Win *win, const char* filename) { + File *file = file_new(win->vis, filename); + if (!file) + return false; + file->refcount++; + if (win->file) + file_free(win->vis, win->file); + win->file = file; + view_reload(win->view, file->text); + return true; +} + bool vis_window_split(Win *original) { vis_doupdates(original->vis, false); Win *win = window_new_file(original->vis, original->file, UI_OPTION_STATUSBAR); -- cgit v1.2.3