nano

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

commit 02dd0b4ed5fbf9766c98397ea2b350aad633db2f
parent add945e717f6c2392622f665390b8d586bf183e4
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sat, 25 May 2024 14:50:37 +0200

options: require --colonparsing/-@ to parse colon+number after a filename

Stop doing colon parsing by default, to avoid surprises and frustration
for users that have filenames that end in a colon plus digits.

The equivalent rcfile option is, of course, 'set colonparsing'.

Using +1, or similar, before the filename disables any colon parsing
and the filename is taken as is.

Diffstat:
Msrc/definitions.h | 1+
Msrc/nano.c | 10++++++++--
Msrc/rcfile.c | 1+
Msyntax/nanorc.nanorc | 2+-
4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/definitions.h b/src/definitions.h @@ -373,6 +373,7 @@ enum { EMPTY_LINE, INDICATOR, BOOKSTYLE, + COLON_PARSING, STATEFLAGS, USE_MAGIC, MINIBAR, diff --git a/src/nano.c b/src/nano.c @@ -646,6 +646,7 @@ void usage(void) print_opt("-!", "--magic", N_("Also try magic to determine syntax")); #endif #ifndef NANO_TINY + print_opt("-@", "--colonparsing", N_("Accept 'filename:linenumber' notation")); print_opt("-%", "--stateflags", N_("Show some states on the title bar")); print_opt("-_", "--minibar", N_("Show a feedback bar at the bottom")); print_opt("-0", "--zero", N_("Hide all bars, use whole terminal")); @@ -1799,6 +1800,7 @@ int main(int argc, char **argv) {"indicator", 0, NULL, 'q'}, {"unix", 0, NULL, 'u'}, {"afterends", 0, NULL, 'y'}, + {"colonparsing", 0, NULL, '@'}, {"stateflags", 0, NULL, '%'}, {"minibar", 0, NULL, '_'}, {"zero", 0, NULL, '0'}, @@ -1850,7 +1852,7 @@ int main(int argc, char **argv) SET(MODERN_BINDINGS); while ((optchr = getopt_long(argc, argv, "ABC:DEFGHIJ:KLMNOPQ:RS$T:UVWX:Y:Z" - "abcdef:ghijklmno:pqr:s:tuvwxy!%_0/", long_options, NULL)) != -1) { + "abcdef:ghijklmno:pqr:s:tuvwxy!@%_0/", long_options, NULL)) != -1) { switch (optchr) { #ifndef NANO_TINY case 'A': @@ -2089,6 +2091,9 @@ int main(int argc, char **argv) break; #endif #ifndef NANO_TINY + case '@': + SET(COLON_PARSING); + break; case '%': SET(STATEFLAGS); break; @@ -2504,7 +2509,8 @@ int main(int argc, char **argv) * (possibly preceded by more digits and a colon). If there is or * are such trailing numbers, chop the colons plus numbers off. * The number is later used to place the cursor on that line. */ - if (strchr(filename, ':') && stat(filename, &fileinfo) < 0) { + if (ISSET(COLON_PARSING) && !givenline && strchr(filename, ':') && + !givencol && stat(filename, &fileinfo) < 0) { char *coda = filename + strlen(filename); maybe_two: while (--coda > filename + 1 && ('0' <= *coda && *coda <= '9')) diff --git a/src/rcfile.c b/src/rcfile.c @@ -98,6 +98,7 @@ static const rcoption rcopts[] = { {"backup", MAKE_BACKUP}, {"backupdir", 0}, {"bookstyle", BOOKSTYLE}, + {"colonparsing", COLON_PARSING}, {"cutfromcursor", CUT_FROM_CURSOR}, {"emptyline", EMPTY_LINE}, {"guidestripe", 0}, diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc @@ -14,7 +14,7 @@ color bold,purple "^[[:blank:]]*include[[:blank:]][^"]*([[:blank:]]|$)" color lime "^[[:blank:]]*extendsyntax[[:blank:]]+[[:alpha:]]+[[:blank:]]+(i?color|header|magic|comment|formatter|linter|tabgives)[[:blank:]]+.*" # The arguments of commands -color brightgreen "^[[:blank:]]*(set|unset)[[:blank:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|boldtext|bookstyle|breaklonglines|casesensitive|constantshow|cutfromcursor|emptyline|historylog|indicator|jumpyscrolling|linenumbers|locking|magic|minibar|mouse|multibuffer|noconvert|nohelp|nonewlines|positionlog|preserve|quickblank|rawsequences|rebinddelete|regexp|saveonexit|showcursor|smarthome|softwrap|stateflags|tabstospaces|trimblanks|unix|wordbounds|zap|zero)\>" +color brightgreen "^[[:blank:]]*(set|unset)[[:blank:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|boldtext|bookstyle|breaklonglines|casesensitive|colonparsing|constantshow|cutfromcursor|emptyline|historylog|indicator|jumpyscrolling|linenumbers|locking|magic|minibar|mouse|multibuffer|noconvert|nohelp|nonewlines|positionlog|preserve|quickblank|rawsequences|rebinddelete|regexp|saveonexit|showcursor|smarthome|softwrap|stateflags|tabstospaces|trimblanks|unix|wordbounds|zap|zero)\>" color brightgreen "^[[:blank:]]*set[[:blank:]]+(backupdir|brackets|errorcolor|functioncolor|keycolor|matchbrackets|minicolor|numbercolor|operatingdir|promptcolor|punct|quotestr|scrollercolor|selectedcolor|speller|spotlightcolor|statuscolor|stripecolor|titlecolor|whitespace|wordchars)[[:blank:]]+" color brightgreen "^[[:blank:]]*set[[:blank:]]+(fill[[:blank:]]+-?[[:digit:]]+|(guidestripe|tabsize)[[:blank:]]+[1-9][0-9]*)\>" color brightgreen "^[[:blank:]]*bind[[:blank:]]+((\^([A-Za-z]|[]/@\^_`-]|Space)|([Ss][Hh]-)?[Mm]-[A-Za-z]|[Mm]-([][!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-9]|2[0-4])|Ins|Del)[[:blank:]]+([a-z]+|".*")[[:blank:]]+(main|help|search|replace(with)?|yesno|gotoline|writeout|insert|execute|browser|whereisfile|gotodir|spell|linter|all)\>"