|
@@ -304,6 +304,57 @@ define_minor_mode("line-numbers-mode", {
|
|
|
-- Example: Custom keybindings
|
|
-- Example: Custom keybindings
|
|
|
-- Syntax: bind_key("key", function() ... end)
|
|
-- Syntax: bind_key("key", function() ... end)
|
|
|
|
|
|
|
|
|
|
+-- Basic Editing Commands (moved from C++ fallback)
|
|
|
|
|
+function lumacs_insert_newline()
|
|
|
|
|
+ local cursor = editor.cursor
|
|
|
|
|
+ editor.buffer:insert_newline(cursor)
|
|
|
|
|
+ editor:set_cursor(lumacs.Position(cursor.line + 1, 0))
|
|
|
|
|
+end
|
|
|
|
|
+bind_key("Return", lumacs_insert_newline)
|
|
|
|
|
+define_command("insert-newline", lumacs_insert_newline, "Insert a new line at cursor position.")
|
|
|
|
|
+
|
|
|
|
|
+function lumacs_backward_delete_char()
|
|
|
|
|
+ local cursor = editor.cursor
|
|
|
|
|
+ editor.buffer:erase_char(cursor)
|
|
|
|
|
+ if cursor.column > 0 then
|
|
|
|
|
+ editor:set_cursor(lumacs.Position(cursor.line, cursor.column - 1))
|
|
|
|
|
+ elseif cursor.line > 0 then
|
|
|
|
|
+ local prev_line_len = #editor.buffer:line(cursor.line - 1)
|
|
|
|
|
+ editor:set_cursor(lumacs.Position(cursor.line - 1, prev_line_len))
|
|
|
|
|
+ end
|
|
|
|
|
+end
|
|
|
|
|
+bind_key("Backspace", lumacs_backward_delete_char)
|
|
|
|
|
+define_command("backward-delete-char", lumacs_backward_delete_char, "Delete the character before cursor.")
|
|
|
|
|
+
|
|
|
|
|
+function lumacs_delete_char()
|
|
|
|
|
+ local cursor = editor.cursor
|
|
|
|
|
+ editor.buffer:erase_char(lumacs.Position(cursor.line, cursor.column + 1))
|
|
|
|
|
+end
|
|
|
|
|
+bind_key("Delete", lumacs_delete_char)
|
|
|
|
|
+define_command("delete-char", lumacs_delete_char, "Delete the character at cursor position.")
|
|
|
|
|
+
|
|
|
|
|
+-- Navigation Commands (explicitly bound arrow keys)
|
|
|
|
|
+bind_key("ArrowUp", function() editor:move_up() end)
|
|
|
|
|
+bind_key("ArrowDown", function() editor:move_down() end)
|
|
|
|
|
+bind_key("ArrowLeft", function() editor:move_left() end)
|
|
|
|
|
+bind_key("ArrowRight", function() editor:move_right() end)
|
|
|
|
|
+
|
|
|
|
|
+bind_key("Home", function() editor:move_to_line_start() end)
|
|
|
|
|
+bind_key("End", function() editor:move_to_line_end() end)
|
|
|
|
|
+
|
|
|
|
|
+-- Generic self-insert command for printable characters
|
|
|
|
|
+-- This command is special; it's called by the C++ core if no other binding matches a printable char.
|
|
|
|
|
+function self_insert_command(char_to_insert)
|
|
|
|
|
+ local cursor = editor.cursor
|
|
|
|
|
+ editor.buffer:insert(cursor, char_to_insert)
|
|
|
|
|
+ editor:set_cursor(lumacs.Position(cursor.line, cursor.column + 1))
|
|
|
|
|
+ -- Optionally, log for debugging
|
|
|
|
|
+ -- local new_cursor = editor.cursor
|
|
|
|
|
+ -- print(string.format("[DEBUG Lua] Inserted '%s' at (%d,%d) -> cursor now at (%d,%d)",
|
|
|
|
|
+ -- char_to_insert, cursor.line, cursor.column, new_cursor.line, new_cursor.column))
|
|
|
|
|
+end
|
|
|
|
|
+define_command("self-insert-command", self_insert_command, "Insert the character pressed.")
|
|
|
|
|
+
|
|
|
-- Emacs-style navigation (Ctrl+N/P for next/previous line)
|
|
-- Emacs-style navigation (Ctrl+N/P for next/previous line)
|
|
|
bind_key("C-n", function()
|
|
bind_key("C-n", function()
|
|
|
editor:move_down()
|
|
editor:move_down()
|
|
@@ -416,7 +467,7 @@ function find_next(query)
|
|
|
-- A simple way is to advance column by 1 for the search start.
|
|
-- A simple way is to advance column by 1 for the search start.
|
|
|
local search_start = lumacs.Position(cursor.line, cursor.column + 1)
|
|
local search_start = lumacs.Position(cursor.line, cursor.column + 1)
|
|
|
|
|
|
|
|
- -- If at end of line, search from start of next line is handled by find() implementation?
|
|
|
|
|
|
|
+ -- If at end of line, search from start of next line is handled by find() implementation?
|
|
|
-- Buffer::find currently implements simple linear search from a position.
|
|
-- Buffer::find currently implements simple linear search from a position.
|
|
|
-- If column is beyond end, it should handle it. Let's trust the C++ impl or adjust.
|
|
-- If column is beyond end, it should handle it. Let's trust the C++ impl or adjust.
|
|
|
|
|
|
|
@@ -746,8 +797,8 @@ bind_key("C-x C-b", function()
|
|
|
table.insert(lines, "Buffer List:")
|
|
table.insert(lines, "Buffer List:")
|
|
|
table.insert(lines, "------------")
|
|
table.insert(lines, "------------")
|
|
|
table.insert(lines, "")
|
|
table.insert(lines, "")
|
|
|
- table.insert(lines, string.format("%-3s %-20s %-10s %s", "Mod", "Name", "Size", "File"))
|
|
|
|
|
- table.insert(lines, string.format("%-3s %-20s %-10s %s", "---", "----", "----", "----"))
|
|
|
|
|
|
|
+ table.insert(lines, string.format("% -3s % -20s % -10s %s", "Mod", "Name", "Size", "File"))
|
|
|
|
|
+ table.insert(lines, string.format("% -3s % -20s % -10s %s", "---", "----", "----"))
|
|
|
|
|
|
|
|
for i, info in ipairs(buffer_info) do
|
|
for i, info in ipairs(buffer_info) do
|
|
|
local modified = info.modified and " * " or " "
|
|
local modified = info.modified and " * " or " "
|
|
@@ -756,7 +807,7 @@ bind_key("C-x C-b", function()
|
|
|
filepath = tostring(info.filepath)
|
|
filepath = tostring(info.filepath)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- local line = string.format("%s %-20s %-10d %s",
|
|
|
|
|
|
|
+ local line = string.format("%s % -20s % -10d %s",
|
|
|
modified,
|
|
modified,
|
|
|
info.name,
|
|
info.name,
|
|
|
info.size,
|
|
info.size,
|
|
@@ -862,7 +913,7 @@ bind_key("C-x C-l", function()
|
|
|
end)
|
|
end)
|
|
|
|
|
|
|
|
-- ============================================================================
|
|
-- ============================================================================
|
|
|
--- COMMENTING (M-;)
|
|
|
|
|
|
|
+-- COMMENTING (M- ;)
|
|
|
-- ============================================================================
|
|
-- ============================================================================
|
|
|
|
|
|
|
|
function escape_pattern(text)
|
|
function escape_pattern(text)
|
|
@@ -945,7 +996,7 @@ function comment_dwim()
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-bind_key("M-;", comment_dwim)
|
|
|
|
|
|
|
+bind_key("M-;") comment_dwim)
|
|
|
|
|
|
|
|
-- ============================================================================
|
|
-- ============================================================================
|
|
|
-- REGISTERS (C-x r s, C-x r i)
|
|
-- REGISTERS (C-x r s, C-x r i)
|
|
@@ -1162,14 +1213,14 @@ define_command("list-buffers", function()
|
|
|
table.insert(lines, "Buffer List:")
|
|
table.insert(lines, "Buffer List:")
|
|
|
table.insert(lines, "------------")
|
|
table.insert(lines, "------------")
|
|
|
table.insert(lines, "")
|
|
table.insert(lines, "")
|
|
|
- table.insert(lines, string.format("%-3s %-20s %-10s %s", "Mod", "Name", "Size", "File"))
|
|
|
|
|
- table.insert(lines, string.format("%-3s %-20s %-10s %s", "---", "----", "----", "----"))
|
|
|
|
|
|
|
+ table.insert(lines, string.format("% -3s % -20s % -10s %s", "Mod", "Name", "Size", "File"))
|
|
|
|
|
+ table.insert(lines, string.format("% -3s % -20s % -10s %s", "---", "----"))
|
|
|
|
|
|
|
|
for i, info in ipairs(buffer_info) do
|
|
for i, info in ipairs(buffer_info) do
|
|
|
local modified = info.modified and " * " or " "
|
|
local modified = info.modified and " * " or " "
|
|
|
local filepath = ""
|
|
local filepath = ""
|
|
|
if info.filepath then filepath = tostring(info.filepath) end
|
|
if info.filepath then filepath = tostring(info.filepath) end
|
|
|
- table.insert(lines, string.format("%s %-20s %-10d %s", modified, info.name, info.size, filepath))
|
|
|
|
|
|
|
+ table.insert(lines, string.format("%s % -20s % -10d %s", modified, info.name, info.size, filepath))
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
local list_text = table.concat(lines, "\n")
|
|
local list_text = table.concat(lines, "\n")
|
|
@@ -1458,4 +1509,4 @@ function get_completion_candidates(mode_name, input)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
return candidates
|
|
return candidates
|
|
|
-end
|
|
|
|
|
|
|
+end
|