External editor start_line from find dialog




Hello.

I was scratching at a long-standing itch of mine recently,
trying to get mc to call my external editor with a
line offset coming out of the find dialog, so it works
like the internal editor via :edit( what, start_line );

I was messing with execute_with_vfs_arg() in execute.c
to see if I can get it to deal with some extra arguments
passed to the command. First I goofed with passing a va_list
around, but the real problem here is getting
execlp() to do what we want in my_system().
It needs a NULL terminated list of commands so we have to
hardcode it into the program. Not much room for flexibility.

So it made me think, all I want is ONE extra argument
aside from the filename, so what if we added a const char* to
my_system() and noodle backwards through do_execute(),
execute_with_vfs_arg(), and do_edit_at_line();

It starts with this in cmd.c:do_edit_at_line():

     extra_argument = g_strdup_printf ( "+%i", start_line );
     execute_with_vfs_arg ( editor, what, extra_argument);
     g_free ( extra_argument );

And ends with this in utilunix.c:my_system():

	if (flags & EXECUTE_AS_SHELL)
	    execl (shell, shell, "-c", command, NULL);
	else {
	    if ( extra_argument )
		execlp (shell, shell, extra_argument, command, NULL);
	    else
		execlp (shell, shell, command, NULL);
	}

And it works. Neat-O!

execute_with_vfs_arg() and do_execute() just pass it on.

Is anyone else interested in this approach?
There are only tiny patches to cmd.c, execute.[ch],
util.h, and utilunix.c.


--
Peace and Cheer.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]