Files
LLeMbas-IDE/nvim/plugin/llembas.lua
T
HomerandClaude Fable 5.2 102d68349f Neovim: the four bars — top, bottom, tree, and the right bar with settings lines, chat and prompt
One table of keys binds every action in two forms (the terminal's chords, and keys that always
arrive), and the bottom bar shows the form that works for the bar that has the focus. The prompt
says what Enter will do (ask, rewrite, add; Tab switches in an empty prompt) and carries the
selection or the cursor's line as its attachment. Mode, effort, suggestions, AI on or off and
the bars are remembered per directory with a machine-wide default.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-12-02 20:33:22 +00:00

90 lines
6.8 KiB
Lua

if vim.g.loaded_llembas then return end
vim.g.loaded_llembas = true
if vim.fn.has("nvim-0.10") == 0 then
vim.notify("llembas.nvim needs Neovim 0.10 or newer", vim.log.levels.WARN)
return
end
local function L() return require("llembas") end
local cmd = vim.api.nvim_create_user_command
cmd("LLeMbas", function() L().toggle() end, { desc = "LLeMbas: open or close the chat panel" })
cmd("LLeMbasAsk", function(o) L().ask(o.line1, o.line2, o.args) end,
{ range = true, nargs = "*", desc = "LLeMbas: ask about the selected lines" })
cmd("LLeMbasEdit", function(o) L().edit(o.line1, o.line2, o.args) end,
{ range = true, nargs = "*", desc = "LLeMbas: have the selected lines rewritten" })
cmd("LLeMbasGenerate", function(o) L().generate(o.args) end,
{ nargs = "*", desc = "LLeMbas: generate code at the cursor" })
cmd("LLeMbasCancelEdit", function() require("llembas.diff").cancel() end,
{ desc = "LLeMbas: cancel an in-flight rewrite or generation" })
cmd("LLeMbasStop", function() L().stop() end, { desc = "LLeMbas: stop the running turn" })
cmd("LLeMbasNew", function(o) L().new(o.bang) end, { bang = true, desc = "LLeMbas: start a new session (! also while a turn hangs)" })
cmd("LLeMbasCompact", function() L().compact() end, { desc = "LLeMbas: compact session context" })
cmd("LLeMbasMode", function(o) L().mode(o.args) end,
{ nargs = "?", complete = function() return L().mode_ids() end, desc = "LLeMbas: change the mode" })
cmd("LLeMbasModel", function(o) L().model(o.args) end, { nargs = "?", desc = "LLeMbas: show or change the model" })
cmd("LLeMbasAccept", function(o) require("llembas.diff").accept(o.bang) end, { bang = true, desc = "LLeMbas: accept the change under the cursor (! all)" })
cmd("LLeMbasReject", function(o) require("llembas.diff").reject(o.bang) end, { bang = true, desc = "LLeMbas: reject the change under the cursor (! all)" })
cmd("LLeMbasNextHunk", function() require("llembas.diff").next_hunk() end, { desc = "LLeMbas: jump to next proposed change" })
cmd("LLeMbasPrevHunk", function() require("llembas.diff").prev_hunk() end, { desc = "LLeMbas: jump to previous proposed change" })
local function on_off(arg) if arg == "on" then return true elseif arg == "off" then return false end end
local function on_off_words() return { "on", "off" } end
cmd("LLeMbasAutocomplete", function(o) L().autocomplete(on_off(o.args)) end,
{ nargs = "?", complete = on_off_words, desc = "LLeMbas: suggestions as you type on or off" })
cmd("LLeMbasAI", function(o) L().ai(on_off(o.args)) end,
{ nargs = "?", complete = on_off_words, desc = "LLeMbas: everything of LLeMbas on or off (off: a plain editor)" })
cmd("LLeMbasEffort", function(o) L().effort(o.args) end,
{ nargs = "?", complete = function() return L().EFFORTS end, desc = "LLeMbas: the effort of the conversation" })
cmd("LLeMbasPrompt", function(o)
local intent = o.args ~= "" and o.args or nil
if o.range > 0 then L().prompt({ intent = intent, first = o.line1, last = o.line2 }) else L().prompt({ intent = intent }) end
end, { range = true, nargs = "?", complete = function() return { "ask", "rewrite", "add" } end,
desc = "LLeMbas: to the prompt with the lines or the cursor's line (ask, rewrite or add)" })
cmd("LLeMbasMenu", function() L().menu() end, { desc = "LLeMbas: every command and every setting" })
cmd("LLeMbasTree", function() require("llembas.layout").toggle("tree") end, { desc = "LLeMbas: the file tree, show and hide" })
cmd("LLeMbasBars", function(o)
local layout = require("llembas.layout")
local a = o.fargs
if #a == 0 then return L().setup({ bars = not layout.options().on and true or false }) end
if a[1] == "on" or a[1] == "off" then return L().setup({ bars = a[1] == "on" }) end
layout.toggle(a[1], on_off(a[2]))
end, { nargs = "*", complete = function() return { "on", "off", "top", "bottom", "tree", "chat" } end,
desc = "LLeMbas: the four bars on or off, or one of them (top, bottom, tree, chat) [on|off]" })
cmd("LLeMbasAutocompleteTokens", function(o) L().autocomplete_tokens(o.args) end,
{ nargs = "?", complete = function() return { "auto", "words", "line", "block", "file", "24", "64", "256", "1024", "2048" } end,
desc = "LLeMbas: set autocomplete max tokens or prediction length preset" })
cmd("LLeMbasAutocompleteInstructions", function(o) L().autocomplete_instructions(o.args) end,
{ nargs = "*", desc = "LLeMbas: set custom instructions for autocomplete (- clears)" })
cmd("LLeMbasAutocompleteModel", function(o) L().autocomplete_model(o.args, o.bang) end,
{ nargs = "?", bang = true, desc = "LLeMbas: the autocomplete model (! for this editor only, - for the default)" })
cmd("LLeMbasMainModel", function(o) L().main_model(o.args) end,
{ nargs = "?", desc = "LLeMbas: the model for chat and rewriting, saved in your account (? shows both)" })
cmd("LLeMbasOpen", function() L().open_shown() end, { desc = "LLeMbas: open the file the agent showed last" })
cmd("LLeMbasFiles", function(o) L().files(o.args, o.bang) end,
{ nargs = "?", bang = true, desc = "LLeMbas: search project files and attach @path (! opens file in editor)" })
cmd("LLeMbasOpenFile", function(o) L().files(o.args, true) end,
{ nargs = "?", desc = "LLeMbas: open a file from the project index" })
cmd("LLeMbasCommands", function() L().commands() end, { desc = "LLeMbas: pick a /command or skill" })
cmd("LLeMbasSessions", function() L().sessions() end, { desc = "LLeMbas: list and resume a previous session" })
cmd("LLeMbasExplain", function(o) L().explain(o.line1, o.line2) end,
{ range = true, desc = "LLeMbas: explain the selected lines" })
cmd("LLeMbasFix", function() L().fix() end, { desc = "LLeMbas: fix diagnostics in the current buffer" })
cmd("LLeMbasToggleThoughts", function() L().toggle_thoughts() end, { desc = "LLeMbas: toggle showing model thinking" })
cmd("LLeMbasStatus", function() L().status_popup() end, { desc = "LLeMbas: show agent, session and autocomplete status" })
cmd("LLeMbasLogin", function(o)
local address, ca = nil, nil
local args = o.fargs
local i = 1
while i <= #args do
if args[i] == "--ca" then ca = args[i + 1]; i = i + 2 else address = address or args[i]; i = i + 1 end
end
require("llembas.login").login(address, ca)
end, { nargs = "*", desc = "LLeMbas: sign this computer in to a LLeMbas server ([address] [--ca file])" })
cmd("LLeMbasLoginCancel", function()
if not require("llembas.login").cancel() then vim.notify("LLeMbas: no sign-in is under way", vim.log.levels.INFO) end
end, { desc = "LLeMbas: stop a sign-in that is waiting to be approved" })
cmd("LLeMbasLogout", function() require("llembas.login").logout() end, { desc = "LLeMbas: sign this computer out of its LLeMbas server" })
cmd("LLeMbasRestart", function() L().restart() end, { desc = "LLeMbas: stop the agent (it starts again when needed)" })
cmd("LLeMbasLog", function() L().log() end, { desc = "LLeMbas: show what the agent wrote on stderr" })
cmd("LLeMbasHelp", function() L().help() end, { desc = "LLeMbas: show commands and keymaps" })