akermu / emacs-libvterm

Emacs libvterm integration
GNU General Public License v3.0
1.67k stars 131 forks source link

ZSH integration script breaks popular zsh plugin (zsh-users/zsh-autosuggestions) #574

Open freeo opened 2 years ago

freeo commented 2 years ago

This file: ~/.emacs.d/.local/straight/repos/emacs-libvterm/etc/emacs-vterm-zsh.sh

contains this offending line: add-zsh-hook -Uz chpwd (){ print -Pn "\e]2;%m:%2~\a" }

This breaks this plugin: https://github.com/zsh-users/zsh-autosuggestions

I tried to remove/undo this hook with add-zsh-hook -d ... but all my attempts failed. I don't want to just comment this line out, as I don't want to version control emacs-vterm-zsh.sh

Would like to request some help here...

Sbozzolo commented 2 years ago

I use zsh with zsh-autosuggestions on a remote machine and everything works fine. How does it break exactly?

freeo commented 2 years ago

As per documentation, I've added the extra configs to make the most of emacs/vterm integration by adding these lines to my zshrc:

if [[ "$INSIDE_EMACS" = 'vterm' ]] \
    && [[ -n ${EMACS_VTERM_PATH} ]] \
    && [[ -f ${EMACS_VTERM_PATH}/etc/emacs-vterm-zsh.sh ]]; then
  source ${EMACS_VTERM_PATH}/etc/emacs-vterm-zsh.sh
[...]

The sourced script contains this line:

 add-zsh-hook -Uz chpwd (){ print -Pn "\e]2;%m:%2~\a" }

When I comment this line, autosuggestions work as expected. Uncommenting this line-> no autosuggestions at all.

So this zsh-hook somehow interferes with the inner workings of autosuggestions. And since this hook isn't changing the vterm buffer title (which it should as per docs) I just want to undo this hook somehow, which is why I'm asking here. I couldn't find a way.

Sbozzolo commented 2 years ago

If the title in not changing, there is probably another problem.

If you just want to remove the hook, you don't really need the entire emacs-vterm-zsh.sh. You can just copy and paste the parts that you like in your .zshrc.

freeo commented 2 years ago

I was thinking of copy & pasting as well. But I like the idea of getting upstream changes to this file on updating vterm, that's why I was thinking towards overriding just this line.

But considering the title isn't even changing, let's investigate. Shall I generate some output that will help debug this?

Sbozzolo commented 2 years ago

It would be useful if you could verify that the problem appears with a clean Emacs and clean zsh. Maybe it is the interaction with some other plugins that is messing up things.

ryuheechul commented 2 years ago

I also confirm that this issue exists on my setup as well and I mitigated it by managing the file in my repo (as suggested in this issue) until there is a change made from upstream.

slackorama commented 1 year ago

Having the same problem.

add-zsh-hook -Uz chpwd (){ print -Pn "\e]2;%m:%2~\a" }

seems to be redefining add-zsh-hook.

When I load up vterm I get the following:

❯ type add-zsh-hook
add-zsh-hook is a shell function from /usr/share/zsh/5.8.1/functions/add-zsh-hook
❯ source $EMACS_VTERM_PATH/etc/emacs-vterm-zsh.sh 
❯ type add-zsh-hook                              
add-zsh-hook is a shell function from /Users/seth/.emacs.d/.local/straight/build-28.2/vterm//etc/emacs-vterm-zsh.sh
❯ which add-zsh-hook 
add-zsh-hook () {
        print -Pn "\e]2;%m:%2~\a"
}

This looks very wrong.

ryuheechul commented 1 year ago

it seems like it's similar issue with this one, https://github.com/teaxyz/cli/issues/281 (which contains a resolution or workaround depends on your view)