diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2011-01-19 16:11:39 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2011-01-19 16:11:39 +0000 |
commit | 3769f5ab1677f1c7bd63fee372f9b93fec1e3f81 (patch) | |
tree | a32658023f8e69ba75d658e346aed6bd1f9d5a9d | |
parent | 54ec25cc0a86e7937c37c801272dac1336af86b5 (diff) |
patch from Henri Kemppainen:
clean up undo boundaries for functions in random.c
This catches an error, where twiddling in an empty file could
disable undo boundaries for the rest of the session.
proper undo boundaries around newline() will have to wait until
proper reference counting is done... Thanks!
-rw-r--r-- | usr.bin/mg/random.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/usr.bin/mg/random.c b/usr.bin/mg/random.c index 0e00fbceeab..70ef6d474dd 100644 --- a/usr.bin/mg/random.c +++ b/usr.bin/mg/random.c @@ -1,4 +1,4 @@ -/* $OpenBSD: random.c,v 1.28 2011/01/18 16:25:40 kjell Exp $ */ +/* $OpenBSD: random.c,v 1.29 2011/01/19 16:11:38 kjell Exp $ */ /* This file is in the public domain. */ @@ -119,7 +119,6 @@ twiddle(int f, int n) dotp = curwp->w_dotp; doto = curwp->w_doto; - undo_boundary_enable(FFRAND, 0); if (doto == llength(dotp)) { if (--doto <= 0) return (FALSE); @@ -129,6 +128,7 @@ twiddle(int f, int n) if (doto == 0) return (FALSE); } + undo_boundary_enable(FFRAND, 0); cr = lgetc(dotp, doto - 1); (void)backdel(FFRAND, 1); (void)forwchar(FFRAND, 1); @@ -158,6 +158,7 @@ openline(int f, int n) return (TRUE); /* insert newlines */ + undo_boundary_enable(FFRAND, 0); i = n; do { s = lnewline(); @@ -166,6 +167,7 @@ openline(int f, int n) /* then go back up overtop of them all */ if (s == TRUE) s = backchar(f | FFRAND, n); + undo_boundary_enable(FFRAND, 1); return (s); } @@ -223,8 +225,11 @@ deblank(int f, int n) int justone(int f, int n) { + undo_boundary_enable(FFRAND, 0); (void)delwhite(f, n); - return (linsert(1, ' ')); + linsert(1, ' '); + undo_boundary_enable(FFRAND, 1); + return (TRUE); } /* @@ -318,10 +323,12 @@ int lfindent(int f, int n) { int c, i, nicol; + int s = TRUE; if (n < 0) return (FALSE); + undo_boundary_enable(FFRAND, 0); while (n--) { nicol = 0; for (i = 0; i < llength(curwp->w_dotp); ++i) { @@ -337,10 +344,13 @@ lfindent(int f, int n) curbp->b_flag & BFNOTAB) ? linsert(nicol, ' ') == FALSE : ( #endif /* NOTAB */ ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE) || - ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE)))) - return (FALSE); + ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE)))) { + s = FALSE; + break; + } } - return (TRUE); + undo_boundary_enable(FFRAND, 1); + return (s); } /* |