zsh-autosuggestions: Maybe fix for slow pastes

Howdy, I think I may have a solution for slow pastes (#141 #219) but I’m not sure if there are problems with it or what the best way to actually implement it is.

I believe that the paste slowdown comes from the additional zle invocation to call the original widget on self-insert. Rather than doing that, if, on disable, we replace self-insert with the original widget and then on enable, we replace it back, things are snappy.

Here is my naive implementation:

# Disable suggestions
_zsh_autosuggest_disable() {
	typeset -g _ZSH_AUTOSUGGEST_DISABLED
	_zsh_autosuggest_clear
	zle -N self-insert url-quote-magic
}

# Enable suggestions
_zsh_autosuggest_enable() {
	unset _ZSH_AUTOSUGGEST_DISABLED
	zle -N self-insert _zsh_autosuggest_bound_1_self-insert

	if [ $#BUFFER -gt 0 ]; then
		_zsh_autosuggest_fetch
	fi
}

Obviously we shouldn’t hard-code url-quote-magic or _zsh_autosuggest_bound_1_self-insert but I wasn’t sure of the best way to get the right ones in there.

Thoughts? Suggestions? Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 23 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Works for me. Thanks again for your help.

For posterity:

# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
  OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
  zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}

pastefinish() {
  zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish

The proposed fix works for me but why is it not added to zsh-autosuggestions and needs to be applied manually?

The proposed fix works for me but why is it not added to zsh-autosuggestions and needs to be applied manually?

I’d also like to know why this can’t be included directly in zsh-autosuggestions

Where does one use apply this?

Works for me. Thanks again for your help.

For posterity:

# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
  OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
  zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}

pastefinish() {
  zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish

I put mine in my .zshrc

I fixed this issue by adding the following line to my .zshrc config

zstyle ':bracketed-paste-magic' active-widgets '.self-*'

maybe this advice should be added to the readme. What do you think @ericfreese?

@bric3, I experience this bug as well. The above fix isn’t really intended to address that, it’s intended to make pasting fast, which it does for me. It seems there could still be an issue with either that fix or with zsh-autosuggestions.