summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>2011-01-18 16:25:41 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>2011-01-18 16:25:41 +0000
commit96d64c06e48f39d450e390fcd67a41778a97945e (patch)
tree51673c683979d59ad353eb526cfb203cabc32189
parent249d2fa75589fafb352e1fcce62e56ef3725d855 (diff)
Add join-line, bound to M-^
Join the current line to the previous. original diff by Henri Kemppainen. minor mod to add undo boundaries. Thanks!
-rw-r--r--usr.bin/mg/def.h3
-rw-r--r--usr.bin/mg/funmap.c3
-rw-r--r--usr.bin/mg/keymap.c4
-rw-r--r--usr.bin/mg/mg.19
-rw-r--r--usr.bin/mg/random.c32
5 files changed, 44 insertions, 7 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index d9abec3e367..ef26daa3595 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.114 2011/01/17 03:12:06 kjell Exp $ */
+/* $OpenBSD: def.h,v 1.115 2011/01/18 16:25:40 kjell Exp $ */
/* This file is in the public domain. */
@@ -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 --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c
index 0ec02a031f2..b274aa208da 100644
--- a/usr.bin/mg/funmap.c
+++ b/usr.bin/mg/funmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: funmap.c,v 1.33 2011/01/17 03:12:06 kjell Exp $ */
+/* $OpenBSD: funmap.c,v 1.34 2011/01/18 16:25:40 kjell Exp $ */
/* This file is in the public domain */
@@ -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 --git a/usr.bin/mg/keymap.c b/usr.bin/mg/keymap.c
index 8cb89f96647..099405ef24d 100644
--- a/usr.bin/mg/keymap.c
+++ b/usr.bin/mg/keymap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keymap.c,v 1.44 2011/01/17 03:12:06 kjell Exp $ */
+/* $OpenBSD: keymap.c,v 1.45 2011/01/18 16:25:40 kjell Exp $ */
/* This file is in the public domain. */
@@ -228,7 +228,7 @@ static PF metasqf[] = {
NULL, /* [ */
delwhite, /* \ */
rescan, /* ] */
- rescan, /* ^ */
+ joinline, /* ^ */
rescan, /* _ */
rescan, /* ` */
rescan, /* a */
diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1
index aa467398f85..ad0088e63c4 100644
--- a/usr.bin/mg/mg.1
+++ b/usr.bin/mg/mg.1
@@ -1,7 +1,7 @@
-.\" $OpenBSD: mg.1,v 1.48 2011/01/17 03:12:06 kjell Exp $
+.\" $OpenBSD: mg.1,v 1.49 2011/01/18 16:25:40 kjell Exp $
.\" This file is in the public domain.
.\"
-.Dd $Mdocdate: January 17 2011 $
+.Dd $Mdocdate: January 18 2011 $
.Dt MG 1
.Os
.Sh NAME
@@ -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 direction.
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 --git a/usr.bin/mg/random.c b/usr.bin/mg/random.c
index a3c3893e4b5..0e00fbceeab 100644
--- a/usr.bin/mg/random.c
+++ b/usr.bin/mg/random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: random.c,v 1.27 2011/01/17 03:12:06 kjell Exp $ */
+/* $OpenBSD: random.c,v 1.28 2011/01/18 16:25:40 kjell Exp $ */
/* This file is in the public domain. */
@@ -453,3 +453,33 @@ 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;
+
+ undo_boundary_enable(FFRAND, 0);
+ 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;
+ }
+ undo_boundary_enable(FFRAND, 1);
+
+ return (TRUE);
+}