feat: add interactive and non-interactive commands to set the current buffer's tab_width
This commit is contained in:
		
							parent
							
								
									1632061144
								
							
						
					
					
						commit
						3e0e75c9c8
					
				
					 3 changed files with 39 additions and 0 deletions
				
			
		| 
						 | 
					@ -432,6 +432,7 @@ pub const Editor = struct {
 | 
				
			||||||
            tp.extract_cbor(&cursels_cbor),
 | 
					            tp.extract_cbor(&cursels_cbor),
 | 
				
			||||||
        }))
 | 
					        }))
 | 
				
			||||||
            return error.RestoreStateMatch;
 | 
					            return error.RestoreStateMatch;
 | 
				
			||||||
 | 
					        self.refresh_tab_width();
 | 
				
			||||||
        if (op == .open_file)
 | 
					        if (op == .open_file)
 | 
				
			||||||
            try self.open(file_path);
 | 
					            try self.open(file_path);
 | 
				
			||||||
        self.clipboard = if (clipboard.len > 0) try self.allocator.dupe(u8, clipboard) else null;
 | 
					        self.clipboard = if (clipboard.len > 0) try self.allocator.dupe(u8, clipboard) else null;
 | 
				
			||||||
| 
						 | 
					@ -702,6 +703,23 @@ pub const Editor = struct {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn refresh_tab_width(self: *Self) void {
 | 
				
			||||||
 | 
					        self.metrics = self.plane.metrics(self.tab_width);
 | 
				
			||||||
 | 
					        switch (self.indent_mode) {
 | 
				
			||||||
 | 
					            .spaces, .auto => {},
 | 
				
			||||||
 | 
					            .tabs => self.indent_size = self.tab_width,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn set_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} };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn close(self: *Self) !void {
 | 
					    fn close(self: *Self) !void {
 | 
				
			||||||
        var meta = std.ArrayListUnmanaged(u8).empty;
 | 
					        var meta = std.ArrayListUnmanaged(u8).empty;
 | 
				
			||||||
        defer meta.deinit(self.allocator);
 | 
					        defer meta.deinit(self.allocator);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								src/tui/mode/mini/tab_width.zig
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/tui/mode/mini/tab_width.zig
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					const command = @import("command");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const Type = @import("numeric_input.zig").Create(@This());
 | 
				
			||||||
 | 
					pub const create = Type.create;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn name(_: *Type) []const u8 {
 | 
				
			||||||
 | 
					    return " tab size";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub const preview = goto;
 | 
				
			||||||
 | 
					pub const apply = goto;
 | 
				
			||||||
 | 
					pub const cancel = goto;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn goto(self: *Type) void {
 | 
				
			||||||
 | 
					    command.executeName("set_tab_width", command.fmt(.{self.input orelse self.start})) catch {};
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -744,6 +744,11 @@ const cmds = struct {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    pub const force_terminate_meta: Meta = .{ .description = "Force quit without saving" };
 | 
					    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 const tab_width_meta: Meta = .{ .description = "Set tab width" };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn set_theme(self: *Self, ctx: Ctx) Result {
 | 
					    pub fn set_theme(self: *Self, ctx: Ctx) Result {
 | 
				
			||||||
        var name: []const u8 = undefined;
 | 
					        var name: []const u8 = undefined;
 | 
				
			||||||
        if (!try ctx.args.match(.{tp.extract(&name)}))
 | 
					        if (!try ctx.args.match(.{tp.extract(&name)}))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue