mcedit can be invoked with the common filename:lineno syntax.

This commit is contained in:
Roland Illig 2008-12-18 12:21:23 +00:00
parent c1eb75a515
commit bdf23438af
4 changed files with 53 additions and 11 deletions

View File

@ -1,3 +1,8 @@
2008-12-18 Roland Illig <roland.illig@gmx.de>
* doc/mcedit.1: Documented the newly added filename:lineno
invocation method.
2008-02-19 Pavel Roskin <proski@gnu.org> 2008-02-19 Pavel Roskin <proski@gnu.org>
* doc/hu/mc.1.in: Fix description for M-u and M-H. Reported by * doc/hu/mc.1.in: Fix description for M-u and M-H. Reported by

View File

@ -3,7 +3,10 @@
mcedit \- Internal file editor of GNU Midnight Commander. mcedit \- Internal file editor of GNU Midnight Commander.
.SH USAGE .SH USAGE
.B mcedit .B mcedit
[\-bcCdfhstVx?] [+number] file [\-bcCdfhstVx?] [+lineno] file
.PP
.B mcedit
[\-bcCdfhstVx?] file:lineno[:]
.SH DESCRIPTION .SH DESCRIPTION
.LP .LP
mcedit is a link to mcedit is a link to
@ -18,8 +21,8 @@ version of
\- standalone editor for X Window System. \- standalone editor for X Window System.
.SH OPTIONS .SH OPTIONS
.TP .TP
.I "+number" .I "+lineno"
Go to the line specified by number (do not put a space between the Go to the line specified by number (do not put a space between the
.I "+" .I "+"
sign and the number). sign and the number).
.TP .TP

View File

@ -1,3 +1,9 @@
2008-12-18 Roland Illig <roland.illig@gmx.de>
* 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 <roland.illig@gmx.de> 2008-12-02 Roland Illig <roland.illig@gmx.de>
* tty.c (tty_tgetstr): Fixed a crash because of an uninitialized * tty.c (tty_tgetstr): Fixed a crash because of an uninitialized

View File

@ -2055,17 +2055,45 @@ handle_args (int argc, char *argv[])
if (!STRNCOMP (base, "mce", 3) || !STRCOMP (base, "vi")) { if (!STRNCOMP (base, "mce", 3) || !STRCOMP (base, "vi")) {
edit_one_file = ""; edit_one_file = "";
if (tmp) { if (tmp) {
if (*tmp == '+' && isdigit ((unsigned char) tmp[1])) { /*
int start_line = atoi (tmp); * Check for filename:lineno, followed by an optional colon.
if (start_line > 0) { * This format is used by many programs (especially compilers)
char *file = poptGetArg (ctx); * in error messages and warnings. It is supported so that
if (file) { * users can quickly copy and paste file locations.
tmp = file; */
edit_one_file_start_line = start_line; 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")) { } else if (!STRNCOMP (base, "mcv", 3) || !STRCOMP (base, "view")) {
if (tmp) if (tmp)