From 5b6eed51f8dff5a9fa00e581d4277e198231fedd Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Thu, 25 Sep 2025 16:17:52 +0200 Subject: [PATCH] plugin: expose NewTabFromBuffer to Lua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no really good way to create a new tab that’s not bound to a specific file on disk without this function. Now you can create a new buffer from string, pass it to this function and add the resulting tab to the tabs list. It’s still not particularly ergonomic, but at least it’s possible with a few lines of boilerplate. --- cmd/micro/initlua.go | 1 + runtime/help/plugins.md | 3 +++ 2 files changed, 4 insertions(+) diff --git a/cmd/micro/initlua.go b/cmd/micro/initlua.go index 7eac563763..d196238241 100644 --- a/cmd/micro/initlua.go +++ b/cmd/micro/initlua.go @@ -55,6 +55,7 @@ func luaImportMicro() *lua.LTable { ulua.L.SetField(pkg, "Tabs", luar.New(ulua.L, func() *action.TabList { return action.Tabs })) + ulua.L.SetField(pkg, "NewTabFromBuffer", luar.New(ulua.L, action.NewTabFromBuffer)) ulua.L.SetField(pkg, "After", luar.New(ulua.L, func(t time.Duration, f func()) { time.AfterFunc(t, func() { timerChan <- f diff --git a/runtime/help/plugins.md b/runtime/help/plugins.md index c683804f50..3512c447de 100644 --- a/runtime/help/plugins.md +++ b/runtime/help/plugins.md @@ -147,6 +147,9 @@ The packages and their contents are listed below (in Go type signatures): - `Tabs() *TabList`: returns the global tab list. + - `NewTabFromBuffer(x, y, width, height int, buf *Buffer) *Tab`: creates + a new tab from the given buffer with the specified dimensions and position. + - `After(t time.Duration, f func())`: run function `f` in the background after time `t` elapses. See https://pkg.go.dev/time#Duration for the usage of `time.Duration`.