While I am 'paragraph' mode, here is the useful 'transpose-paragraph'
command. Comments/ok?
mark
Index: def.h
===================================================================
RCS file: /cvs/src/usr.bin/mg/def.h,v
retrieving revision 1.148
diff -u -p -u -p -r1.148 def.h
--- def.h 24 Sep 2015 07:07:59 -0000 1.148
+++ def.h 24 Sep 2015 18:15:38 -0000
@@ -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);
Index: funmap.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/funmap.c,v
retrieving revision 1.50
diff -u -p -u -p -r1.50 funmap.c
--- funmap.c 24 Sep 2015 07:07:59 -0000 1.50
+++ funmap.c 24 Sep 2015 18:15:38 -0000
@@ -200,6 +200,7 @@ static struct funmap functnames[] = {
{poptobuffer, "switch-to-buffer-other-window",},
{togglereadonly, "toggle-read-only" },
{twiddle, "transpose-chars",},
+ {transposepara, "transpose-paragraph",},
{undo, "undo",},
{undo_add_boundary, "undo-boundary",},
{undo_boundary_enable, "undo-boundary-toggle",},
Index: mg.1
===================================================================
RCS file: /cvs/src/usr.bin/mg/mg.1,v
retrieving revision 1.92
diff -u -p -u -p -r1.92 mg.1
--- mg.1 24 Sep 2015 07:07:59 -0000 1.92
+++ mg.1 24 Sep 2015 18:15:38 -0000
@@ -874,6 +874,10 @@ Toggle the read-only flag on the current
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-paragraph
+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,
Index: paragraph.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/paragraph.c,v
retrieving revision 1.39
diff -u -p -u -p -r1.39 paragraph.c
--- paragraph.c 24 Sep 2015 07:20:12 -0000 1.39
+++ paragraph.c 24 Sep 2015 18:15:38 -0000
@@ -314,6 +314,50 @@ markpara(int f, int n)
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);
+}
+
+
/*
* Go down the buffer until we find a line with non-space characters.
*/