diff options
author | Vincent Labrecque <vincent@cvs.openbsd.org> | 2002-02-21 04:16:28 +0000 |
---|---|---|
committer | Vincent Labrecque <vincent@cvs.openbsd.org> | 2002-02-21 04:16:28 +0000 |
commit | 632b5fbb8d19d35bfed874eb4647b36ab4ffb58c (patch) | |
tree | d208fa965f238a8fa0224fa5621f8abce8356a52 /usr.bin | |
parent | 0395d46f469f6dd61a81c8e715f4e8480b972ce8 (diff) |
Don't ignore the argument to undo. (makes ^U work)
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/def.h | 4 | ||||
-rw-r--r-- | usr.bin/mg/undo.c | 89 |
2 files changed, 48 insertions, 45 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 036fcc9f95f..b4a49d18490 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.31 2002/02/21 00:02:04 deraadt Exp $ */ +/* $OpenBSD: def.h,v 1.32 2002/02/21 04:16:27 vincent Exp $ */ #include <sys/queue.h> @@ -578,7 +578,7 @@ int undo_add_boundary(void); int undo_add_insert(LINE *, int, int); int undo_add_delete(LINE *, int, int); int undo_add_change(LINE *, int, int); -int undo(void); +int undo(int, int); /* * Externals. diff --git a/usr.bin/mg/undo.c b/usr.bin/mg/undo.c index 6e8b5d2f532..1866d7432d5 100644 --- a/usr.bin/mg/undo.c +++ b/usr.bin/mg/undo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: undo.c,v 1.3 2002/02/21 03:24:14 vincent Exp $ */ +/* $OpenBSD: undo.c,v 1.4 2002/02/21 04:16:27 vincent Exp $ */ /* * Copyright (c) 2002 Vincent Labrecque <vincent@openbsd.org> * All rights reserved. @@ -373,58 +373,61 @@ undo_add_change(LINE *lp, int offset, int size) } int -undo(void) +undo(int f, int n) { struct undo_rec *rec; LINE *ln; int off; - again: - rec = LIST_FIRST(&undo_list); - if (rec == NULL) { - ewprintf("Nothing to undo!"); - return FALSE; - } - if (rec->buf != curbp) - popbuf(rec->buf); - - LIST_REMOVE(rec, next); - if (rec->type == BOUNDARY) - goto again; - /* - * Let called functions know they are below us (for example, ldelete - * don't want to record an undo record when called by us) + * Let called functions know they are below us (for + * example, ldelete don't want to record an undo record + * when called by us) */ undoaction++; - find_linep(rec->pos, &ln, &off); - if (ln == NULL) - return FALSE; - - /* - * Move to where this record has to apply - */ - curwp->w_dotp = ln; - curwp->w_doto = off; - - switch (rec->type) { - case INSERT: - ldelete(rec->region.r_size, KFORW); - break; - case DELETE: - region_put_data(rec->content, rec->region.r_size); - break; - case CHANGE: - forwchar(0, rec->region.r_size); - lreplace(rec->region.r_size, rec->content, 1); - break; - default: - break; - } - - free_undo_record(rec); + while (n-- > 0) { + rec = LIST_FIRST(&undo_list); + if (rec == NULL) { + ewprintf("Nothing to undo!"); + return FALSE; + } + if (rec->buf != curbp) + popbuf(rec->buf); + + LIST_REMOVE(rec, next); + if (rec->type == BOUNDARY) { + n++; /* XXX */ + continue; + } + find_linep(rec->pos, &ln, &off); + if (ln == NULL) + return FALSE; + + /* + * Move to where this record has to apply + */ + curwp->w_dotp = ln; + curwp->w_doto = off; + + switch (rec->type) { + case INSERT: + ldelete(rec->region.r_size, KFORW); + break; + case DELETE: + region_put_data(rec->content, rec->region.r_size); + break; + case CHANGE: + forwchar(0, rec->region.r_size); + lreplace(rec->region.r_size, rec->content, 1); + break; + default: + break; + } + + free_undo_record(rec); + } undoaction--; return TRUE; |