magit/with-editor

shell-commands not seeing $EDITOR override

dpassen opened this issue · 5 comments

I use with-editor alongside vterm and see my $EDITOR variable set appropriately to an invocation of emacsclient.

However, when I use either with-editor-shell-command or with-editor-async-shell-command, I do not. I've tried echo $EDITOR as well as env as the shell command and both confirm to me that $EDITOR is not being set properly.

with-editor 20220810.1159
emacs 28.2
macOS Ventura 13.0

If there's more detail I can provide, please let me know. Thank you.

I don't know why it doesn't work for you. I recommend you add a debug statement to with-editor-async-shell-command, something like (message "EDITOR: %s" (getenv "EDITOR"), inside with-editor. If that doesn't reveal anything, then also add debug statements to that macro and make sure you evaluate both the macro and the command before trying again.

Both locations revealed the same correct emacsclient value.

If I export EDITOR from my .zshenv file, it looks like that value wins out. If I export from .zshrc, emacs doesn't see it when I run (getenv "EDITOR") and it is exported properly in the with-editor shell-command functions.

with-editor-async-shell-command works by binding EDITOR and then relying on nothing else changing the value again. If your .zshrc changes it, then you will have to find a way to prevent that. The INSIDE_EMACS envvar might help with that or check if you are using a "dumb shell", which is the case here I believe.

Thanks for your help, it appears exporting editor like this:

export EDITOR="${EDITOR:-mg}"

solves my issues.

You are welcome!

(If added the faq label, so that I might one day document that somewhere.)