Thread (10 messages) flat view 10 messages, 5 authors, 2016-08-13

Re: using gvim as editor on Windows

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:48:24

Tait [off-list ref] writes:
It comes from line 33 of editor.c, in launch_editor().
if (strcmp(editor, ":")) {
This says "if 'editor' is not exactly the string ':'", then come into this
block.  If you set editor to ":abc", or "c:\path to\my editor.exe", they
are not "exactly the string ':'" and the codepath inside will be executed.
... I'm not familiar with the EDITOR=:
convention. What is that supposed to indicate?
Literally, it means "run ':' command as the editor".  ':' command takes
and ignores arbitrary arguments and returns success without doing
anything.  As such, the codepath pretends that it ran ':' command without
actually running it, and returns as if it ran ':' command that left the
input file given as its argument unmodified.
Can we narrow the
detection to that specific case, or does a : anywhere in EDITOR need
to be handled this way?
No, and the if statement is already narrow enough.  I think the problem is
that you have a broken shell ("sh").

    /* ... */
    if (strcspn(editor, "$ \t'") != len) {
        /* there are specials */
        strbuf_addf(&arg0, "%s \"$@\"", editor);
        args[i++] = "sh";
        args[i++] = "-c";
        args[i++] = arg0.buf;
    }
    args[i++] = editor;
    args[i++] = path;
    args[i] = NULL;
    /* ... */


If you have editor='"c:\some path\editor" -f', strcspn() notices that you have a
funny character in the path, and creates this string in arg0:

    "c:\some path\editor" -f "$@"

and feeds '-c', the above arg0, editor, and finally the name of the file,
to your shell; it is the same as running this from the command line:

    sh -c '"c:\some path\editor" -f "$@"' '"c:\some path\editor" -f' path-to-file

Now shell is supposed to expand "$@" into positional parameters, i.e. $1
(in this case, path-to-file) and run the named editor with it, IOW, your
editor program should see "-f" as its first parameter, and path-to-file as
its second parameter (and argv[] is terminated with NULL after that).

If you end up with a file whose name literally is '$@', that probably
means your "sh" did not expand it correctly.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help