diff options
author | Mark Lumsden <lum@cvs.openbsd.org> | 2015-09-26 15:03:16 +0000 |
---|---|---|
committer | Mark Lumsden <lum@cvs.openbsd.org> | 2015-09-26 15:03:16 +0000 |
commit | b4ca701784506aeb3453783b8b1ea79a9e791711 (patch) | |
tree | 8a81231301364e7bab2bc0e82348ae4bb659ccbc /usr.bin | |
parent | af711b0d8661eccebad52ad434d401dfad977c66 (diff) |
Add transpose-paragraphs. ok jasper@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/def.h | 3 | ||||
-rw-r--r-- | usr.bin/mg/funmap.c | 3 | ||||
-rw-r--r-- | usr.bin/mg/mg.1 | 8 | ||||
-rw-r--r-- | usr.bin/mg/paragraph.c | 44 |
4 files changed, 53 insertions, 5 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index 8c0007d6625..e8f466fd716 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.148 2015/09/24 07:07:59 lum Exp $ */ +/* $OpenBSD: def.h,v 1.149 2015/09/26 15:03:15 lum Exp $ */ /* This file is in the public domain. */ @@ -588,6 +588,7 @@ int killpara(int, int); int fillword(int, int); int setfillcol(int, int); int markpara(int, int); +int transposepara(int, int); /* word.c X */ int backword(int, int); diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c index 8bb67fdbd2e..2571526897b 100644 --- a/usr.bin/mg/funmap.c +++ b/usr.bin/mg/funmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: funmap.c,v 1.50 2015/09/24 07:07:59 lum Exp $ */ +/* $OpenBSD: funmap.c,v 1.51 2015/09/26 15:03:15 lum Exp $ */ /* This file is in the public domain */ @@ -200,6 +200,7 @@ static struct funmap functnames[] = { {poptobuffer, "switch-to-buffer-other-window",}, {togglereadonly, "toggle-read-only" }, {twiddle, "transpose-chars",}, + {transposepara, "transpose-paragraphs",}, {undo, "undo",}, {undo_add_boundary, "undo-boundary",}, {undo_boundary_enable, "undo-boundary-toggle",}, diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1 index f2ed9732d70..41f2b4a70dd 100644 --- a/usr.bin/mg/mg.1 +++ b/usr.bin/mg/mg.1 @@ -1,7 +1,7 @@ -.\" $OpenBSD: mg.1,v 1.92 2015/09/24 07:07:59 lum Exp $ +.\" $OpenBSD: mg.1,v 1.93 2015/09/26 15:03:15 lum Exp $ .\" This file is in the public domain. .\" -.Dd $Mdocdate: September 24 2015 $ +.Dd $Mdocdate: September 26 2015 $ .Dt MG 1 .Os .Sh NAME @@ -874,6 +874,10 @@ Toggle the read-only flag on the current buffer. Transpose the two characters in front of and under dot, then move forward one character. Treat newline characters the same as any other. +.It transpose-paragraphs +Transpose adjacent paragraphs. +If multiple iterations are requested, the current paragraph will +be moved n paragraphs forward. .It undo Undo the most recent action. If invoked again without an intervening command, diff --git a/usr.bin/mg/paragraph.c b/usr.bin/mg/paragraph.c index 216c37ef2da..14d695143fc 100644 --- a/usr.bin/mg/paragraph.c +++ b/usr.bin/mg/paragraph.c @@ -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. */ @@ -315,6 +315,48 @@ markpara(int f, int n) } /* + * 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); +} + +/* * Go down the buffer until we find a line with non-space characters. */ int |