feat: add set_buffer_tab_width and set_session_tab_width commands

Also, fold the tab_width and set_tab_width commands into one. The default
command (set_tab_width) now stores the tab_width in the persistent config.
This commit is contained in:
CJ van den Berg 2025-08-12 12:54:34 +02:00
parent 4037d67fe9
commit 80002e4d6b
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 34 additions and 5 deletions

View file

@ -711,14 +711,14 @@ pub const Editor = struct {
}
}
pub fn set_tab_width(self: *Self, ctx: Context) Result {
pub fn set_editor_tab_width(self: *Self, ctx: Context) Result {
var tab_width: usize = 0;
if (!try ctx.args.match(.{tp.extract(&tab_width)}))
return error.InvalidSetTabWidthArgument;
self.tab_width = tab_width;
self.refresh_tab_width();
}
pub const set_tab_width_meta: Meta = .{ .arguments = &.{.integer} };
pub const set_editor_tab_width_meta: Meta = .{ .arguments = &.{.integer} };
fn close(self: *Self) !void {
var meta = std.ArrayListUnmanaged(u8).empty;

View file

@ -745,10 +745,39 @@ const cmds = struct {
}
pub const force_terminate_meta: Meta = .{ .description = "Force quit without saving" };
pub fn tab_width(self: *Self, ctx: Ctx) Result {
return enter_mini_mode(self, @import("mode/mini/tab_width.zig"), ctx);
pub fn set_tab_width(self: *Self, ctx: Ctx) Result {
var tab_width: usize = 0;
if (!try ctx.args.match(.{tp.extract(&tab_width)}))
return enter_mini_mode(self, @import("mode/mini/tab_width.zig"), Ctx.fmt(.{"set_tab_width"}));
self.config_.tab_width = tab_width;
self.session_tab_width = null;
command.executeName("set_editor_tab_width", ctx) catch {};
try save_config();
self.logger.print("tab width {}", .{tab_width});
}
pub const tab_width_meta: Meta = .{ .description = "Set tab width" };
pub const set_tab_width_meta: Meta = .{ .description = "Set tab width" };
pub fn set_buffer_tab_width(self: *Self, ctx: Ctx) Result {
var tab_width: usize = 0;
if (!try ctx.args.match(.{tp.extract(&tab_width)}))
return enter_mini_mode(self, @import("mode/mini/tab_width.zig"), Ctx.fmt(.{"set_buffer_tab_width"}));
command.executeName("set_editor_tab_width", ctx) catch {};
self.logger.print("buffer tab width {}", .{tab_width});
}
pub const set_buffer_tab_width_meta: Meta = .{ .description = "Set tab width for current buffer" };
pub fn set_session_tab_width(self: *Self, ctx: Ctx) Result {
var tab_width: usize = 0;
if (!try ctx.args.match(.{tp.extract(&tab_width)}))
return enter_mini_mode(self, @import("mode/mini/tab_width.zig"), Ctx.fmt(.{"set_session_tab_width"}));
self.session_tab_width = tab_width;
command.executeName("set_editor_tab_width", ctx) catch {};
self.logger.print("session tab width {}", .{tab_width});
}
pub const set_session_tab_width_meta: Meta = .{ .description = "Set tab width for current session" };
pub fn set_theme(self: *Self, ctx: Ctx) Result {
var name: []const u8 = undefined;