2

I want to execute a bash command with my user environment, and I do not want to open a terminal windows on my Windows desktop. I tried:

c:\cygwin64\bin\run.exe zsh -lic emacs

And it opens a emacs window with my user environment. But if I try:

c:\cygwin64\bin\run.exe zsh -lic emacs --name fancy-name

It seems the --name option is ineffective.

I tried to add quote, but did not work.

What I want to achieve is to use --eval option in Emacs to initialize my Emacs according to my command context.

1

I can get Emacs to interpret its flags on my setup if I wrap things in two sets of quotes, like this:

C:\cygwin64\bin\run.exe bash -lic '"emacs -q"'

(All of this is in a cmd window, by the way. And I'm assuming that zsh and bash are not different in any way relevant to the question.)

I think what's happening here is that run is stripping one level of quotes before it hands things off to bash. However, I don't think you need the extra level of indirection. This also works for me:

C:\cygwin64\bin\bash.exe -lic "emacs -q"


EDIT: But of course you're using the --eval switch with Emacs, which means you'll want to use quotes with whatever you want evaluated. The hitch here is that the argument to eval also needs to be quoted, e.g.

C:\cygwin64\bin\run.exe bash -lic '"emacs --eval \"(foo)\""'

To quote strings inside that, you'll need to replace the outer single quotes with doubles and double- and triple-escape as necessary:

C:\cygwin64\bin\run.exe bash -lic "\"emacs --eval \\\"(message \\\\\\\"Foo\\\\\\\")\\\"\""

Of course that gets nuts pretty quickly. String literal syntax makes things a little saner by using single quotes while still allowing you to escape single quotes inside the string:

C:\cygwin64\bin\run.exe bash -lic "\"emacs --eval $'(message \\\"Foo\\\")'\""

Finally, there's the option of just encapsulating the code you want to evaluate as a function inside Emacs so you can call it without string or symbol literals. Alternatively, you could put it in a file and have Emacs load it with the -l switch.

  • Thanks for the single quote trick. But still, I cannot get this one work: d:\cygwin64\bin\run.exe zsh -lic '"emacs --eval (switch-to-buffer (get-buffer-create \"sss\"))"'. Any suggestions? – David S. May 13 '16 at 1:04
  • The immediate problem is that you need to put the entire argument to eval inside quotes, but after that I can't figure out a way to quote strings inside that. See my edit for another idea. – Aaron Harris May 13 '16 at 16:10
  • And I figured out how to get string literals to work. I'm still not sure I'd recommend using them over encapsulating the code as a function or file, but you can if you need to. – Aaron Harris May 13 '16 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.