nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 2326bf695e0c7bea9eb3bea33e49cb1f6319dccf
parent a9dd73fb16529259bd247de77667e3920b8c62d1
Author: Brand Huntsman <alpha@qzx.com>
Date:   Sat, 17 Aug 2019 15:30:43 -0600

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>

Diffstat:
Msrc/nano.c | 27+++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/nano.c b/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 (optind < argc - 1 && argv[optind][0] == '+') { - if (argv[optind][1] == '/' || argv[optind][1] == '?') { - if (argv[optind][2]) { - searchstring = mallocstrcpy(NULL, &argv[optind][2]); - if (argv[optind][1] == '?') + int n = 1; + + while (isalpha(argv[optind][n])) { + 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); - } else + } else if (n == 1) statusline(ALERT, _("Empty search string")); optind++; } 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")); }