summaryrefslogtreecommitdiff
path: root/usr.bin
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
commitda081b53116f582f80163c35671902f0a3916ffa (patch)
treea31223fc37cd8c997b55416fe5ee589c195898c7 /usr.bin
parent98fa97bb051198f5534ce2012a7c723f9c9d3ed1 (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')
-rw-r--r--usr.bin/mg/util.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/usr.bin/mg/util.c b/usr.bin/mg/util.c
index 1ac19cdba03..896d62324f1 100644
--- a/usr.bin/mg/util.c
+++ b/usr.bin/mg/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.32 2013/03/25 11:41:44 florian Exp $ */
+/* $OpenBSD: util.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);