On Mon, Nov 28 2022, Jeff King wrote: > On Sat, Nov 26, 2022 at 12:52:50AM +0100, Ævar Arnfjörð Bjarmason wrote: > >> > Second, there is a difficulty passing arbitrary arguments properly to >> > Emacs Lisp properly. >> > For example, your version will cause error with >> > git jump grep "hello world" >> > My early patch was doing something similar. But the second problem was >> > hard to deal with, >> > so I switched to using a temporary file. >> >> To the extent that that's painful couldn't we write the grep expression >> / arguments to the tempfile, then feed the tempfile to the ad-hoc elisp >> code? >> >> It would then read it, get the argument to grep for, and we'd call (grep >> that-argument). > > You'd still need to quote the arguments, since you'll be reading > potentially multiple arguments out of the bytestream of the file[1]. > > If you're not going to quote, the simplest thing is to generate the > line-oriented output and read that. > > If you are going to quote, then you don't need the tempfile at all. You > can shove the command into the eval, as if git-jump were run from emacs > directly (but you want to use the --stdout mode introduced in this > series, and not the git commands directly, because of course they're > non-trivial). > > I showed how to do the quoting earlier in the thread. But it is ugly, > and this tempfile hack should work (modulo the gross wait loop > afterwards). Thanks, I'd missed https://lore.kernel.org/git/Y30a0ulfxyE7dnYi@xxxxxxxxxxxxxxxxxxxxxxx/ I think the case where the temporary directory itself has spaces in it isn't worth worrying about. So, all we'd need to worry about is getting the arguments to be grep'd to emacs. That should be simpler & bug-free with some equivalent of echo "args" >$tmpfile then in Emacs, given some "<tmpfile>" variable: (with-temp-buffer (insert-file-contents <tempfile>) (buffer-string))) We'd then invoke M-x grep with that. I think getting rid of the tempfile isn't worth it, or worth worrying about, what I was pointing out is that the implementation as it stands works notably differently than if you invoked M-x grep itself. I.e. it doesn't do highlighting, and (I didn't note this before) if it takes a while we'll "hang", if we had emacs itself invoke the "git grep" we'd stream out grep results as they came in.