nano

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

commit 54c8cb8c811b9fd202266f43798d77d2120d015e
parent 803a16cbcd2d1a770dc5d8f5aa7051f5dcf2b398
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Fri, 10 May 2024 10:44:28 +0200

files: when a filename with a colon and digits exists, open that file

When the user specifies, on the command line, a filename that ends with
a colon plus digits, and that filename exists in the file system, then
open that file, instead of interpreting the digits as a line number.

Also, if the filename stripped of the colon plus digits does not exist,
then do not interpret the digits as a line number either but treat them
as part of the file name.

Before this change, the user would have to escape the colon whenever
they wanted to open a file whose name ended with a colon plus digits.
Now the user needs to escape the colon only when 'foo' exists and they
want to create, say, 'foo:24'.

Problem-was-reported-by: Ralph Corderoy <ralph@inputplus.co.uk>
  https://lists.gnu.org/archive/html/nano-devel/2024-05/msg00001.html
Mitigation-was-suggested-by: Mike Scalora <mike@scalora.org>
  https://lists.gnu.org/archive/html/nano-devel/2024-05/msg00008.html

Diffstat:
Msrc/nano.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -2495,19 +2495,24 @@ int main(int argc, char **argv) { char *filename = argv[optind++]; char *colon = filename + (*filename ? 1 : 0); + struct stat fileinfo; /* Search the filename for a colon. If the colon is preceded by * a backslash, elide the backslash and skip the colon. If there * is a valid number after the colon, chop colon and number off. * The number is later used to place the cursor on that line. */ + if (strchr(filename, ':') && stat(filename, &fileinfo) < 0) { while ((colon = strchr(colon, ':'))) { if (*(colon - 1) == '\\') memmove(colon - 1, colon, strlen(colon) + 1); - else if (parse_line_column(colon + 1, &givenline, &givencol)) + else if (parse_line_column(colon + 1, &givenline, &givencol)) { *colon = '\0'; - else + if (stat(filename, &fileinfo) < 0) + *colon++ = ':'; + } else ++colon; } + } if (!open_buffer(filename, TRUE)) continue;