From 5acedce0b04bca7d2e633d15fb4d8c911cb27268 Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Fri, 8 Oct 2021 12:39:30 +0200 Subject: [PATCH] speed up pre-redraw hook --- internal/p10k.zsh | 48 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 8126b6d1..af56ef77 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -7693,17 +7693,23 @@ function _p9k_widget() { res=$? } } - (( ! __p9k_enabled )) || [[ $CONTEXT != start ]] || { - [[ $1 == zle-line-pre-redraw ]] && (( PENDING || KEYS_QUEUED_COUNT )) && { - (( _p9k__redraw_fd )) || { - sysopen -o cloexec -ru _p9k__redraw_fd /dev/null - zle -F $_p9k__redraw_fd _p9k_redraw - } - return res + (( ! __p9k_enabled )) || [[ $CONTEXT != start ]] || _p9k_widget_hook "$@" + return res +} + +function _p9k_widget_zle-line-pre-redraw-impl() { + (( __p9k_enabled )) && [[ $CONTEXT == start ]] || return 0 + ! (( ${+functions[p10k-on-post-widget]} || ${#_p9k_show_on_command} || _p9k__restore_prompt_fd || _p9k__redraw_fd )) && + [[ ${KEYMAP:-} != vicmd ]] && + return + (( PENDING || KEYS_QUEUED_COUNT )) && { + (( _p9k__redraw_fd )) || { + sysopen -o cloexec -ru _p9k__redraw_fd /dev/null + zle -F $_p9k__redraw_fd _p9k_redraw } - _p9k_widget_hook "$@" + return } - return res + _p9k_widget_hook zle-line-pre-redraw } function _p9k_widget_send-break() { @@ -7718,6 +7724,7 @@ typeset -gi __p9k_widgets_wrapped=0 function _p9k_wrap_widgets() { (( __p9k_widgets_wrapped )) && return + typeset -gir __p9k_widgets_wrapped=1 local -a widget_list if is-at-least 5.3; then @@ -7759,6 +7766,7 @@ function _p9k_wrap_widgets() { zf_rm -f -- $tmp } fi + local widget for widget in $widget_list; do if (( ! $+functions[_p9k_widget_$widget] )); then @@ -7774,6 +7782,28 @@ function _p9k_wrap_widgets() { zle -N $widget _p9k_widget_$widget fi done 2>/dev/null # `zle -A` fails for inexisting widgets and complains to stderr + + case ${widgets[._p9k_orig_zle-line-pre-redraw]:-} in + user:-z4h-zle-line-pre-redraw) + function _p9k_widget_zle-line-pre-redraw() { + -z4h-zle-line-pre-redraw "$@" + _p9k_widget_zle-line-pre-redraw-impl + } + ;; + ?*) + function _p9k_widget_zle-line-pre-redraw() { + zle ._p9k_orig_zle-line-pre-redraw -- "$@" + local -i res=$? + _p9k_widget_zle-line-pre-redraw-impl + return res + } + ;; + '') + function _p9k_widget_zle-line-pre-redraw() { + _p9k_widget_zle-line-pre-redraw-impl + } + ;; + esac } function _p9k_restore_prompt() {