diff --git a/ChangeLog b/ChangeLog index 57a14e367..291791f69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-12-18 Roland Illig + + * doc/mcedit.1: Documented the newly added filename:lineno + invocation method. + 2008-02-19 Pavel Roskin * doc/hu/mc.1.in: Fix description for M-u and M-H. Reported by diff --git a/doc/mcedit.1.in b/doc/mcedit.1.in index c080923fe..691d86ec5 100644 --- a/doc/mcedit.1.in +++ b/doc/mcedit.1.in @@ -3,7 +3,10 @@ mcedit \- Internal file editor of GNU Midnight Commander. .SH USAGE .B mcedit -[\-bcCdfhstVx?] [+number] file +[\-bcCdfhstVx?] [+lineno] file +.PP +.B mcedit +[\-bcCdfhstVx?] file:lineno[:] .SH DESCRIPTION .LP mcedit is a link to @@ -18,8 +21,8 @@ version of \- standalone editor for X Window System. .SH OPTIONS .TP -.I "+number" -Go to the line specified by number (do not put a space between the +.I "+lineno" +Go to the line specified by number (do not put a space between the .I "+" sign and the number). .TP diff --git a/src/ChangeLog b/src/ChangeLog index 9b4a89be6..a5aefea74 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2008-12-18 Roland Illig + + * main.c (main): It is now possible to invoke mcedit with + filename:lineno[:], so that copy and paste of file locations + can be done quickly. + 2008-12-02 Roland Illig * tty.c (tty_tgetstr): Fixed a crash because of an uninitialized diff --git a/src/main.c b/src/main.c index 37312c004..a59607e58 100644 --- a/src/main.c +++ b/src/main.c @@ -2055,17 +2055,45 @@ handle_args (int argc, char *argv[]) if (!STRNCOMP (base, "mce", 3) || !STRCOMP (base, "vi")) { edit_one_file = ""; if (tmp) { - if (*tmp == '+' && isdigit ((unsigned char) tmp[1])) { - int start_line = atoi (tmp); - if (start_line > 0) { - char *file = poptGetArg (ctx); - if (file) { - tmp = file; - edit_one_file_start_line = start_line; + /* + * Check for filename:lineno, followed by an optional colon. + * This format is used by many programs (especially compilers) + * in error messages and warnings. It is supported so that + * users can quickly copy and paste file locations. + */ + char *end = tmp + strlen (tmp), *p = end; + if (p > tmp && p[-1] == ':') + p--; + while (p > tmp && isdigit ((unsigned char) p[-1])) + p--; + if (tmp < p && p < end && p[-1] == ':') { + struct stat st; + gchar *fname = g_strndup (tmp, p - 1 - tmp); + /* + * Check that the file before the colon actually exists. + * If it doesn't exist, revert to the old behavior. + */ + if (mc_stat (tmp, &st) == -1 && mc_stat (fname, &st) != -1) { + edit_one_file = fname; + edit_one_file_start_line = atoi (p); + } else { + g_free (fname); + goto try_plus_filename; + } + } else { + try_plus_filename: + if (*tmp == '+' && isdigit ((unsigned char) tmp[1])) { + int start_line = atoi (tmp); + if (start_line > 0) { + char *file = poptGetArg (ctx); + if (file) { + tmp = file; + edit_one_file_start_line = start_line; + } } } + edit_one_file = g_strdup (tmp); } - edit_one_file = g_strdup (tmp); } } else if (!STRNCOMP (base, "mcv", 3) || !STRCOMP (base, "view")) { if (tmp)