diff options
| author | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-05-11 15:07:55 -0500 |
|---|---|---|
| committer | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-05-11 15:07:55 -0500 |
| commit | cebb280fe546190e55e071b6adbf37cd47950f34 (patch) | |
| tree | 6e7a7605f8832b1c1bd7e467884a8792a5e1fab4 /init.lua | |
initial commit
Diffstat (limited to 'init.lua')
| -rw-r--r-- | init.lua | 75 |
1 files changed, 75 insertions, 0 deletions
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) |
