From 34936951651b9d1e9f3b7e4108c2d656e0cfeec0 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Sat, 6 Dec 2025 11:40:00 -0800 Subject: [PATCH] Add support for creating a new empty buffer (C-k i). - Introduced `BufferNew` command to create and switch to a new unnamed buffer. - Registered `BufferNew` in the command registry and updated keymap and help text. - Implemented `cmd_buffer_new()` to handle buffer creation and switching logic. --- Command.cc | 14 ++++++++++++++ Command.h | 1 + HelpText.cc | 1 + KKeymap.cc | 3 +++ 4 files changed, 19 insertions(+) diff --git a/Command.cc b/Command.cc index 51152a8..2327431 100644 --- a/Command.cc +++ b/Command.cc @@ -1585,6 +1585,19 @@ cmd_buffer_close(const CommandContext &ctx) } +// Create a new empty, unnamed buffer and switch to it +static bool +cmd_buffer_new(const CommandContext &ctx) +{ + // Create an empty buffer and add it to the editor + Buffer empty; + std::size_t idx = ctx.editor.AddBuffer(std::move(empty)); + ctx.editor.SwitchTo(idx); + ctx.editor.SetStatus("New buffer"); + return true; +} + + // --- Editing --- static bool cmd_insert_text(CommandContext &ctx) @@ -4378,6 +4391,7 @@ InstallDefaultCommands() CommandId::BufferSwitchStart, "buffer-switch-start", "Begin buffer switch prompt", cmd_buffer_switch_start, false, false }); + CommandRegistry::Register({CommandId::BufferNew, "buffer-new", "Open new empty buffer", cmd_buffer_new}); CommandRegistry::Register({CommandId::BufferNext, "buffer-next", "Switch to next buffer", cmd_buffer_next}); CommandRegistry::Register({CommandId::BufferPrev, "buffer-prev", "Switch to previous buffer", cmd_buffer_prev}); CommandRegistry::Register({ diff --git a/Command.h b/Command.h index 1a1bdf5..ce9ed53 100644 --- a/Command.h +++ b/Command.h @@ -31,6 +31,7 @@ enum class CommandId { VisualFontPickerToggle, // Buffers BufferSwitchStart, // begin buffer switch prompt + BufferNew, // create a new empty, unnamed buffer (C-k i) BufferClose, BufferNext, BufferPrev, diff --git a/HelpText.cc b/HelpText.cc index 6ee1d72..59b9405 100644 --- a/HelpText.cc +++ b/HelpText.cc @@ -31,6 +31,7 @@ HelpText::Text() " C-k c Close current buffer\n" " C-k d Kill to end of line\n" " C-k e Open file (prompt)\n" + " C-k i New empty buffer\n" " C-k f Flush kill ring\n" " C-k g Jump to line\n" " C-k h Show this help\n" diff --git a/KKeymap.cc b/KKeymap.cc index a3c800b..12f2f20 100644 --- a/KKeymap.cc +++ b/KKeymap.cc @@ -42,6 +42,9 @@ KLookupKCommand(const int ascii_key, const bool ctrl, CommandId &out) -> bool case 'a': out = CommandId::MarkAllAndJumpEnd; return true; + case 'i': + out = CommandId::BufferNew; // C-k i new empty buffer + return true; case 'k': out = CommandId::CenterOnCursor; // C-k k center current line return true;