diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2018-08-29 07:50:17 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2018-08-29 07:50:17 +0000 |
commit | 12500a136200ea749fcd410f3deb512a51b3941e (patch) | |
tree | 73914da66f77903e2ccecf77ffcc736835cddfa4 /usr.bin | |
parent | 4d2995288b624131fc1cf8e9fd8f25003c4fc371 (diff) |
Add set-case-replaced to toggle case-preserving replace on or off.
By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".
OK florian@ tb@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/def.h | 3 | ||||
-rw-r--r-- | usr.bin/mg/funmap.c | 3 | ||||
-rw-r--r-- | usr.bin/mg/line.c | 30 | ||||
-rw-r--r-- | usr.bin/mg/mg.1 | 7 |
4 files changed, 33 insertions, 10 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index f7111ca1a06..86c606f7ff4 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.155 2016/04/14 17:05:32 lum Exp $ */ +/* $OpenBSD: def.h,v 1.156 2018/08/29 07:50:16 reyk Exp $ */ /* This file is in the public domain. */ @@ -391,6 +391,7 @@ int ldelete(RSIZE, int); int ldelnewline(void); int lreplace(RSIZE, char *); char * linetostr(const struct line *); +int setcasereplace(int, int); /* yank.c X */ diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c index bd555d6fc40..def40477262 100644 --- a/usr.bin/mg/funmap.c +++ b/usr.bin/mg/funmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: funmap.c,v 1.53 2016/04/14 17:05:32 lum Exp $ */ +/* $OpenBSD: funmap.c,v 1.54 2018/08/29 07:50:16 reyk Exp $ */ /* This file is in the public domain */ @@ -184,6 +184,7 @@ static struct funmap functnames[] = { #ifdef REGEX {setcasefold, "set-case-fold-search",}, #endif /* REGEX */ + {setcasereplace, "set-case-replace",}, {set_default_mode, "set-default-mode",}, {setfillcol, "set-fill-column",}, {setmark, "set-mark-command",}, diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c index 7c292dbe12d..4e4f5248738 100644 --- a/usr.bin/mg/line.c +++ b/usr.bin/mg/line.c @@ -1,4 +1,4 @@ -/* $OpenBSD: line.c,v 1.60 2018/07/12 12:38:56 florian Exp $ */ +/* $OpenBSD: line.c,v 1.61 2018/08/29 07:50:16 reyk Exp $ */ /* This file is in the public domain. */ @@ -27,6 +27,22 @@ #include "def.h" +int casereplace = TRUE; + +/* + * Preserve the case of the replaced string. + */ +int +setcasereplace(int f, int n) +{ + if (f & FFARG) + casereplace = n > 0; + else + casereplace = !casereplace; + ewprintf("Case-replace is %sabled", casereplace ? "en" : "dis"); + return (TRUE); +} + /* * Allocate a new line of size `used'. lrealloc() can be called if the line * ever needs to grow beyond that. @@ -516,7 +532,7 @@ lreplace(RSIZE plen, char *st) RSIZE n; int s, doto, is_query_capitalised = 0, is_query_allcaps = 0; int is_replace_alllower = 0; - char *repl; + char *repl = NULL; if ((s = checkdirty(curbp)) != TRUE) return (s); @@ -531,11 +547,14 @@ lreplace(RSIZE plen, char *st) ewprintf("out of memory"); return (FALSE); } + rlen = strlen(repl); undo_boundary_enable(FFRAND, 0); - (void)backchar(FFARG | FFRAND, (int)plen); + if (casereplace != TRUE) + goto done; + lp = curwp->w_dotp; doto = curwp->w_doto; n = plen; @@ -556,9 +575,6 @@ lreplace(RSIZE plen, char *st) } } - (void)ldelete(plen, KNONE); - - rlen = strlen(repl); for (n = 0, is_replace_alllower = 1; n < rlen && is_replace_alllower; n++) is_replace_alllower = !isupper((unsigned char)repl[n]); @@ -572,6 +588,8 @@ lreplace(RSIZE plen, char *st) } } + done: + (void)ldelete(plen, KNONE); region_put_data(repl, rlen); lchange(WFFULL); diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1 index 3979fac4e42..7241e090c0b 100644 --- a/usr.bin/mg/mg.1 +++ b/usr.bin/mg/mg.1 @@ -1,7 +1,7 @@ -.\" $OpenBSD: mg.1,v 1.106 2017/12/11 07:27:07 jmc Exp $ +.\" $OpenBSD: mg.1,v 1.107 2018/08/29 07:50:16 reyk Exp $ .\" This file is in the public domain. .\" -.Dd $Mdocdate: December 11 2017 $ +.Dd $Mdocdate: August 29 2018 $ .Dt MG 1 .Os .Sh NAME @@ -846,6 +846,9 @@ Currently only affects fill-paragraph. Set case-fold searching, causing case not to matter in regular expression searches. This is the default. +.It set-case-replace +Preserve the case of the replaced string. +This is the default. .It set-default-mode Append the supplied mode to the list of default modes used by subsequent buffer creation. |