Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

btv.host

btv.host.name()

btv.host.name() -> the id of the app embedding this editor (what it named itself with, SessionOptions::host), or nil when nothing does: the TUI, bemtvi-gui, the browser. It’s set before any config runs, so an init.lua can branch on it.

Defined in host.lua.

btv.host.send(name, payload)

btv.host.send(name, payload): send the app embedding this editor a message, which it gets as EditorEvent::Host { name, payload }. name is a non-empty string the app and the config agree on; payload is anything msgpack carries: nil, booleans, numbers, strings, and tables of them (a table whose keys are exactly 1..n goes as a list). Anything else in it (a function, a coroutine) raises.

Raises when no app embeds the editor (btv.host.name() is nil), so a config meant to run both ways checks that first:

if btv.host.name() then
  btv.keymap.set("n", "<leader>p", function()
    btv.host.send("preview", { file = btv.buf.name(0) })
  end)
end

Defined in host.lua.

btv.host.forward(events)

btv.host.forward(events): tell the app embedding this editor about edits as they happen, as btv.host.send messages. events is a list of:

"changed"  a buffer's text changed: { buf, name, modified }, once typing pauses
           for 200 ms (the last buffer changed wins)
"wrote"    a buffer was written: { buf, name }

name is the buffer’s file ("" for one with none). The text isn’t sent — a large buffer on every keystroke would stall the editor; the app asks for what it needs (btv.buf.lines(buf, 0, -1) through its handle). Calling it again replaces what it forwards (btv.host.forward({}) stops). Raises when no app embeds the editor, or for an event it doesn’t know.

Defined in host.lua.