Subject: Re: How can Zle -U interfere with zsh-syntax-highlighting?
From: Bart Schaefer <[email-masked]>
To: Zsh hackers list <[email-masked]>
Date: Sun, 15 May 2016 04:13:21 -0700
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Sat, May 14, 2016 at 2:07 PM, Sebastian Gniazdowski
<[email-masked]> wrote:
> Below is a widget that outputs long sophisticated string with zle -U:
>
[...]
>
> With z-sy-h enabled, it takes 4 seconds to appear after pressing
> Ctrl-T. Pasting the same text is instant and correct (i.e.
> highlighting works). What can be happening?

This (line 73-74 in current z-sy-h.zsh):

# Do not highlight if there are pending inputs (copy/paste).
[[ $PENDING -gt 0 ]] && return $ret

"zle -U" feeds the input back to zle one character at a time but does
not set PENDING, so I suspect the highlight is being recaculated after
every character.  I suppose it might make sense for "zle -U" to
pretend to be actual input even to the extent of PENDING, but it
currently does not.

This also explains why immediately typing something else speeds things
up:  Highlighting pauses until that character is consumed.

> Is there some alternative to Zle -U?

Other than just LBUFFER+="long text here", no.  If you want the other
effects of zle -U (i.e., that each character is interpreted as if it
had been typed) then there is no alternative.