From cebb280fe546190e55e071b6adbf37cd47950f34 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Mon, 11 May 2026 15:07:55 -0500 Subject: initial commit --- init.lua | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 init.lua (limited to 'init.lua') diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..9930ba7 --- /dev/null +++ b/init.lua @@ -0,0 +1,75 @@ +local open_prompt = { + active = false, + text = "", + buffer = editor.aux_buffer_new(), +} + +local function hide_open_prompt() + open_prompt.active = false + open_prompt.text = "" + editor.aux_buffer_set_text(open_prompt.buffer, "") +end + +local function show_open_prompt() + open_prompt.active = true + open_prompt.text = "" + editor.aux_buffer_set_text(open_prompt.buffer, "open file: ") +end + +local function refresh_open_prompt() + editor.aux_buffer_set_text(open_prompt.buffer, "open file: " .. open_prompt.text) +end + +lemacs.keys.bind_leader("f", function() + if not open_prompt.active then + show_open_prompt() + end +end) + +lemacs.hooks.add("intercept_key", function(key) + if not open_prompt.active then + return false + end + + if key == "escape" then + hide_open_prompt() + return true + end + + if key == "backspace" then + open_prompt.text = open_prompt.text:sub(1, #open_prompt.text - 1) + refresh_open_prompt() + return true + end + + if key == "enter" then + local path = open_prompt.text + hide_open_prompt() + if path ~= "" then + editor.open_file(path) + end + return true + end + + return open_prompt.active +end) + +lemacs.hooks.add("intercept_text", function(text) + if not open_prompt.active then + return false + end + + open_prompt.text = open_prompt.text .. text + refresh_open_prompt() + return true +end) + +lemacs.hooks.add("after_layout", function() + if not open_prompt.active then + return + end + + local width = editor.screen_width() + local y = editor.screen_height() - 24 + lemacs.ui.add_view(1, open_prompt.buffer, 0, y, width, 24, false, 42, 44, 54, 245, 232, 232, 236, 255) +end) -- cgit v1.3.1