|
|
@@ -714,6 +714,85 @@ bind_key("C-x 0", function()
|
|
|
message("Closed window with C-x 0")
|
|
|
end)
|
|
|
|
|
|
+-- ============================================================================
|
|
|
+-- BUFFER MANAGEMENT (C-x b, C-x C-b, C-x k)
|
|
|
+-- ============================================================================
|
|
|
+
|
|
|
+-- C-x b: Switch to buffer (with tab completion)
|
|
|
+bind_key("C-x b", function()
|
|
|
+ editor:buffer_switch_mode()
|
|
|
+end)
|
|
|
+
|
|
|
+-- C-x k: Kill buffer (with tab completion)
|
|
|
+bind_key("C-x k", function()
|
|
|
+ editor:kill_buffer_mode()
|
|
|
+end)
|
|
|
+
|
|
|
+-- C-x C-b: List all buffers
|
|
|
+bind_key("C-x C-b", function()
|
|
|
+ local buffer_info = editor:get_all_buffer_info()
|
|
|
+
|
|
|
+ if #buffer_info == 0 then
|
|
|
+ message("No buffers open")
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ -- Format buffer list
|
|
|
+ local lines = {}
|
|
|
+ table.insert(lines, "Buffer List:")
|
|
|
+ table.insert(lines, "------------")
|
|
|
+ table.insert(lines, "")
|
|
|
+
|
|
|
+ for i, info in ipairs(buffer_info) do
|
|
|
+ local modified = info.modified and "[+]" or " "
|
|
|
+ local filepath = ""
|
|
|
+ if info.filepath then
|
|
|
+ filepath = tostring(info.filepath)
|
|
|
+ end
|
|
|
+
|
|
|
+ local line = string.format("%s %-20s %5d lines %s",
|
|
|
+ modified,
|
|
|
+ info.name,
|
|
|
+ info.size,
|
|
|
+ filepath
|
|
|
+ )
|
|
|
+ table.insert(lines, line)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- Create a new buffer for the list
|
|
|
+ local list_text = table.concat(lines, "\n")
|
|
|
+
|
|
|
+ -- For now, just show in message (full buffer list implementation would create a special buffer)
|
|
|
+ -- This is a simple version that shows the list in a new buffer
|
|
|
+ local current_buf_name = editor.buffer:name()
|
|
|
+
|
|
|
+ -- Try to find or create the *Buffer List* buffer
|
|
|
+ local list_buf = editor:get_buffer_by_name("*Buffer List*")
|
|
|
+ if not list_buf then
|
|
|
+ -- Create a new buffer for buffer list
|
|
|
+ editor:new_buffer("*Buffer List*")
|
|
|
+ local buf = editor.buffer
|
|
|
+
|
|
|
+ -- Clear buffer and insert list
|
|
|
+ buf:clear_styles()
|
|
|
+ -- Insert the formatted text
|
|
|
+ local cursor = editor.cursor
|
|
|
+ buf:insert(cursor, list_text)
|
|
|
+
|
|
|
+ message(string.format("Buffer list (%d buffers)", #buffer_info))
|
|
|
+ else
|
|
|
+ -- Switch to existing buffer list
|
|
|
+ editor:switch_buffer_in_window("*Buffer List*")
|
|
|
+
|
|
|
+ -- Update the content
|
|
|
+ local buf = editor.buffer
|
|
|
+ -- Clear and reinsert (simple approach)
|
|
|
+ -- In a full implementation, we'd replace the content properly
|
|
|
+
|
|
|
+ message("Showing buffer list")
|
|
|
+ end
|
|
|
+end)
|
|
|
+
|
|
|
-- Test control keys (ncurses versions)
|
|
|
bind_key("C-k", function()
|
|
|
message("C-k pressed! (Control key working with ncurses)")
|