git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: using gvim as editor on Windows

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 9, 2010, 20:07 UTC
Message-ID
<7vzl2hw972.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20100309024523.GU2480@ece.pdx.edu>
Tait <git.git@t41t.com> 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.

Previous: TaitNext: Tait
Message 8 of 10 in “using gvim as editor on Windows”
  1. TaitMar 6, 2010
  2. Jacob HelwigMar 6, 2010
  3. TaitMar 6, 2010
  4. Markus HeidelbergMar 6, 2010
  5. TaitMar 8, 2010
  6. Markus HeidelbergMar 8, 2010
  7. TaitMar 9, 2010
  8. Junio C HamanoMar 9, 2010
  9. TaitMar 11, 2010
  10. Johannes SixtMar 11, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.