~martanne/devel

[RFC vis] lua: allow Lua to change displayed files v1 SUPERSEDED

Florian Fischer: 1
 allow lua to change a windows file

 3 files changed, 16 insertions(+), 0 deletions(-)
Heyhey!

Florian Fischer <florian.fischer@muhq.space> wrote:
Next
Florian Fischer <florian.fischer@muhq.space> wrote:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~martanne/devel/patches/51585/mbox | git am -3
Learn more about email & git

[PATCH] allow lua to change a windows file Export this patch

---
 vis-lua.c |  3 +++
 vis.c     | 11 +++++++++++
 vis.h     |  2 ++
 3 files changed, 16 insertions(+)

diff --git a/vis-lua.c b/vis-lua.c
index 4d783c5d..cb328b66 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -2058,6 +2058,9 @@ static int window_newindex(lua_State *L) {
			}
			lua_pop(L, 1);
			return ret;
		} else if (strcmp(key, "file") == 0 && lua_isstring(L, 3)) {
			const char* filename = strdup(lua_tostring(L, 3));
			vis_window_change_file(win, filename);
		}
	}

diff --git a/vis.c b/vis.c
index 0c05558a..7f005057 100644
--- a/vis.c
+++ b/vis.c
@@ -505,6 +505,17 @@ 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);
}

bool vis_window_split(Win *original) {
	vis_doupdates(original->vis, false);
	Win *win = window_new_file(original->vis, original->file, UI_OPTION_STATUSBAR);
diff --git a/vis.h b/vis.h
index 312e87c4..b7192c6f 100644
--- a/vis.h
+++ b/vis.h
@@ -212,6 +212,8 @@ bool vis_window_new(Vis*, const char *filename);
bool vis_window_new_fd(Vis*, int fd);
/** Reload the file currently displayed in the window from disk. */
bool vis_window_reload(Win*);
/** Change the file currently displayed in the window. */
bool vis_window_change_file(Win*, const char *filename);
/** Check whether closing the window would loose unsaved changes. */
bool vis_window_closable(Win*);
/** Close window, redraw user interface. */
-- 
2.45.0
Heyhey!

Florian Fischer <florian.fischer@muhq.space> wrote: