summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkjell <kjell@openbsd.org>2009-06-05 18:02:06 +0000
committerkjell <kjell@openbsd.org>2009-06-05 18:02:06 +0000
commit5df198997757c2fb711c0aedb4cf5231a8b8a718 (patch)
treebf96b94beb24a97ff71a1eb4eb549cb4c6eacb9d
parentClear screen to clean up after X. (diff)
downloadwireguard-openbsd-5df198997757c2fb711c0aedb4cf5231a8b8a718.tar.xz
wireguard-openbsd-5df198997757c2fb711c0aedb4cf5231a8b8a718.zip
emacs handles the undo of a region kill (C-w) differently than a line kill
(C-k) with respect to cursor position. The former leaves the cursor at the end, the latter at the beginning of the region. emacs is wacky. Make mg undo do the same. ok deraadt
-rw-r--r--usr.bin/mg/def.h14
-rw-r--r--usr.bin/mg/line.c4
-rw-r--r--usr.bin/mg/region.c4
-rw-r--r--usr.bin/mg/undo.c21
-rw-r--r--usr.bin/mg/yank.c9
5 files changed, 30 insertions, 22 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index e7b79b87a95..b1f2af8b008 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.111 2009/06/04 23:39:37 kjell Exp $ */
+/* $OpenBSD: def.h,v 1.112 2009/06/05 18:02:06 kjell Exp $ */
/* This file is in the public domain. */
@@ -104,9 +104,10 @@ typedef int (*PF)(int, int); /* generally useful type */
/*
* Direction of insert into kill ring
*/
-#define KNONE 0
-#define KFORW 1
-#define KBACK 2
+#define KNONE 0x00
+#define KFORW 0x01 /* forward insert into kill ring */
+#define KBACK 0x02 /* Backwards insert into kill ring */
+#define KREG 0x04 /* This is a region-based kill */
/*
* This structure holds the starting position
@@ -291,7 +292,8 @@ struct undo_rec {
INSERT = 1,
DELETE,
BOUNDARY,
- MODIFIED
+ MODIFIED,
+ DELREG
} type;
struct region region;
int pos;
@@ -620,7 +622,7 @@ int undo_enable(int, int);
int undo_add_boundary(int, int);
void undo_add_modified(void);
int undo_add_insert(struct line *, int, int);
-int undo_add_delete(struct line *, int, int);
+int undo_add_delete(struct line *, int, int, int);
int undo_boundary_enable(int, int);
int undo_add_change(struct line *, int, int);
int undo(int, int);
diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c
index 23d07945b2d..7c1b027dd4b 100644
--- a/usr.bin/mg/line.c
+++ b/usr.bin/mg/line.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: line.c,v 1.47 2009/06/04 02:23:37 kjell Exp $ */
+/* $OpenBSD: line.c,v 1.48 2009/06/05 18:02:06 kjell Exp $ */
/* This file is in the public domain. */
@@ -438,7 +438,7 @@ ldelete(RSIZE n, int kflag)
return (FALSE);
end = 0;
- undo_add_delete(curwp->w_dotp, curwp->w_doto, n);
+ undo_add_delete(curwp->w_dotp, curwp->w_doto, n, (kflag & KREG));
while (n != 0) {
dotp = curwp->w_dotp;
diff --git a/usr.bin/mg/region.c b/usr.bin/mg/region.c
index 3a554a47002..eba11a25486 100644
--- a/usr.bin/mg/region.c
+++ b/usr.bin/mg/region.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: region.c,v 1.28 2009/06/04 23:31:48 kjell Exp $ */
+/* $OpenBSD: region.c,v 1.29 2009/06/05 18:02:06 kjell Exp $ */
/* This file is in the public domain. */
@@ -34,7 +34,7 @@ killregion(int f, int n)
curwp->w_dotp = region.r_linep;
curwp->w_doto = region.r_offset;
curwp->w_dotline = region.r_lineno;
- s = ldelete(region.r_size, KFORW);
+ s = ldelete(region.r_size, KFORW | KREG);
clearmark(FFARG, 0);
return (s);
diff --git a/usr.bin/mg/undo.c b/usr.bin/mg/undo.c
index 92d8d0d57e1..c3e13b9b1c7 100644
--- a/usr.bin/mg/undo.c
+++ b/usr.bin/mg/undo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: undo.c,v 1.48 2009/06/04 23:39:37 kjell Exp $ */
+/* $OpenBSD: undo.c,v 1.49 2009/06/05 18:02:06 kjell Exp $ */
/*
* This file is in the public domain
*/
@@ -294,7 +294,7 @@ undo_add_insert(struct line *lp, int offset, int size)
* This of course must be done _before_ the actual deletion is done.
*/
int
-undo_add_delete(struct line *lp, int offset, int size)
+undo_add_delete(struct line *lp, int offset, int size, int isreg)
{
struct region reg;
struct undo_rec *rec;
@@ -316,15 +316,17 @@ undo_add_delete(struct line *lp, int offset, int size)
* Separate this command from the previous one if we're not
* just before the previous record...
*/
- if (rec->type == DELETE) {
+ if (!isreg && rec->type == DELETE) {
if (rec->pos - rec->region.r_size != pos)
undo_add_boundary(FFRAND, 1);
}
}
rec = new_undo_record();
rec->pos = pos;
-
- rec->type = DELETE;
+ if (isreg)
+ rec->type = DELREG;
+ else
+ rec->type = DELETE;
memmove(&rec->region, &reg, sizeof(struct region));
do {
rec->content = malloc(reg.r_size + 1);
@@ -335,7 +337,7 @@ undo_add_delete(struct line *lp, int offset, int size)
region_get_data(&reg, rec->content, reg.r_size);
- if (lastrectype() != DELETE)
+ if (isreg || lastrectype() != DELETE)
undo_add_boundary(FFRAND, 1);
LIST_INSERT_HEAD(&curbp->b_undo, rec, next);
@@ -353,7 +355,7 @@ undo_add_change(struct line *lp, int offset, int size)
return (TRUE);
undo_add_boundary(FFRAND, 1);
boundary_flag = FALSE;
- undo_add_delete(lp, offset, size);
+ undo_add_delete(lp, offset, size, 0);
undo_add_insert(lp, offset, size);
boundary_flag = TRUE;
undo_add_boundary(FFRAND, 1);
@@ -397,6 +399,7 @@ undo_dump(int f, int n)
snprintf(buf, sizeof(buf),
"%d:\t %s at %d ", num,
(rec->type == DELETE) ? "DELETE":
+ (rec->type == DELREG) ? "DELREGION":
(rec->type == INSERT) ? "INSERT":
(rec->type == BOUNDARY) ? "----" :
(rec->type == MODIFIED) ? "MODIFIED": "UNKNOWN",
@@ -547,6 +550,10 @@ undo(int f, int n)
curwp->w_dotp = lp;
curwp->w_doto = offset;
break;
+ case DELREG:
+ region_put_data(ptr->content,
+ ptr->region.r_size);
+ break;
case BOUNDARY:
done = 1;
break;
diff --git a/usr.bin/mg/yank.c b/usr.bin/mg/yank.c
index c0273879b7a..fa1cb3cb078 100644
--- a/usr.bin/mg/yank.c
+++ b/usr.bin/mg/yank.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: yank.c,v 1.8 2009/06/04 02:23:37 kjell Exp $ */
+/* $OpenBSD: yank.c,v 1.9 2009/06/05 18:02:06 kjell Exp $ */
/* This file is in the public domain. */
@@ -119,20 +119,19 @@ kchunk(char *cp1, RSIZE chunk, int kflag)
if (kused == kstart)
kflag = KFORW;
- if (kflag == KFORW) {
+ if (kflag & KFORW) {
while (ksize - kused < chunk)
if (kgrow(kflag) == FALSE)
return (FALSE);
bcopy(cp1, &(kbufp[kused]), (int)chunk);
kused += chunk;
- } else if (kflag == KBACK) {
+ } else if (kflag & KBACK) {
while (kstart < chunk)
if (kgrow(kflag) == FALSE)
return (FALSE);
bcopy(cp1, &(kbufp[kstart - chunk]), (int)chunk);
kstart -= chunk;
- } else if (kflag != KNONE)
- panic("broken ldelete call");
+ }
return (TRUE);
}