search: accept toggles for case and regex when searching at startup
Allow the user to specify that the search string should be interpreted case-sensitively and/or as a regular expression by preceding the search indicator (/ or ?) with c and/or r. Or to switch these things off by using C and/or R. Signed-off-by: Brand Huntsman <alpha@qzx.com> Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>master
parent
a9dd73fb16
commit
2326bf695e
27
src/nano.c
27
src/nano.c
|
@ -2585,16 +2585,31 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* If there's a +LINE[,COLUMN] argument here, eat it up. */
|
/* If there's a +LINE[,COLUMN] argument here, eat it up. */
|
||||||
if (optind < argc - 1 && argv[optind][0] == '+') {
|
if (optind < argc - 1 && argv[optind][0] == '+') {
|
||||||
if (argv[optind][1] == '/' || argv[optind][1] == '?') {
|
int n = 1;
|
||||||
if (argv[optind][2]) {
|
|
||||||
searchstring = mallocstrcpy(NULL, &argv[optind][2]);
|
while (isalpha(argv[optind][n])) {
|
||||||
if (argv[optind][1] == '?')
|
switch (argv[optind][n++]) {
|
||||||
|
case 'c': SET(CASE_SENSITIVE); break;
|
||||||
|
case 'C': UNSET(CASE_SENSITIVE); break;
|
||||||
|
case 'r': SET(USE_REGEXP); break;
|
||||||
|
case 'R': UNSET(USE_REGEXP); break;
|
||||||
|
default:
|
||||||
|
statusline(ALERT, _("Invalid search modifier '%c'"),
|
||||||
|
argv[optind][n - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv[optind][n] == '/' || argv[optind][n] == '?') {
|
||||||
|
if (argv[optind][n + 1]) {
|
||||||
|
searchstring = mallocstrcpy(NULL, &argv[optind][n + 1]);
|
||||||
|
if (argv[optind][n] == '?')
|
||||||
SET(BACKWARDS_SEARCH);
|
SET(BACKWARDS_SEARCH);
|
||||||
} else
|
} else if (n == 1)
|
||||||
statusline(ALERT, _("Empty search string"));
|
statusline(ALERT, _("Empty search string"));
|
||||||
optind++;
|
optind++;
|
||||||
} else
|
} else
|
||||||
if (!parse_line_column(&argv[optind++][1], &givenline, &givencol))
|
|
||||||
|
if (!parse_line_column(&argv[optind++][n], &givenline, &givencol))
|
||||||
statusline(ALERT, _("Invalid line or column number"));
|
statusline(ALERT, _("Invalid line or column number"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue