diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-10-17 20:08:49 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-10-17 20:08:49 +0000 |
commit | 4a0ed5cca7e7946257e03b643c53682e20a89bf2 (patch) | |
tree | f3cd7441ec777e28431fd4a7264ea8100776bbcb /usr.bin/mg/word.c | |
parent | ca93f248b6ba7559bed213bde7989c66547ca8f8 (diff) |
make undo of word-based capitalization functions work
ok beck@
Diffstat (limited to 'usr.bin/mg/word.c')
-rw-r--r-- | usr.bin/mg/word.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/usr.bin/mg/word.c b/usr.bin/mg/word.c index 93913eaf692..baa62c5c22d 100644 --- a/usr.bin/mg/word.c +++ b/usr.bin/mg/word.c @@ -1,4 +1,4 @@ -/* $OpenBSD: word.c,v 1.10 2005/06/14 18:14:40 kjell Exp $ */ +/* $OpenBSD: word.c,v 1.11 2005/10/17 20:08:48 kjell Exp $ */ /* This file is in the public domain. */ @@ -10,6 +10,8 @@ #include "def.h" +RSIZE countfword(void); + /* * Move the cursor backward by "n" words. All of the details of motion are * performed by the "backchar" and "forwchar" routines. @@ -67,6 +69,7 @@ int upperword(int f, int n) { int c; + RSIZE size; if (curbp->b_flag & BFREADONLY) { ewprintf("Buffer is read-only"); @@ -80,6 +83,9 @@ upperword(int f, int n) if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } + size = countfword(); + undo_add_change(curwp->w_dotp, curwp->w_doto, size); + while (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); if (ISLOWER(c) != FALSE) { @@ -103,6 +109,7 @@ int lowerword(int f, int n) { int c; + RSIZE size; if (curbp->b_flag & BFREADONLY) { ewprintf("Buffer is read-only"); @@ -115,6 +122,9 @@ lowerword(int f, int n) if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } + size = countfword(); + undo_add_change(curwp->w_dotp, curwp->w_doto, size); + while (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); if (ISUPPER(c) != FALSE) { @@ -140,6 +150,7 @@ int capword(int f, int n) { int c; + RSIZE size; if (curbp->b_flag & BFREADONLY) { ewprintf("Buffer is read-only"); @@ -153,6 +164,9 @@ capword(int f, int n) if (forwchar(FFRAND, 1) == FALSE) return (TRUE); } + size = countfword(); + undo_add_change(curwp->w_dotp, curwp->w_doto, size); + if (inword() != FALSE) { c = lgetc(curwp->w_dotp, curwp->w_doto); if (ISLOWER(c) != FALSE) { @@ -178,6 +192,33 @@ capword(int f, int n) } /* + * Count characters in word, from current position + */ +RSIZE +countfword() +{ + RSIZE size; + LINE *dotp; + int doto; + + dotp = curwp->w_dotp; + doto = curwp->w_doto; + size = 0; + + while (inword() != FALSE) { + if (forwchar(FFRAND, 1) == FALSE) + /* hit the end of the buffer */ + goto out; + ++size; + } +out: + curwp->w_dotp = dotp; + curwp->w_doto = doto; + return (size); +} + + +/* * Kill forward by "n" words. */ /* ARGSUSED */ |