=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/paragraph.c,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- src/usr.bin/mg/paragraph.c 2015/09/24 07:20:12 1.39 +++ src/usr.bin/mg/paragraph.c 2015/09/26 15:03:15 1.40 @@ -1,4 +1,4 @@ -/* $OpenBSD: paragraph.c,v 1.39 2015/09/24 07:20:12 lum Exp $ */ +/* $OpenBSD: paragraph.c,v 1.40 2015/09/26 15:03:15 lum Exp $ */ /* This file is in the public domain. */ @@ -310,6 +310,48 @@ curwp->w_marko = curwp->w_doto; (void)gotobop(FFRAND, i); + + return (TRUE); +} + +/* + * Transpose the current paragraph with the following paragraph. If invoked + * multiple times, transpose to the n'th paragraph. If invoked between + * paragraphs, move to the previous paragraph, then continue. + */ +/* ARGSUSED */ +int +transposepara(int f, int n) +{ + int i = 0, status; + char flg; + + /* find a paragraph, set mark, then goto the end */ + gotobop(FFRAND, 1); + curwp->w_markp = curwp->w_dotp; + curwp->w_marko = curwp->w_doto; + (void)gotoeop(FFRAND, 1); + + /* take a note of buffer flags - we may need them */ + flg = curbp->b_flag; + + /* clean out kill buffer then kill region */ + kdelete(); + if ((status = killregion(FFRAND, 1)) != TRUE) + return (status); + + /* + * Now step through n paragraphs. If we reach the end of buffer, + * stop and paste the killed region back, then display a message. + */ + if (do_gotoeop(FFRAND, n, &i) == FALSE) { + ewprintf("Cannot transpose paragraph, end of buffer reached."); + (void)gotobop(FFRAND, i); + (void)yank(FFRAND, 1); + curbp->b_flag = flg; + return (FALSE); + } + (void)yank(FFRAND, 1); return (TRUE); }