diff options
| author | 2024-02-25 04:14:45 +0200 | |
|---|---|---|
| committer | 2024-02-25 04:14:45 +0200 | |
| commit | 7ca3295e318f797d79b84f9650baa95d8c8d7ad6 (patch) | |
| tree | 6d37a64f760b30ba7ea2051425f7e5ad7460b652 | |
| parent | Don't do italic, not supported everywhere (diff) | |
| download | es-7ca3295e318f797d79b84f9650baa95d8c8d7ad6.tar.gz es-7ca3295e318f797d79b84f9650baa95d8c8d7ad6.tar.xz es-7ca3295e318f797d79b84f9650baa95d8c8d7ad6.zip | |
Don't bother saving buffers like *scratch*
| -rw-r--r-- | src/Buffer.zig | 34 | ||||
| -rw-r--r-- | src/Editor.zig | 8 | ||||
| -rw-r--r-- | src/Row.zig | 2 |
3 files changed, 27 insertions, 17 deletions
diff --git a/src/Buffer.zig b/src/Buffer.zig index 555ad1d..ce27d95 100644 --- a/src/Buffer.zig +++ b/src/Buffer.zig | |||
| @@ -25,7 +25,7 @@ rx: usize, | |||
| 25 | rowoff: usize, | 25 | rowoff: usize, |
| 26 | coloff: usize, | 26 | coloff: usize, |
| 27 | 27 | ||
| 28 | dirty: bool, | 28 | edited: bool, |
| 29 | 29 | ||
| 30 | config: Config, | 30 | config: Config, |
| 31 | syntax: ?Syntax, | 31 | syntax: ?Syntax, |
| @@ -52,7 +52,7 @@ pub fn init(allocator: Allocator, name: []const u8) !Buffer { | |||
| 52 | .rowoff = 0, | 52 | .rowoff = 0, |
| 53 | .coloff = 0, | 53 | .coloff = 0, |
| 54 | 54 | ||
| 55 | .dirty = false, | 55 | .edited = false, |
| 56 | 56 | ||
| 57 | .config = config, | 57 | .config = config, |
| 58 | .syntax = null, | 58 | .syntax = null, |
| @@ -161,14 +161,14 @@ pub fn deleteChar(self: *Buffer) !void { | |||
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | if (self.cx < self.rows.items[self.cy].data.items.len) { | 163 | if (self.cx < self.rows.items[self.cy].data.items.len) { |
| 164 | self.dirty = true; | 164 | self.edited = true; |
| 165 | try self.rows.items[self.cy].deleteChar(self, self.cx); | 165 | try self.rows.items[self.cy].deleteChar(self, self.cx); |
| 166 | } else { | 166 | } else { |
| 167 | if (self.cy == self.rows.items.len - 1) { | 167 | if (self.cy == self.rows.items.len - 1) { |
| 168 | return; | 168 | return; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | self.dirty = true; | 171 | self.edited = true; |
| 172 | try self.rows.items[self.cy].appendString(self, self.rows.items[self.cy + 1].data.items); | 172 | try self.rows.items[self.cy].appendString(self, self.rows.items[self.cy + 1].data.items); |
| 173 | self.deleteRow(self.cy + 1); | 173 | self.deleteRow(self.cy + 1); |
| 174 | } | 174 | } |
| @@ -179,7 +179,7 @@ pub fn deleteAllRows(self: *Buffer) void { | |||
| 179 | return; | 179 | return; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | self.dirty = true; | 182 | self.edited = true; |
| 183 | while (self.rows.popOrNull()) |row| { | 183 | while (self.rows.popOrNull()) |row| { |
| 184 | row.deinit(); | 184 | row.deinit(); |
| 185 | } | 185 | } |
| @@ -201,7 +201,7 @@ pub fn deleteRow(self: *Buffer, at: usize) void { | |||
| 201 | return; | 201 | return; |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | self.dirty = true; | 204 | self.edited = true; |
| 205 | 205 | ||
| 206 | self.rows.orderedRemove(at).deinit(); | 206 | self.rows.orderedRemove(at).deinit(); |
| 207 | var i = at; | 207 | var i = at; |
| @@ -291,7 +291,7 @@ pub fn drawStatusBar(self: Buffer, writer: anytype, screencols: usize) !void { | |||
| 291 | try self.allocator.dupe(u8, self.short_name); | 291 | try self.allocator.dupe(u8, self.short_name); |
| 292 | defer self.allocator.free(name); | 292 | defer self.allocator.free(name); |
| 293 | 293 | ||
| 294 | const modified = if (self.dirty) | 294 | const modified = if (self.isDirty()) |
| 295 | @as([]const u8, " (modified)") | 295 | @as([]const u8, " (modified)") |
| 296 | else | 296 | else |
| 297 | @as([]const u8, ""); | 297 | @as([]const u8, ""); |
| @@ -437,7 +437,7 @@ pub fn insertChar(self: *Buffer, char: u8) !void { | |||
| 437 | try self.rows.items[self.cy].insertChar(self, self.cx, char); | 437 | try self.rows.items[self.cy].insertChar(self, self.cx, char); |
| 438 | self.cx += 1; | 438 | self.cx += 1; |
| 439 | 439 | ||
| 440 | self.dirty = true; | 440 | self.edited = true; |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | pub fn insertNChars(self: *Buffer, char: u8, count: usize) !void { | 443 | pub fn insertNChars(self: *Buffer, char: u8, count: usize) !void { |
| @@ -448,7 +448,7 @@ pub fn insertNChars(self: *Buffer, char: u8, count: usize) !void { | |||
| 448 | } | 448 | } |
| 449 | 449 | ||
| 450 | pub fn insertNewline(self: *Buffer) !void { | 450 | pub fn insertNewline(self: *Buffer) !void { |
| 451 | self.dirty = true; | 451 | self.edited = true; |
| 452 | 452 | ||
| 453 | if (self.cx == 0) { | 453 | if (self.cx == 0) { |
| 454 | try self.insertRow(self.cy, ""); | 454 | try self.insertRow(self.cy, ""); |
| @@ -484,7 +484,17 @@ pub fn insertRow(self: *Buffer, at: usize, data: []const u8) !void { | |||
| 484 | } | 484 | } |
| 485 | try self.rows.items[at].update(self); | 485 | try self.rows.items[at].update(self); |
| 486 | 486 | ||
| 487 | self.dirty = true; | 487 | self.edited = true; |
| 488 | } | ||
| 489 | |||
| 490 | pub fn isDirty(self: Buffer) bool { | ||
| 491 | if (self.short_name.len > 0) { | ||
| 492 | if (self.short_name[0] == '*' and self.short_name[self.short_name.len-1] == '*') { | ||
| 493 | return false; | ||
| 494 | } | ||
| 495 | } | ||
| 496 | |||
| 497 | return self.edited; | ||
| 488 | } | 498 | } |
| 489 | 499 | ||
| 490 | pub fn killLine(self: *Buffer) !void { | 500 | pub fn killLine(self: *Buffer) !void { |
| @@ -496,7 +506,7 @@ pub fn killLine(self: *Buffer) !void { | |||
| 496 | if (self.cx == row.data.items.len) { | 506 | if (self.cx == row.data.items.len) { |
| 497 | return self.deleteChar(); | 507 | return self.deleteChar(); |
| 498 | } else { | 508 | } else { |
| 499 | self.dirty = true; | 509 | self.edited = true; |
| 500 | try row.data.resize(self.cx); | 510 | try row.data.resize(self.cx); |
| 501 | return row.update(self); | 511 | return row.update(self); |
| 502 | } | 512 | } |
| @@ -672,7 +682,7 @@ pub fn save(self: *Buffer, editor: *Editor) !void { | |||
| 672 | }; | 682 | }; |
| 673 | 683 | ||
| 674 | try editor.setStatusMessage("Saved to '{s}'", .{file_path}); | 684 | try editor.setStatusMessage("Saved to '{s}'", .{file_path}); |
| 675 | self.dirty = false; | 685 | self.edited = false; |
| 676 | } | 686 | } |
| 677 | 687 | ||
| 678 | pub fn scroll(self: *Buffer, screenrows: usize, screencols: usize) void { | 688 | pub fn scroll(self: *Buffer, screenrows: usize, screencols: usize) void { |
diff --git a/src/Editor.zig b/src/Editor.zig index aa57c15..624e400 100644 --- a/src/Editor.zig +++ b/src/Editor.zig | |||
| @@ -135,7 +135,7 @@ pub fn hasBuffer(self: Editor, name: []const u8) bool { | |||
| 135 | 135 | ||
| 136 | /// Returns true if killed, false if didn't. | 136 | /// Returns true if killed, false if didn't. |
| 137 | pub fn killCurrentBuffer(self: *Editor) !bool { | 137 | pub fn killCurrentBuffer(self: *Editor) !bool { |
| 138 | if (self.buffer.dirty) { | 138 | if (self.buffer.isDirty()) { |
| 139 | if (!try self.promptYN("Unsaved changes, kill anyways?")) { | 139 | if (!try self.promptYN("Unsaved changes, kill anyways?")) { |
| 140 | return false; | 140 | return false; |
| 141 | } | 141 | } |
| @@ -174,7 +174,7 @@ pub fn open(self: *Editor, name: []const u8) !void { | |||
| 174 | const file = std.fs.openFileAbsolute(file_path, .{ .mode = .read_only }) catch |err| switch (err) { | 174 | const file = std.fs.openFileAbsolute(file_path, .{ .mode = .read_only }) catch |err| switch (err) { |
| 175 | error.FileNotFound => { | 175 | error.FileNotFound => { |
| 176 | try self.setStatusMessage("Will create a new file on save...", .{}); | 176 | try self.setStatusMessage("Will create a new file on save...", .{}); |
| 177 | self.buffer.dirty = true; | 177 | self.buffer.edited = true; |
| 178 | return; | 178 | return; |
| 179 | }, | 179 | }, |
| 180 | else => return err, | 180 | else => return err, |
| @@ -192,7 +192,7 @@ pub fn open(self: *Editor, name: []const u8) !void { | |||
| 192 | try self.buffer.appendRow(trimmed); | 192 | try self.buffer.appendRow(trimmed); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | self.buffer.dirty = false; | 195 | self.buffer.edited = false; |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | pub fn openFile(self: *Editor) !void { | 198 | pub fn openFile(self: *Editor) !void { |
| @@ -334,7 +334,7 @@ pub fn refreshWindowSize(self: *Editor) !void { | |||
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | pub fn saveBuffersExit(self: *Editor) !void { | 336 | pub fn saveBuffersExit(self: *Editor) !void { |
| 337 | while (self.buffers.count() > 1 or self.buffer.dirty) { | 337 | while (self.buffers.count() > 1 or self.buffer.isDirty()) { |
| 338 | if (!try self.killCurrentBuffer()) { | 338 | if (!try self.killCurrentBuffer()) { |
| 339 | return; | 339 | return; |
| 340 | } | 340 | } |
diff --git a/src/Row.zig b/src/Row.zig index b8e1674..913253c 100644 --- a/src/Row.zig +++ b/src/Row.zig | |||
| @@ -59,7 +59,7 @@ pub fn cleanWhiteSpace(self: *Row, buf: *Buffer) !void { | |||
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | if (orig_len != self.data.items.len) { | 61 | if (orig_len != self.data.items.len) { |
| 62 | buf.dirty = true; | 62 | buf.edited = true; |
| 63 | try self.update(buf); | 63 | try self.update(buf); |
| 64 | } | 64 | } |
| 65 | } | 65 | } |