commit 7b4af7e0476a5ef0427e2f66921dd164052ed06f
parent f7835588a3b9d7411ecbbdbe133191ccec714e50
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 13 Dec 2015 20:47:51 +0100
Undo only last command
It is important to discard the undo data of
previous commands, because in other case
undo() will undo all the edit work.
Diffstat:
1 file changed, 7 insertions(+), 0 deletions(-)
diff --git a/ed.c b/ed.c
@@ -60,6 +60,7 @@ int repidx;
char *rhs;
char *lastmatch;
struct undo udata;
+int newcmd;
static void
error(char *msg)
@@ -230,6 +231,11 @@ relink(int to1, int from1, int from2, int to2)
{
struct link *p;
+ if (newcmd) {
+ free(udata.vec);
+ udata.vec = NULL;
+ newcmd = udata.nr = udata.cap = 0;
+ }
if (udata.nr >= udata.cap) {
size_t siz = (udata.cap + 10) * sizeof(struct link);
if ((p = realloc(udata.vec, siz)) == NULL)
@@ -1352,6 +1358,7 @@ main(int argc, char *argv[])
}
for (;;) {
+ newcmd = 1;
cmdsiz = 0;
repidx = -1;
if (optprompt)