By default, replacing "foo" with "bar" turns "FOO" into "BAR".
With case-replace turned off, "FOO" will turn into "bar".
OK florian@ tb@
-/* $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. */
int ldelnewline(void);
int lreplace(RSIZE, char *);
char * linetostr(const struct line *);
+int setcasereplace(int, int);
/* yank.c X */
-/* $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 */
#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",},
-/* $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. */
#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.
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);
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;
}
}
- (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]);
}
}
+ done:
+ (void)ldelete(plen, KNONE);
region_put_data(repl, rlen);
lchange(WFFULL);
-.\" $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
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.