vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 6f509c21437d5d94cbeeba255985b4a49b9cf3f6 parent 6d10d544a1703a58bbdf123c45f6069971bf2c46 Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 17 Jul 2014 13:24:03 +0200 Implement modification detection Diffstat:
| M | editor.c | | | 9 | ++++++--- |
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/editor.c b/editor.c @@ -85,6 +85,7 @@ struct Editor { Piece begin, end; /* sentinel nodes which always exists but don't hold any data */ Action *redo, *undo; /* two stacks holding all actions performed to the file */ Action *current_action; /* action holding all file changes until a snapshot is performed */ + Action *saved_action; /* the last action at the time of the save operation */ size_t size; /* current file content size in bytes */ const char *filename; /* filename of which data was loaded */ struct stat info; /* stat as proped on load time */ @@ -411,7 +412,10 @@ int editor_save(Editor *ed, const char *filename) { } if (close(fd) == -1) return -1; - return rename(tmpname, filename); + if (rename(tmpname, filename) == -1) + return -1; + ed->saved_action = ed->undo; + editor_snapshot(ed); err: close(fd); return -1; @@ -591,6 +595,5 @@ void editor_free(Editor *ed) { } bool editor_modified(Editor *ed) { - // TODO: not correct after save - return ed->undo != NULL; + return ed->saved_action != ed->undo; }