ed

simple ed
git clone git://git.2f30.org/ed
Log | Files | Refs | LICENSE

commit de8be38be7f9111fc80f747c519037f5a18e7b29
parent 7b4af7e0476a5ef0427e2f66921dd164052ed06f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 13 Dec 2015 20:53:29 +0100

Discard undo data after new edit

Every time we read a file for editing (first use of r,
or any use of e and E) we have to clear the undo data,
because we cannot undo the action.

Diffstat:
Med.c | 19++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/ed.c b/ed.c @@ -227,15 +227,20 @@ setglobal(int i, int v) } static void +clearundo(void) +{ + free(udata.vec); + udata.vec = NULL; + newcmd = udata.nr = udata.cap = 0; +} + +static void 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 (newcmd) + clearundo(); if (udata.nr >= udata.cap) { size_t siz = (udata.cap + 10) * sizeof(struct link); if ((p = realloc(udata.vec, siz)) == NULL) @@ -312,6 +317,7 @@ setscratch() int k; clearbuf(); + clearundo(); strcpy(tmpname, "ed.XXXXXX"); if ((scratch = mkstemp(tmpname)) < 0) { /* try /tmp if cwd is not writable */ @@ -322,6 +328,7 @@ setscratch() if ((k = makeline("", NULL))) error("input/output error in scratch file"); relink(k, k, k, k); + clearundo(); modflag = 0; } @@ -607,6 +614,7 @@ doread(char *fname) if (savfname[0] == '\0') { modflag = 0; + clearundo(); strcpy(savfname, fname); } } @@ -1188,6 +1196,7 @@ repeat: strcpy(savfname, getfname()); deflines(curln, curln); doread(savfname); + clearundo(); modflag = 0; break; default: