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

Re: [PATCH v4 2/2] git-jump: invoke emacs/emacsclient

From
Jeff King <peff@peff.net>
Date
Nov 24, 2022, 16:29 UTC
Message-ID
<Y3+b80Vb2/6lKQ40@coredump.intra.peff.net>
In-Reply-To
<CAF5D8-u14grTa9cUo=ge8TVRKNYtVHWhFHDW8yYD9gD8=f0Byg@mail.gmail.com>
On Thu, Nov 24, 2022 at 09:32:45PM +0900, Yoichi Nakayama wrote:
Show 13 quoted lines
> > Good point. The vim version is easier to fix (we just need to
> > double-quote \$1 inside the eval), but the fact that nobody has
> > complained is an indication that it does not really matter.
> 
> I've confirmed the vim version is fixed by
>     eval "$editor -q \"\$1\""
> 
> With your hint, I found the emacs version can be fixed
> by single-quoting the variable (I found a mistake in the
> emacs version. Since there is only one argument, I
> should use $1 instead of $@. I'll fix it.), and the vim
> version can be also in the similar form with single quote:
>     eval "$editor -q '$1'"

This isn't quite a full solution, though. The "$1" is expanded by the outer double-quoted string, which is then fed to eval. The inner single-quotes make most characters literally except for single-quotes themselves. So if $1 has single-quotes, the eval will barf due to bad syntax.

> The original vim version used the notation \$1 instead of $1.
> I'm worried that the emacs version might need the backslash.
> What does the backslash mean? Is it necessary?

As you figured out in the other email, it inhibits the outer layer of expansion, and lets the eval expand it. This is the easiest way to pass things through levels of shell evals (since otherwise you have to actually quote, which is a real pain).

None of this is sufficient for your emacs example, though. There you have three levels of quoting:

  - getting the argument intact into the eval; this can use the "\$"
    trick
  - the argument then appears inside a double-quoted string which will
    be evaluated by emacs. You'd want to protect it against
    double-quotes and presumably backslashes.
  - emacs will then execute the final command, presumably you a shell.
    So you'd want to protect against expansion in that shell. The
    easiest way to do that is usually to wrap each argument in
    single-quotes, and quoting against interior single quotes (by ending
    single-quote, adding a single backslashed single-quote, and then
    re-opening the single-quote). It's horribly ugly, but is (AFAIK) the
    shortest way to quote shell arguments, and what we usually do in
    Git.

Those are the three tricks I sent in the earlier email (though looking at it again, I think the single-quote bits need to come first, so their backslashes are then quoted to protect against emacs evaluation).

It's all quite confusing, which is why I am OK with just skipping it for now. ;) The nice thing, though, is that doing the quoting right means it's safe to get rid of the "cat", which solves your race problems in a more direct and robust way.

-Peff
Previous: Jeff KingNext: Yoichi Nakayama
Message 36 of 68 in “git-jump: support Emacs”
  1. 0/2 git-jump: support EmacsYoichi NAKAYAMA via GitGitGadget, Nov 19, 2022
  2. 1/2 git-jump: add an optional argument 'stdout'Yoichi Nakayama via GitGitGadget, Nov 19, 2022
  3. 2/2 git-jump: invoke emacsclientYoichi Nakayama via GitGitGadget, Nov 19, 2022
  4. Eric SunshineNov 19, 2022
  5. Yoichi NakayamaNov 19, 2022
  6. Eric SunshineNov 19, 2022
  7. Yoichi NakayamaNov 21, 2022
  8. 0/2 git-jump: support EmacsYoichi NAKAYAMA via GitGitGadget, Nov 20, 2022
  9. 1/2 git-jump: add an optional argument 'stdout'Yoichi Nakayama via GitGitGadget, Nov 20, 2022
  10. Junio C HamanoNov 21, 2022
  11. Yoichi NakayamaNov 21, 2022
  12. Jeff KingNov 21, 2022
  13. 2/2 git-jump: invoke emacsclientYoichi Nakayama via GitGitGadget, Nov 20, 2022
  14. 0/2 git-jump: support EmacsYoichi NAKAYAMA via GitGitGadget, Nov 21, 2022
  15. 1/2 git-jump: add an optional argument '--stdout'Yoichi Nakayama via GitGitGadget, Nov 21, 2022
  16. Jeff KingNov 21, 2022
  17. Junio C HamanoNov 21, 2022
  18. Yoichi NakayamaNov 22, 2022
  19. Jeff KingNov 22, 2022
  20. Yoichi NakayamaNov 22, 2022
  21. 2/2 git-jump: invoke emacs/emacsclientYoichi Nakayama via GitGitGadget, Nov 21, 2022
  22. Jeff KingNov 21, 2022
  23. Yoichi NakayamaNov 22, 2022
  24. 0/2 git-jump: support EmacsYoichi NAKAYAMA via GitGitGadget, Nov 22, 2022
  25. 1/2 git-jump: add an optional argument '--stdout'Yoichi Nakayama via GitGitGadget, Nov 22, 2022
  26. Jeff KingNov 22, 2022
  27. 2/2 git-jump: invoke emacs/emacsclientYoichi Nakayama via GitGitGadget, Nov 22, 2022
  28. Phillip WoodNov 22, 2022
  29. Yoichi NakayamaNov 23, 2022
  30. Jeff KingNov 22, 2022
  31. Yoichi NakayamaNov 23, 2022
  32. Jeff KingNov 24, 2022
  33. Yoichi NakayamaNov 24, 2022
  34. Yoichi NakayamaNov 24, 2022
  35. Jeff KingNov 24, 2022
  36. Jeff KingNov 24, 2022
  37. Yoichi NakayamaNov 25, 2022
  38. 0/3 git-jump: support EmacsYoichi NAKAYAMA via GitGitGadget, Nov 23, 2022
  39. 1/3 git-jump: add an optional argument '--stdout'Yoichi Nakayama via GitGitGadget, Nov 23, 2022
  40. 2/3 git-jump: move valid-mode check earlierJeff King via GitGitGadget, Nov 23, 2022
  41. 3/3 git-jump: invoke emacs/emacsclientYoichi Nakayama via GitGitGadget, Nov 23, 2022
  42. Phillip WoodNov 23, 2022
  43. Yoichi NakayamaNov 23, 2022
  44. Jeff KingNov 24, 2022
  45. 0/3 git-jump: support EmacsYoichi NAKAYAMA via GitGitGadget, Nov 24, 2022
  46. 1/3 git-jump: add an optional argument '--stdout'Yoichi Nakayama via GitGitGadget, Nov 24, 2022
  47. 2/3 git-jump: move valid-mode check earlierJeff King via GitGitGadget, Nov 24, 2022
  48. 3/3 git-jump: invoke emacs/emacsclientYoichi Nakayama via GitGitGadget, Nov 24, 2022
  49. 0/3 git-jump: support EmacsYoichi NAKAYAMA via GitGitGadget, Nov 25, 2022
  50. 1/3 git-jump: add an optional argument '--stdout'Yoichi Nakayama via GitGitGadget, Nov 25, 2022
  51. Ævar Arnfjörð BjarmasonNov 25, 2022
  52. Yoichi NakayamaNov 27, 2022
  53. 2/3 git-jump: move valid-mode check earlierJeff King via GitGitGadget, Nov 25, 2022
  54. 3/3 git-jump: invoke emacs/emacsclientYoichi Nakayama via GitGitGadget, Nov 25, 2022
  55. Ævar Arnfjörð BjarmasonNov 25, 2022
  56. Yoichi NakayamaNov 25, 2022
  57. Ævar Arnfjörð BjarmasonNov 25, 2022
  58. Jeff KingNov 28, 2022
  59. Ævar Arnfjörð BjarmasonNov 28, 2022
  60. Yoichi NakayamaNov 28, 2022
  61. Yoichi NakayamaNov 27, 2022
  62. 0/3 git-jump: support EmacsYoichi NAKAYAMA via GitGitGadget, Nov 27, 2022
  63. 1/3 git-jump: add an optional argument '--stdout'Yoichi Nakayama via GitGitGadget, Nov 27, 2022
  64. 2/3 git-jump: move valid-mode check earlierJeff King via GitGitGadget, Nov 27, 2022
  65. 3/3 git-jump: invoke emacs/emacsclientYoichi Nakayama via GitGitGadget, Nov 27, 2022
  66. Phillip WoodNov 28, 2022
  67. Junio C HamanoNov 28, 2022
  68. Yoichi NakayamaNov 29, 2022

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.