summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/buffer.c b/buffer.c
index a3d9c51..28ec364 100644
--- a/buffer.c
+++ b/buffer.c
@@ -112,7 +112,6 @@ void buffer_create(TextBuffer *buffer, Ted *ted) {
buffer->ted = ted;
}
-
void line_buffer_create(TextBuffer *buffer, Ted *ted) {
buffer_create(buffer, ted);
buffer->is_line_buffer = true;
@@ -142,6 +141,21 @@ static bool buffer_pos_valid(TextBuffer *buffer, BufferPos p) {
return p.line < buffer->nlines && p.index <= buffer->lines[p.line].len;
}
+// write a buffer position to a file
+void buffer_pos_write(BufferPos pos, FILE *fp) {
+ write_u32(fp, pos.line);
+ write_u32(fp, pos.index);
+}
+
+// read a buffer position from a file, and validate it
+BufferPos buffer_pos_read(TextBuffer *buffer, FILE *fp) {
+ BufferPos pos = {0};
+ pos.line = read_u32(fp);
+ pos.index = read_u32(fp);
+ buffer_pos_validate(buffer, &pos);
+ return pos;
+}
+
// are there any unsaved changes?
bool buffer_unsaved_changes(TextBuffer *buffer) {
if (buffer_is_untitled(buffer) && buffer_empty(buffer))