diff options
author | Mark Lumsden <lum@cvs.openbsd.org> | 2015-09-23 05:03:04 +0000 |
---|---|---|
committer | Mark Lumsden <lum@cvs.openbsd.org> | 2015-09-23 05:03:04 +0000 |
commit | 862c5e15d06293fdd79f850f89f209f76302a1e8 (patch) | |
tree | 619e8f60fc5ffbf4038d7e1eb7c3186395208c40 /usr.bin/mg | |
parent | 74831957ef5b00727c66ce933deae227d19ebac5 (diff) |
fix line number handling in dired delete functions.
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/dired.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c index 50cab3f9dfd..190b7f546af 100644 --- a/usr.bin/mg/dired.c +++ b/usr.bin/mg/dired.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dired.c,v 1.73 2015/09/21 06:59:54 lum Exp $ */ +/* $OpenBSD: dired.c,v 1.74 2015/09/23 05:03:03 lum Exp $ */ /* This file is in the public domain. */ @@ -273,8 +273,10 @@ d_del(int f, int n) while (n--) { if (llength(curwp->w_dotp) > 0) lputc(curwp->w_dotp, 0, 'D'); - if (lforw(curwp->w_dotp) != curbp->b_headp) + if (lforw(curwp->w_dotp) != curbp->b_headp) { curwp->w_dotp = lforw(curwp->w_dotp); + curwp->w_dotline++; + } } curwp->w_rflag |= WFEDIT | WFMOVE; return (d_warpdot(curwp->w_dotp, &curwp->w_doto)); @@ -289,8 +291,10 @@ d_undel(int f, int n) while (n--) { if (llength(curwp->w_dotp) > 0) lputc(curwp->w_dotp, 0, ' '); - if (lforw(curwp->w_dotp) != curbp->b_headp) + if (lforw(curwp->w_dotp) != curbp->b_headp) { curwp->w_dotp = lforw(curwp->w_dotp); + curwp->w_dotline++; + } } curwp->w_rflag |= WFEDIT | WFMOVE; return (d_warpdot(curwp->w_dotp, &curwp->w_doto)); @@ -303,8 +307,10 @@ d_undelbak(int f, int n) if (n < 0) return (d_undel(f, -n)); while (n--) { - if (lback(curwp->w_dotp) != curbp->b_headp) + if (lback(curwp->w_dotp) != curbp->b_headp) { curwp->w_dotp = lback(curwp->w_dotp); + curwp->w_dotline--; + } if (llength(curwp->w_dotp) > 0) lputc(curwp->w_dotp, 0, ' '); } @@ -364,20 +370,27 @@ d_expunge(int f, int n) { struct line *lp, *nlp; char fname[NFILEN], sname[NFILEN]; + int tmp; + + tmp = curwp->w_dotline; + curwp->w_dotline = 0; for (lp = bfirstlp(curbp); lp != curbp->b_headp; lp = nlp) { + curwp->w_dotline++; nlp = lforw(lp); if (llength(lp) && lgetc(lp, 0) == 'D') { switch (d_makename(lp, fname, sizeof(fname))) { case ABORT: dobeep(); ewprintf("Bad line in dired buffer"); + curwp->w_dotline = tmp; return (FALSE); case FALSE: if (unlink(fname) < 0) { (void)xbasename(sname, fname, NFILEN); dobeep(); ewprintf("Could not delete '%s'", sname); + curwp->w_dotline = tmp; return (FALSE); } break; @@ -387,15 +400,19 @@ d_expunge(int f, int n) dobeep(); ewprintf("Could not delete directory " "'%s'", sname); + curwp->w_dotline = tmp; return (FALSE); } break; } lfree(lp); curwp->w_bufp->b_lines--; + if (tmp > curwp->w_dotline) + tmp--; curwp->w_rflag |= WFFULL; } } + curwp->w_dotline = tmp; return (TRUE); } |