summaryrefslogtreecommitdiff
path: root/usr.bin/mg/random.c
diff options
context:
space:
mode:
authorMark Lumsden <lum@cvs.openbsd.org>2014-03-26 22:02:07 +0000
committerMark Lumsden <lum@cvs.openbsd.org>2014-03-26 22:02:07 +0000
commitddbf972eb50180b75a41612318494aa6ef782cb8 (patch)
treeaaa31048333cc9ba056de167a9f8febd7a991b58 /usr.bin/mg/random.c
parent2d4f4eec7a60fc620394e034765f1b7460680a1d (diff)
Previously, C-t (transpose two chars) did not behave the same as
Emacs. This diff makes mg behave more so. Though new-line characters are treated as any other. Difference from emacs observed and reported by deraadt@. First diff tested and ridiculed by deraadt@. Second diff not tested and not ridiculed by deraadt@ but at least email responded to.
Diffstat (limited to 'usr.bin/mg/random.c')
-rw-r--r--usr.bin/mg/random.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/usr.bin/mg/random.c b/usr.bin/mg/random.c
index 10f0c6b23f6..ecf5d71805f 100644
--- a/usr.bin/mg/random.c
+++ b/usr.bin/mg/random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: random.c,v 1.32 2013/03/25 11:41:44 florian Exp $ */
+/* $OpenBSD: random.c,v 1.33 2014/03/26 22:02:06 lum Exp $ */
/* This file is in the public domain. */
@@ -103,11 +103,9 @@ getcolpos(struct mgwin *wp)
}
/*
- * Twiddle the two characters on either side of dot. If dot is at the end
- * of the line twiddle the two characters before it. Return with an error
- * if dot is at the beginning of line; it seems to be a bit pointless to
- * make this work. This fixes up a very common typo with a single stroke.
- * Normally bound to "C-T". This always works within a line, so "WFEDIT"
+ * Twiddle the two characters in front of and under dot, then move forward
+ * one character. Treat new-line characters the same as any other.
+ * Normally bound to "C-t". This always works within a line, so "WFEDIT"
* is good enough.
*/
/* ARGSUSED */
@@ -116,26 +114,40 @@ twiddle(int f, int n)
{
struct line *dotp;
int doto, cr;
- int fudge = FALSE;
dotp = curwp->w_dotp;
doto = curwp->w_doto;
- if (doto == llength(dotp)) {
- if (--doto <= 0)
- return (FALSE);
- (void)backchar(FFRAND, 1);
- fudge = TRUE;
- } else {
- if (doto == 0)
- return (FALSE);
+
+ /* Don't twiddle if the dot is on the first char of buffer */
+ if (doto == 0 && lback(dotp) == curbp->b_headp) {
+ dobeep();
+ ewprintf("Beginning of buffer");
+ return(FALSE);
+ }
+ /* Don't twiddle if the dot is on the last char of buffer */
+ if (doto == llength(dotp) && lforw(dotp) == curbp->b_headp) {
+ dobeep();
+ return(FALSE);
}
undo_boundary_enable(FFRAND, 0);
- cr = lgetc(dotp, doto - 1);
- (void)backdel(FFRAND, 1);
- (void)forwchar(FFRAND, 1);
- linsert(1, cr);
- if (fudge != TRUE)
- (void)backchar(FFRAND, 1);
+ if (doto == 0 && doto == llength(dotp)) { /* only '\n' on this line */
+ (void)forwline(FFRAND, 1);
+ curwp->w_doto = 0;
+ } else {
+ if (doto == 0) { /* 1st twiddle is on 1st character of a line */
+ cr = lgetc(dotp, doto);
+ (void)backdel(FFRAND, 1);
+ (void)forwchar(FFRAND, 1);
+ lnewline();
+ linsert(1, cr);
+ (void)backdel(FFRAND, 1);
+ } else { /* twiddle is elsewhere in line */
+ cr = lgetc(dotp, doto - 1);
+ (void)backdel(FFRAND, 1);
+ (void)forwchar(FFRAND, 1);
+ linsert(1, cr);
+ }
+ }
undo_boundary_enable(FFRAND, 1);
lchange(WFEDIT);
return (TRUE);