On Wed, Dec 18, 2019 at 05:55:25PM -0500, Thomas Dickey wrote:
>On Wed, Dec 18, 2019 at 11:00:44AM -0800, Marc Simpson wrote:
>> One nice nvi feature that I miss in vile is the `iclower' setting:
>>
>> iclower [off]
>> The iclower edit option makes all Regular Expressions
>> case-insensitive, as long as an uppercase letter does not
>> appear in the search string.
[...]
>> Out of curiosity: Would anyone else find this functionality useful
>> in vile?
>
>maybe - it doesn't seem like a large change, since the existing
>comparison is done in one place in regexp.c:
>
>#define SAME(a,b) (ignorecase ? nocase_eq(a,b) : (CharOf(a) == CharOf(b)))
I looked at this today and it is certainly doable, but ends up being a bit
more invasive than expected due to the requirement to toggle the behaviour
based on the search string, which is somewhat further up the stack than where
the match is performed.
A patch to 9.8t is attached which implements "smartmatch", which is a similar
feature that vim supports. Very lightly tested.
--bod
diff --git a/basic.c b/basic.c
index 2d31f45..7bca596 100644
--- a/basic.c
+++ b/basic.c
@@ -980,7 +980,7 @@ gotoeosent(int f, int n)
exp = b_val_rexp(curbp, VAL_SENTENCES)->reg;
/* if we're on the end of a sentence now, don't bother scanning
further, or we'll miss the immediately following sentence */
-if (!(lregexec(exp, DOT.l, DOT.o, llength(DOT.l)) &&
+if (!(lregexec(exp, DOT.l, DOT.o, llength(DOT.l), FALSE) &&
exp->startp[0] - lvalue(DOT.l) == DOT.o)) {
if (findpat(f, n, exp, FORWARD) != TRUE) {
DOT = curbp->b_line;
diff --git a/buffer.c b/buffer.c
index 06c7932..d921fbd 100644
--- a/buffer.c
+++ b/buffer.c
@@ -1187,7 +1187,7 @@ found_modeline(LINE *lp, int *first, int *last)
for (n = 0; n < TABLESIZE(mls_patterns); ++n) {
regexp *prog = mls_regcomp((int) n);
- if (lregexec(prog, lp, 0, limit)) {
+ if (lregexec(prog, lp, 0, limit, FALSE)) {
int j = mls_patterns[n].mark;
*first = (int) (prog->startp[j] - prog->startp[0]);
*last = (int) (prog->endp[j] - prog->startp[0]);
@@ -1564,11 +1564,9 @@ int
has_C_suffix(BUFFER *bp)
{
int s;
-int save = ignorecase;
-ignorecase = global_g_val(GMDFILENAME_IC);
s = nregexec(global_g_val_rexp(GVAL_CSUFFIXES)->reg,
- bp->b_fname, (char *) 0, 0, -1);
-ignorecase = save;
+ bp->b_fname, (char *) 0, 0, -1,
+ global_g_val(GMDFILENAME_IC));
return s;
}
#endif
@@ -1642,7 +1640,7 @@ make_buffer_list(char *bufn)
if ((exp = regcomp(bufn, strlen(bufn), TRUE)) != 0) {
for_each_buffer(bp) {
- if (nregexec(exp, bp->b_bname, (char *) 0, 0, -1)) {
+ if (nregexec(exp, bp->b_bname, (char *) 0, 0, -1, FALSE)) {
result[count++] = strmalloc(bp->b_bname);
}
}
diff --git a/doc/vile-hlp.html b/doc/vile-hlp.html
index 21a26fc..c40a22a 100644
--- a/doc/vile-hlp.html
+++ b/doc/vile-hlp.html
@@ -3279,6 +3279,12 @@ set-rs-crlf or set-dos-mode
If your keyboard repeats really fast and you have smoothscroll
enabled, it may take a while for vile to catch up. (U)
+smartcase
+(scs)
+
+Overrides the setting of ignorecase
+when the pattern contains uppercase characters. (B)
+
spaces-after-sentence
(sas)
diff --git a/eightbit.c b/eightbit.c
index 04c59bd..9830cc4 100644
--- a/eightbit.c
+++ b/eightbit.c
@@ -297,7 +297,7 @@ vl_narrowed(const char *wide)
if ((result = malloc(strlen(wide) + 2 + strlen(on_right))) != 0) {
strcpy(result, wide);
for (n = 0; n < len; ++n) {
- found = regexec(exp, result, result + len, n, len);
+ found = regexec(exp, result, result + len, n, len, FALSE);
if (found)
break;
}
@@ -587,7 +587,7 @@ vl_get_encoding(char **target, const char *locale)
exp = regcomp(tb_values(latin1_expr),
(size_t) tb_length0(latin1_expr), TRUE);
if (exp != 0) {
- if (nregexec(exp, mylocale, (char *) 0, 0, -1)) {
+ if (nregexec(exp, mylocale, (char *) 0, 0, -1, FALSE)) {
TRACE(("... found match in $latin1-expr\n"));
result = iso_latin1;
}
diff --git a/eval.c b/eval.c
index 58bcedd..4a5487d 100644
--- a/eval.c
+++ b/eval.c
@@ -294,7 +294,7 @@ match_charclass_regexp(int ch, REGEXVAL * exp)
char temp[2];
temp[0] = (char) ch;
-return nregexec(exp->reg, temp, temp + 1, 0, 0);
+return nregexec(exp->reg, temp, temp + 1, 0, 0, FALSE);
}
static int
@@ -1469,15 +1469,12 @@ run_func(int fnum)
break;
case UFCMATCH:
if ((exp = new_regexval(arg[0], TRUE)) != 0) {
- int save_flag = ignorecase;
- ignorecase = TRUE;
- value = nregexec(exp->reg, arg[1], (char *) 0, 0, -1);
- ignorecase = save_flag;
+ value = nregexec(exp->reg, arg[1], (char *) 0, 0, -1, TRUE);
}
break;
case UFMATCH:
if ((exp = new_regexval(arg[0], TRUE)) != 0)
- value = nregexec(exp->reg, arg[1], (char *) 0, 0, -1);
+ value = nregexec(exp->reg, arg[1], (char *) 0, 0, -1, FALSE);
break;
case UFRANDOM: