reddit / emacs
Setting emacs as $EDITOR in zshrc
Schievel1 · 2022-09-21 13:09
Hi,
I have a minor thing that is driving me crazy.
I want to set `emacsclient -t -a emacs -nw` as $EDITOR, so programs like git commit use emacs.
So, what I am trying is setting `export EDITOR='emacsclient -t -a emacs -nw'` in my `~/.zshrc`.
When I run `$EDITOR` it says `zsh: command not found: emacsclient -t -a emacs -nw`.
I also tried `export EDITOR="emacsclient -t -a emacs -nw"` and `export EDITOR=emacsclient -t -a emacs -nw`.
The first one has the same result, the second one treads `-t` like a command
/ It's a bit weird, because this is how it's recommended in the wiki: https://www.emacswiki.org/emacs/EmacsClient
Maybe a problem with zsh?
// yup looks like it, because this works in bash.
takeonrules · 2022-09-21 13:26
I use `zshrc` and solved this by creating a shell script that I declare as `$EDITOR`:
https://codeberg.org/takeonrules/dotzshrc/src/2aa186214030faa03bfdc7a1272ec54339f7d1af/bin/editor
Then I have [the export here](https://codeberg.org/takeonrules/dotzshrc/src/2aa186214030faa03bfdc7a1272ec54339f7d1af/configs/aliases.zsh#L12-13).
fmou67 · 2022-09-21 13:39
The links are not working... Thanks for fixing them!
jvillasante · 2022-09-21 13:40
Use this in your .zshrc/.bashrc file:
```
export ALTERNATE_EDITOR=""
export VISUAL="emacsclient -c -n -a ''" # $VISUAL opens in GUI with non-daemon as alternate
export EDITOR="emacsclient -t -a ''" # $EDITOR should open in terminal
```
Schievel1 · 2022-09-21 14:13
Yes thanks, this is pretty much what I wrote and also linked to, and it isn't working
Schievel1 · 2022-09-21 14:15
[https://codeberg.org/takeonrules/dotzshrc/src/branch/main/bin/editor](https://codeberg.org/takeonrules/dotzshrc/src/branch/main/bin/editor)
https://codeberg.org/takeonrules/dotzshrc/src/branch/main/configs/aliases.zsh#L12-13
takeonrules · 2022-09-21 14:17
Gah…so much for Emacs's git-link working with Codeberg.
Schievel1 · 2022-09-21 14:32
it just went down anyway. I hope for you it wasn't because of your emacs :D
mshkrebtan · 2022-09-21 14:41
Er… is emacsclient actually discoverable in your shell? Do you set the PATH variable correctly?
takeonrules · 2022-09-21 14:44
How about giving Github a try instead: https://github.com/jeremyf/dotzshrc/blob/2aa186214030faa03bfdc7a1272ec54339f7d1af/bin/editor
Schievel1 · 2022-09-21 14:48
ah, I see where this commit hash was coming from :D
masukomi · 2022-09-21 14:58
your codeberg link is a 404 :( Maybe you're the only one authorized to see it?
Schievel1 · 2022-09-21 15:02
Thanks, I did a little simpler approach:
I made this script `editor` in `~/.local/bin`:
```
#!/usr/bin/env bash
emacsclient -t -a emacs -nw
```
Then put `export EDITOR='editor'` into `~/.zshrc`
/ Is your script missing the shebang? I newer saw `#/bin/sh` before
anoduck · 2022-09-21 15:07
This is odd, because I know I have done it.
Try using single quotes, and the full path for emacsclient.
This will avoid command expansion from rewriting the command.
Alan_Shutko · 2022-09-21 15:29
It is a zsh thing. If a variable contains spaces it won’t be split after expansion, on purpose.
krisbrowne42 · 2022-09-21 16:36
The oh-my-zsh emacs plugin does a lot of this for you pretty cleanly, worth looking at.
mgeisler · 2022-09-21 19:09
Precisely, OP would need to run
```
$ ${=EDITOR}
```
instead. That enables _word splitting_ on the variable. See the [zsh FAQ](https://zsh.sourceforge.io/FAQ/zshfaq03.html) for more information.
Schievel1 · 2022-09-21 21:41
True that. But that doesn't help me with scripts and programs that use the variable $EDITOR
mgeisler · 2022-09-24 09:47
It's only Zsh itself that doesn't do word splitting unless you ask for it as shown.
Programs that use `$EDITOR` have always had to deal with word splitting themselves, or they could pass the string to a known shell like `/bin/sh`.
If you have shell scripts, then make sure they start with an appropriate `#!/bin/sh` line and that they do word splitting according to the shell chosen there.
In other words, the behaviour of Zsh does not affect other programs and scripts.