From b08d508cd8792df2b6c8e044e42dffeb7f9118fe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 15:49:24 +0000 Subject: [PATCH] driver: Fix a bug that prevented subsequent, third-party zle-line-pre-redraw hooks from running. Without this patch, `_zsh_highlight` was invoked by add-zle-hook-widget with `$?` being non-zero (see add-zle-hook-widget:48-52). Since `_zsh_highlight` preserves `$?` from its caller's point of view, add-zle-hook-widget saw a non-zero exit code from `_zsh_highlight` and did not run any the remaining zle-line-pre-redraw hooks. See https://github.com/zsh-users/zsh-syntax-highlighting/issues/579#issuecomment-623576907. --- zsh-syntax-highlighting.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index aa650d3..47a4e07 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -350,9 +350,15 @@ then _zsh_highlight } } + _zsh_highlight__zle-line-pre-redraw() { + # Set $? to 0 for _zsh_highlight. Without this, subsequent + # zle-line-pre-redraw hooks won't run, since add-zle-hook-widget happens to + # call us with $? == 1 in the common case. + true && _zsh_highlight "$@" + } _zsh_highlight_bind_widgets(){} if [[ -o zle ]]; then - add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + add-zle-hook-widget zle-line-pre-redraw _zsh_highlight__zle-line-pre-redraw add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish fi else