Here's another command I always miss while working with mg.
diff -up src/usr.bin/mg.old/def.h src/usr.bin/mg/def.h
--- src/usr.bin/mg.old/def.h Fri Jan 14 17:27:17 2011
+++ src/usr.bin/mg/def.h Fri Jan 14 17:49:34 2011
@@ -512,6 +512,7 @@ int forwdel(int, int);
int backdel(int, int);
int space_to_tabstop(int, int);
int backtoindent(int, int);
+int joinline(int, int);
/* extend.c X */
int insert(int, int);
diff -up src/usr.bin/mg.old/funmap.c src/usr.bin/mg/funmap.c
--- src/usr.bin/mg.old/funmap.c Fri Jan 14 17:27:17 2011
+++ src/usr.bin/mg/funmap.c Fri Jan 14 17:50:55 2011
@@ -103,6 +103,7 @@ static struct funmap functnames[] = {
{fillword, "insert-with-wrap",},
{backisearch, "isearch-backward",},
{forwisearch, "isearch-forward",},
+ {joinline, "join-line",},
{justone, "just-one-space",},
{ctrlg, "keyboard-quit",},
{killbuffer_cmd, "kill-buffer",},
diff -up src/usr.bin/mg.old/keymap.c src/usr.bin/mg/keymap.c
--- src/usr.bin/mg.old/keymap.c Fri Jan 14 18:41:34 2011
+++ src/usr.bin/mg/keymap.c Fri Jan 14 17:52:04 2011
@@ -228,7 +228,7 @@ static PF metasqf[] = {
NULL, /* [ */
delwhite, /* \ */
rescan, /* ] */
- rescan, /* ^ */
+ joinline, /* ^ */
rescan, /* _ */
rescan, /* ` */
rescan, /* a */
diff -up src/usr.bin/mg.old/mg.1 src/usr.bin/mg/mg.1
--- src/usr.bin/mg.old/mg.1 Fri Jan 14 17:27:17 2011
+++ src/usr.bin/mg/mg.1 Fri Jan 14 18:35:02 2011
@@ -220,6 +220,8 @@ beginning-of-buffer
end-of-buffer
.It M-\e
delete-horizontal-space
+.It M-^
+join-line
.It M-b
backward-word
.It M-c
@@ -510,6 +512,9 @@ Use incremental searching, initially in the forward di
isearch ignores any explicit arguments.
If invoked during macro definition or evaluation, the non-incremental
search-forward is invoked instead.
+.It join-line
+Join the current line to the previous. If called with an argument,
+join the next line to the current one.
.It just-one-space
Delete any whitespace around dot, then insert a space.
.It keyboard-quit
diff -up src/usr.bin/mg.old/random.c src/usr.bin/mg/random.c
--- src/usr.bin/mg.old/random.c Fri Jan 14 17:27:17 2011
+++ src/usr.bin/mg/random.c Fri Jan 14 18:45:16 2011
@@ -453,3 +453,31 @@ backtoindent(int f, int n)
++curwp->w_doto;
return (TRUE);
}
+
+/*
+ * Join the current line to the previous, or with arg, the next line
+ * to the current one. If the former line is not empty, leave exactly
+ * one space at the joint. Otherwise, leave no whitespace.
+ */
+int
+joinline(int f, int n)
+{
+ int doto;
+
+ if (f & FFARG) {
+ gotoeol(FFRAND, 1);
+ forwdel(FFRAND, 1);
+ } else {
+ gotobol(FFRAND, 1);
+ backdel(FFRAND, 1);
+ }
+
+ delwhite(FFRAND, 1);
+
+ if ((doto = curwp->w_doto) > 0) {
+ linsert(1, ' ');
+ curwp->w_doto = doto;
+ }
+
+ return (TRUE);
+}