Files
HomerandClaude Opus 5.5 97d3f8bbba LLeMbas IDE: one rule for where the CLI is, its installer checked, honest doctor and start screen
- The CLI is found where the plugin finds it (require("llembas").cli(): PATH, then
  ~/.local/bin); the installer and the launcher keep the same find_cli in shell, and
  scripts/test-ide.sh fails when the two shell copies differ or disagree with the plugin. A CLI
  in ~/.local/bin that is not on PATH (right after a first install) is no longer "not installed".
- The CLI's get.sh is taken from a CLI release (the newest of the channel, or
  LLEMBAS_IDE_CLI_VERSION) and run only after that release's SHA256SUMS is verified with the
  release key and get.sh matches it; LEMBAS_REF names that release.
- curl … | bash -s -- --help prints the help (it is a here-document now); it names ssh-keygen.
- The start screen says a sign-in is needed only when there is none.
- doctor and an update see files added to a plugin, not only changed ones; doctor accepts the
  start as the installer does, says when plugins.lock is missing, checks ssh-keygen, and counts
  "1 check failed" / "N checks failed".
- A release archive that holds a link is refused; newest_tag keeps redirects on https.
- The README key table says where a chord also works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 07:52:31 +00:00

274 lines
14 KiB
Lua

-- Every key the IDE adds, in one table: the mappings, the hints that appear after <Space>, the
-- cheat sheet (:LLeMbasIdeKeys) and the table in the README are all made from it.
-- The leader is <Space>. Neovim's own keys are unchanged unless listed here.
--
-- LLeMbas's own keys are not written here a second time: they are the LLeMbas plugin's key table
-- (lua/llembas/keys.lua), which maps them, feeds the bottom bar, and is read below for the cheat
-- sheet. Each action there has two forms: a chord (Ctrl+Shift+A …) that arrives from a terminal
-- with the kitty keyboard protocol, and a key after <Space>l that always arrives.
local M = {}
local function pick(name, opts) return function() require("mini.pick").builtin[name](opts) end end
local function extra(name, opts) return function() require("mini.extra").pickers[name](opts) end end
local function problem(count)
return function()
if vim.diagnostic.jump then return vim.diagnostic.jump({ count = count, float = true }) end
if count > 0 then vim.diagnostic.goto_next() else vim.diagnostic.goto_prev() end -- Neovim 0.10
end
end
local function mod(module, fn) return function(...) return require(module)[fn](...) end end
M.groups = {
{ "<Leader>f", "find" },
{ "<Leader>b", "buffer" },
{ "<Leader>c", "code" },
{ "<Leader>g", "git" },
{ "<Leader>l", "LLeMbas" },
{ "<Leader>s", "session" },
{ "<Leader>t", "terminal" },
{ "<Leader>u", "look" },
{ "<Leader>x", "problems" },
{ "<Leader>i", "IDE" },
}
-- { modes, keys, action, what it does, section }
M.map = {
-- Files and search
{ "n", "<Leader><Space>", pick("files"), "Find a file", "Find" },
{ "n", "<Leader>/", pick("grep_live"), "Search in files (needs rg)", "Find" },
{ "n", "<Leader>,", pick("buffers"), "Switch buffer", "Find" },
{ "n", "<Leader>e", function() require("llembas.layout").toggle("tree") end, "File tree (the left bar), show and hide", "Find" },
{ "n", "<Leader>E", function() require("mini.files").open(vim.api.nvim_buf_get_name(0)) end, "Directories side by side, at this file (edit them like text)", "Find" },
{ "n", "<Leader>ff", pick("files"), "Find a file", "Find" },
{ "n", "<Leader>fg", pick("grep_live"), "Search in files (needs rg)", "Find" },
{ "n", "<Leader>fw", function() require("mini.pick").builtin.grep({ pattern = vim.fn.expand("<cword>") }) end, "Search the word under the cursor", "Find" },
{ "n", "<Leader>fb", pick("buffers"), "Open buffers", "Find" },
{ "n", "<Leader>fr", extra("oldfiles"), "Recent files", "Find" },
{ "n", "<Leader>fs", extra("lsp", { scope = "document_symbol" }), "Symbols in this file", "Find" },
{ "n", "<Leader>fS", extra("lsp", { scope = "workspace_symbol" }), "Symbols in the project", "Find" },
{ "n", "<Leader>fR", extra("lsp", { scope = "references" }), "References to the symbol under the cursor", "Find" },
{ "n", "<Leader>fd", extra("diagnostic", { scope = "all" }), "Problems in the project", "Find" },
{ "n", "<Leader>fh", pick("help"), "Help pages", "Find" },
{ "n", "<Leader>fk", extra("keymaps"), "All key mappings", "Find" },
{ "n", "<Leader>f.", pick("resume"), "The last search again", "Find" },
-- Buffers and windows
{ "n", "<Leader>bd", function() require("mini.bufremove").delete() end, "Close the buffer, keep the window", "Buffers" },
{ "n", "<Leader>bn", "<Cmd>bnext<CR>", "Next buffer", "Buffers" },
{ "n", "<Leader>bp", "<Cmd>bprevious<CR>", "Previous buffer", "Buffers" },
{ "n", "<S-l>", "<Cmd>bnext<CR>", "Next buffer", "Buffers" },
{ "n", "<S-h>", "<Cmd>bprevious<CR>", "Previous buffer", "Buffers" },
{ "n", "<Leader>w", "<Cmd>write<CR>", "Save", "Buffers" },
{ "n", "<Leader>q", "<Cmd>quit<CR>", "Close the window", "Buffers" },
{ "n", "<Esc>", "<Cmd>nohlsearch<CR>", "Clear the search highlight", "Buffers" },
-- Code
{ "n", "<Leader>ca", function() vim.lsp.buf.code_action() end, "Code action", "Code" },
{ "n", "<Leader>cr", function() vim.lsp.buf.rename() end, "Rename the symbol", "Code" },
{ { "n", "x" }, "<Leader>cf", mod("llembas_ide.plugins", "format"), "Format the file or the selection", "Code" },
{ "n", "<Leader>cd", function() vim.diagnostic.open_float() end, "The problem on this line", "Code" },
{ "n", "<Leader>cl", mod("llembas_ide.lsp", "guide"), "Language servers: found, missing, how to install", "Code" },
-- Problems
{ "n", "<Leader>xx", function() vim.diagnostic.setloclist() end, "Problems in this file, as a list", "Problems" },
{ "n", "<Leader>xw", function() vim.diagnostic.setqflist() end, "Problems in the project, as a list", "Problems" },
{ "n", "<Leader>xn", problem(1), "Next problem", "Problems" },
{ "n", "<Leader>xp", problem(-1), "Previous problem", "Problems" },
-- Git
{ "n", "<Leader>gs", extra("git_files", { scope = "modified" }), "Changed files", "Git" },
{ "n", "<Leader>gh", extra("git_hunks"), "Changes, hunk by hunk", "Git" },
{ "n", "<Leader>gd", mod("llembas_ide.git", "diff_head"), "This file beside its committed version", "Git" },
{ "n", "<Leader>go", function() require("mini.diff").toggle_overlay(0) end, "Show changes inline, on and off", "Git" },
{ "n", "<Leader>ga", mod("llembas_ide.git", "stage_hunk"), "Stage the change under the cursor", "Git" },
{ "n", "<Leader>gr", mod("llembas_ide.git", "reset_hunk"), "Undo the change under the cursor", "Git" },
{ "n", "<Leader>gb", function() require("mini.git").show_at_cursor() end, "Who changed this line, and the commit", "Git" },
-- (LLeMbas: the plugin's own key table; see the top of this file.)
-- Sessions
{ "n", "<Leader>sr", mod("llembas_ide.sessions", "restore"), "Restore this directory's session", "Session" },
{ "n", "<Leader>sw", mod("llembas_ide.sessions", "save"), "Save the session now", "Session" },
{ "n", "<Leader>sd", mod("llembas_ide.sessions", "delete"), "Forget this directory's session", "Session" },
-- Terminal
{ "n", "<Leader>tt", mod("llembas_ide.terminal", "toggle"), "Terminal, open and close", "Terminal" },
{ { "n", "t" }, "<C-/>", mod("llembas_ide.terminal", "toggle"), "Terminal, open and close", "Terminal" },
{ { "n", "t" }, "<C-_>", mod("llembas_ide.terminal", "toggle"), "The same, as some terminals send it", "Terminal" },
{ "t", "<Esc><Esc>", "<C-\\><C-n>", "Leave the terminal's typing mode", "Terminal" },
-- Look
{ "n", "<Leader>ut", function() vim.o.background = vim.o.background == "dark" and "light" or "dark" end, "Dark and light theme", "Look" },
{ "n", "<Leader>uw", function() vim.wo.wrap = not vim.wo.wrap end, "Wrap long lines, on and off", "Look" },
{ "n", "<Leader>un", function() vim.wo.relativenumber = not vim.wo.relativenumber end, "Relative line numbers, on and off", "Look" },
-- The IDE itself
{ "n", "<Leader>ih", mod("llembas_ide.dashboard", "open"), "Start screen", "IDE" },
{ "n", "<Leader>ik", function() M.show() end, "This list of keys", "IDE" },
{ "n", "<Leader>id", "<Cmd>LLeMbasIdeDoctor<CR>", "Check the installation", "IDE" },
{ "n", "<Leader>iu", "<Cmd>LLeMbasIdeConfig<CR>", "Open your own settings file", "IDE" },
{ "n", "<Leader>iv", "<Cmd>LLeMbasIdeVersion<CR>", "Versions", "IDE" },
}
-- Added to a buffer when a language server attaches to it.
M.lsp = {
{ "n", "gd", function() vim.lsp.buf.definition() end, "Go to the definition" },
{ "n", "gD", function() vim.lsp.buf.declaration() end, "Go to the declaration" },
{ "n", "gI", function() vim.lsp.buf.implementation() end, "Go to the implementation" },
{ "n", "gy", function() vim.lsp.buf.type_definition() end, "Go to the type's definition" },
}
-- Keys that are not the IDE's mappings but belong on the cheat sheet: plugins' and Neovim's own.
M.also = {
{ "i", "<M-\\>", "Ask LLeMbas for a suggestion now (accepting one: under LLeMbas, below)", "Typing" },
{ "i", "<C-n> <C-p>", "Move in the completion menu (also <Down> <Up>)", "Typing" },
{ "i", "<CR>", "Take the menu entry you moved to; otherwise a new line", "Typing" },
{ "i", "<C-y>", "Take the menu's first entry", "Typing" },
{ "i", "<C-e>", "Close the menu", "Typing" },
{ "i", "<C-Space>", "Open the menu, or the entry's documentation", "Typing" },
{ "n", "gcc", "Comment the line, on and off (gc with a motion or a selection)", "Editing" },
{ "n", "sa sd sr", "Surround: add (saiw\"), delete (sd\"), replace (sr\"')", "Editing" },
{ "n", "K", "Documentation of the symbol under the cursor", "Editing" },
{ "n", "gd gD gI gy", "Definition, declaration, implementation, type (with a language server)", "Editing" },
{ "n", "]g [g", "Next and previous git change (]G [G: last and first)", "Git" },
}
--- LLeMbas's keys, from the plugin's table: { keys, where, what it does } for the cheat sheet.
--- Both forms of an action are in the one cell, the chord first.
local WHERE = {
tree = "the tree", settings = "the settings lines", prompt = "the prompt", chat = "the transcript",
change = "a proposed change", suggestion = "insert, with a suggestion",
}
function M.llembas_rows()
local ok, keys = pcall(require, "llembas.keys")
if not ok then return {} end
local out = {}
for _, r in ipairs(keys.rows()) do
local both = {}
if r.chord then both[#both + 1] = r.chord end
if r.alt ~= "" then both[#both + 1] = r.alt end
local where = WHERE[r.where]
if not where then
local names = {}
for _, m in ipairs(r.modes) do names[#names + 1] = ({ n = "normal", x = "visual", i = "insert" })[m] or m end
where = table.concat(names, ", ")
-- The chord form is mapped in normal, visual and insert mode, whatever the other form is.
if r.chord then
local more = {}
for _, m in ipairs({ "n", "x", "i" }) do
if not vim.tbl_contains(r.modes, m) then more[#more + 1] = ({ n = "normal", x = "visual", i = "insert" })[m] end
end
if #more > 0 then where = where .. "; the chord also in " .. table.concat(more, ", ") end
end
end
if #both > 0 then out[#out + 1] = { table.concat(both, " or "), where, r.desc } end
end
return out
end
local function modes(m) return type(m) == "table" and m or { m } end
--- Bindings given more than once (the same mode and keys), as text. Empty when the map is sound.
function M.duplicates()
local seen, dup = {}, {}
-- LLeMbas's keys that are mapped everywhere count too: nothing here may take one of them.
local ok, llembas = pcall(require, "llembas.keys")
for _, k in ipairs(ok and llembas.table or {}) do
if k.run and not k.virtual then
local function take(mode, lhs)
seen[mode .. " " .. vim.api.nvim_replace_termcodes(llembas.lhs(lhs), true, true, true)] = true
end
for _, lhs in ipairs(type(k.chord) == "table" and k.chord or { k.chord }) do
for _, mode in ipairs({ "n", "x", "i" }) do take(mode, lhs) end
end
if not k.scope then
for _, lhs in ipairs(llembas.alts(k)) do
for _, mode in ipairs(k.modes or { "n" }) do take(mode, lhs) end
end
end
end
end
for _, list in ipairs({ M.map, M.lsp }) do
for _, k in ipairs(list) do
for _, mode in ipairs(modes(k[1])) do
local id = mode .. " " .. vim.api.nvim_replace_termcodes(k[2], true, true, true)
if seen[id] then table.insert(dup, mode .. " " .. k[2]) end
seen[id] = true
end
end
end
return dup
end
function M.setup()
for _, k in ipairs(M.map) do
vim.keymap.set(k[1], k[2], k[3], { desc = k[4], silent = type(k[3]) ~= "string" or k[3]:sub(1, 1) ~= ":" })
end
end
local function shown(lhs) return (lhs:gsub("<Leader>", "<Space>")) end
local mode_names = { n = "normal", x = "visual", i = "insert", t = "terminal" }
local function mode_text(m)
local out = {}
for _, mode in ipairs(modes(m)) do table.insert(out, mode_names[mode] or mode) end
return table.concat(out, ", ")
end
--- The sections of the cheat sheet in order: { name, { {keys, modes, text}, … } }.
function M.sections()
local order, by = {}, {}
local function add(section, keys, mode, text)
if not by[section] then
by[section] = {}
table.insert(order, section)
end
table.insert(by[section], { shown(keys), mode_text(mode), text })
end
for _, k in ipairs(M.also) do if k[4] == "Typing" or k[4] == "Editing" then add(k[4], k[2], k[1], k[3]) end end
for _, k in ipairs(M.map) do add(k[5], k[2], k[1], k[4]) end
for _, k in ipairs(M.also) do if k[4] ~= "Typing" and k[4] ~= "Editing" then add(k[4], k[2], k[1], k[3]) end end
local out = {}
for _, name in ipairs(order) do
table.insert(out, { name, by[name] })
-- LLeMbas's own section stands after Git, where it always stood.
if name == "Git" then
local rows = {}
for _, r in ipairs(M.llembas_rows()) do table.insert(rows, { shown(r[1]), r[2], r[3] }) end
if #rows > 0 then table.insert(out, { "LLeMbas", rows }) end
end
end
return out
end
--- The cheat sheet as the README has it.
function M.markdown()
local out = {}
for _, s in ipairs(M.sections()) do
vim.list_extend(out, { "**" .. s[1] .. "**", "", "| Keys | In | What it does |", "|---|---|---|" })
for _, r in ipairs(s[2]) do
table.insert(out, ("| `%s` | %s | %s |"):format(r[1]:gsub("|", "\\|"), r[2], (r[3]:gsub("|", "\\|"))))
end
table.insert(out, "")
end
return out
end
--- :LLeMbasIdeKeys
function M.show()
local lines, titles = { "The leader key is <Space>. Press it and wait: the next keys are shown.", "" }, {}
for _, s in ipairs(M.sections()) do
table.insert(lines, s[1])
table.insert(titles, #lines - 1)
-- The keys' column is as wide as this section's longest, so every row of it shares one edge.
local kw, ww = 16, 16
for _, r in ipairs(s[2]) do
kw, ww = math.max(kw, vim.fn.strdisplaywidth(r[1])), math.max(ww, vim.fn.strdisplaywidth(r[2]))
end
for _, r in ipairs(s[2]) do
table.insert(lines, " " .. r[1] .. (" "):rep(kw - vim.fn.strdisplaywidth(r[1]) + 1) .. r[2] .. (" "):rep(ww - vim.fn.strdisplaywidth(r[2]) + 1) .. r[3])
end
table.insert(lines, "")
end
local buf = require("llembas_ide.ui").page("LLeMbas IDE: keys", lines)
for _, l in ipairs(titles) do vim.api.nvim_buf_add_highlight(buf, -1, "Title", l, 0, -1) end
for i = 2, #lines - 1 do
if lines[i + 1]:sub(1, 2) == " " then
local keys_end = lines[i + 1]:find(" ", 3, true) or 18
vim.api.nvim_buf_add_highlight(buf, -1, "LLeMbasIdeKey", i, 2, keys_end)
end
end
end
return M