commit 5290a85afd67271af311e565d98fe279f73473a6
parent b5157dd9cb3fefd9261c430d7bce9ac483b1124d
Author: Benjamin Valentin <benpicco@googlemail.com>
Date: Sun, 29 Jan 2023 23:43:00 +0100
new feature: interpret also <filename>:<linenumber> when opening a file
Various tools will output filenames with line numbers in the format
<filename>:<line>:<column>. Support this format in addition to the
+<line>,<column> format when opening files.
Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
Diffstat:
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -2482,8 +2482,32 @@ int main(int argc, char **argv)
continue;
} else
#endif
- if (!open_buffer(argv[optind++], TRUE))
- continue;
+ {
+ char *filename = argv[optind++];
+ char *colon = filename + (*filename ? 1 : 0);
+
+ /* Search for a colon, to open the file on a specific line. */
+ while ((colon = strchr(colon, ':'))) {
+
+ /* If the colon is escaped, unescape it and skip it. */
+ if (*(colon - 1) == '\\') {
+ memmove(colon - 1, colon, strlen(colon) + 1);
+ continue;
+ }
+
+ /* If parsing succeeds, cut off the line suffix. */
+ if (parse_line_column(colon + 1, &givenline, &givencol)) {
+ *colon = 0;
+ break;
+ }
+
+ /* Parsing failed; skip this colon. */
+ ++colon;
+ }
+
+ if (!open_buffer(filename, TRUE))
+ continue;
+ }
/* If a position was given on the command line, go there. */
if (givenline != 0 || givencol != 0)
diff --git a/src/utils.c b/src/utils.c
@@ -137,7 +137,7 @@ bool parse_line_column(const char *str, ssize_t *line, ssize_t *column)
while (*str == ' ')
str++;
- comma = strpbrk(str, "m,. /;");
+ comma = strpbrk(str, "m,. /;:");
if (comma == NULL)
return parse_num(str, line);