Skip to content

Commit

Permalink
Stop infinite syntax highlight loop
Browse files Browse the repository at this point in the history
Prevent `zsh-syntax-highlighting` from going into an infinite loop.
  • Loading branch information
marlonrichert committed Jan 22, 2021
1 parent 1d26537 commit 397f8e7
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions functions/.znap.prompt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# args: [<repo>] <theme>
zmodload -F zsh/parameter p:functions
zmodload -F zsh/terminfo b:echoti p:terminfo
autoload -Uz add-zle-hook-widget add-zsh-hook
autoload -Uz add-zsh-hook

.znap.prompt.setup() {
emulate -L zsh; setopt $_znap_opts
Expand Down Expand Up @@ -62,16 +62,28 @@ autoload -Uz add-zle-hook-widget add-zsh-hook

add-zsh-hook precmd .znap.prompt.precmd

# Prevent `zsh-syntax-highlighting` from sending us into an infinite loop.
typeset -gHi _znap__hook_widgets=0
add-zle-hook-widget() {
eval ":znap:add-zle-hook-widget:$(( ++_znap__hook_widgets ))() {
add-zle-hook-widget $*
}"
}
{
prompt_themes+=( $theme )
prompt $theme

local precmd=prompt_${theme}_precmd
[[ -n $functions[$precmd] ]] &&
$precmd
} always {
unfunction add-zle-hook-widget
autoload -Uz add-zle-hook-widget
}

.znap.prompt.echoti sc # save cursor position
.znap.prompt.echoti civis # invisible cursor

prompt_themes+=( $theme )
prompt $theme

local precmd=prompt_${theme}_precmd
[[ -n $functions[$precmd] ]] &&
$precmd

[[ -o promptcr ]] &&
print -n $'\r'

Expand All @@ -85,6 +97,10 @@ autoload -Uz add-zle-hook-widget add-zsh-hook
add-zsh-hook -d precmd ${(%):-%N}

add-zle-hook-widget line-init .znap.prompt.line-init
local -i i; for (( i = 1; i <= _znap__hook_widgets; i++ )); do
eval :znap:add-zle-hook-widget:$i
done
unset _znap__hook_widgets

.znap.prompt.echoti civis # invisible cursor
.znap.prompt.echoti invis # invisible text
Expand Down

0 comments on commit 397f8e7

Please sign in to comment.