diff options
author | Mark Lumsden <lum@cvs.openbsd.org> | 2015-09-24 01:24:11 +0000 |
---|---|---|
committer | Mark Lumsden <lum@cvs.openbsd.org> | 2015-09-24 01:24:11 +0000 |
commit | 9a7e15f99fe787c57c932458040eeb08513192f9 (patch) | |
tree | e3eed99a7c437bad621d629e8f794fbab3e66a63 | |
parent | 60734f3c1f26d9595242226301c1c00ff4e066b4 (diff) |
Fix multiple iterations of kill-paragraph. ok jasper@
-rw-r--r-- | usr.bin/mg/paragraph.c | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/usr.bin/mg/paragraph.c b/usr.bin/mg/paragraph.c index cf24ca0833a..cbe3999e3ad 100644 --- a/usr.bin/mg/paragraph.c +++ b/usr.bin/mg/paragraph.c @@ -1,4 +1,4 @@ -/* $OpenBSD: paragraph.c,v 1.36 2015/03/19 21:22:15 bcallah Exp $ */ +/* $OpenBSD: paragraph.c,v 1.37 2015/09/24 01:24:10 lum Exp $ */ /* This file is in the public domain. */ @@ -20,6 +20,8 @@ static int fillcol = 70; #define MAXWORD 256 +static int findpara(void); + /* * Move to start of paragraph. * Move backwards by line, checking from the 1st character forwards for the @@ -251,32 +253,57 @@ cleanup: int killpara(int f, int n) { - int status, end = FALSE; /* returned status of functions */ + int lineno, status; + + if (findpara() == FALSE) + return (TRUE); - /* for each paragraph to delete */ - while (n--) { + /* go to the beginning of the paragraph */ + (void)gotobop(FFRAND, 1); - /* mark out the end and beginning of the para to delete */ - if (!gotoeop(FFRAND, 1)) - end = TRUE; + /* take a note of the line number for after deletions and set mark */ + lineno = curwp->w_dotline; + curwp->w_markp = curwp->w_dotp; + curwp->w_marko = curwp->w_doto; - /* set the mark here */ - curwp->w_markp = curwp->w_dotp; - curwp->w_marko = curwp->w_doto; + (void)gotoeop(FFRAND, n); - /* go to the beginning of the paragraph */ - (void)gotobop(FFRAND, 1); + if ((status = killregion(FFRAND, 1)) != TRUE) + return (status); - /* force us to the beginning of line */ + curwp->w_dotline = lineno; + return (TRUE); +} + +/* + * Go down the buffer until we find text. + */ +int +findpara(void) +{ + int col, nospace = 0; + + /* we move forward to find a para to mark */ + do { curwp->w_doto = 0; + col = 0; + + /* check if we are on a blank line */ + while (col < llength(curwp->w_dotp)) { + if (!isspace(lgetc(curwp->w_dotp, col))) + nospace = 1; + col++; + } + if (nospace) + break; + + if (lforw(curwp->w_dotp) == curbp->b_headp) + return (FALSE); - /* and delete it */ - if ((status = killregion(FFRAND, 1)) != TRUE) - return (status); + curwp->w_dotp = lforw(curwp->w_dotp); + curwp->w_dotline++; + } while (1); - if (end) - return (TRUE); - } return (TRUE); } |