From 9745d3d67a07c252bc9af5fa446e52d5e7379a52 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Sat, 4 Aug 2018 17:23:44 +0200 Subject: [PATCH] =?UTF-8?q?hsmw:=20reset-prompt-protect=20zstyle=20?= =?UTF-8?q?=E2=80=93=20allow=20users=20to=20run=20zle=20reset-prompt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set: zstyle :plugin:history-search-multi-word reset-prompt-protect 1 to be able to use `zle reset-prompt' in your e.g. sched calls, in presence of zdharma/fast-syntax-highlighting, zsh-users/zsh-syntax-high- lighting, zsh-users/zsh-autosuggestions and other plugins that hook up into Zshell by overloading Zle widgets. In general, HSMW should be loaded in bulk (no gap) with all those plugins, right before them. Issue #12 --- history-search-multi-word | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/history-search-multi-word b/history-search-multi-word index 82ec3f0..71c87c3 100644 --- a/history-search-multi-word +++ b/history-search-multi-word @@ -64,8 +64,10 @@ if (( ${+functions[_hsmw_main]} == 0 )); then fi # '0' will get changed into $to_display limit - [[ "$WIDGET" = *-word || "$WIDGET" = *-pforwards ]] && __hsmw_hcw_index="1" - [[ "$WIDGET" = *-backwards || "$WIDGET" = *-pbackwards ]] && __hsmw_hcw_index="0" + [[ "$NO_MOVE" != 1 ]] && { + [[ "$WIDGET" = *-word || "$WIDGET" = *-pforwards ]] && __hsmw_hcw_index="1" + [[ "$WIDGET" = *-backwards || "$WIDGET" = *-pbackwards ]] && __hsmw_hcw_index="0" + } __hsmw_hcw_widget_name="${${${WIDGET%-backwards}%-pbackwards}%-pforwards}" __hsmw_hcw_found=( ) __hsmw_hcw_finished="0" @@ -82,10 +84,12 @@ if (( ${+functions[_hsmw_main]} == 0 )); then fi # Consecutive call - [[ "$WIDGET" = *-word ]] && (( __hsmw_hcw_index ++ )) - [[ "$WIDGET" = *-backwards ]] && (( __hsmw_hcw_index -- )) - [[ "$WIDGET" = *-pforwards ]] && (( __hsmw_hcw_index = __hsmw_hcw_index + __hsmw_page_size )) - [[ "$WIDGET" = *-pbackwards ]] && (( __hsmw_hcw_index = __hsmw_hcw_index - __hsmw_page_size )) + [[ "$NO_MOVE" != 1 ]] && { + [[ "$WIDGET" = *-word ]] && (( __hsmw_hcw_index ++ )) + [[ "$WIDGET" = *-backwards ]] && (( __hsmw_hcw_index -- )) + [[ "$WIDGET" = *-pforwards ]] && (( __hsmw_hcw_index = __hsmw_hcw_index + __hsmw_page_size )) + [[ "$WIDGET" = *-pbackwards ]] && (( __hsmw_hcw_index = __hsmw_hcw_index - __hsmw_page_size )) + } fi # Find history entries matching pattern *word1*~^*word2*~^*word3* etc. @@ -239,6 +243,12 @@ _hsmw_backward_kill_word() { _hsmw_simulate_widget } +_hsmw_reset_prompt() { + zle .reset-prompt + local NO_MOVE=1 + _hsmw_simulate_widget +} + _hsmw_jump_entry() { local entry if (( __hsmw_ctx )); then @@ -256,6 +266,10 @@ _hsmw_jump_entry() { } if [[ "$__hsmw_hcw_call_count" -eq "1" ]]; then + # Load config of reset-prompt protection + local __hsmw_reset_prompt_protect + zstyle -t ":plugin:history-search-multi-word" reset-prompt-protect && __hsmw_reset_prompt_protect=1 || __hsmw_reset_prompt_protect=0 + # Make the hsmw keymap a copy of the current main bindkey -N hsmw emacs @@ -337,9 +351,11 @@ if [[ "$__hsmw_hcw_call_count" -eq "1" ]]; then zle -A self-insert hsmw-saved-self-insert zle -A backward-delete-char hsmw-saved-backward-delete-char zle -A delete-char hsmw-saved-delete-char + (( __hsmw_reset_prompt_protect )) && zle -A reset-prompt hsmw-saved-reset-prompt zle -N self-insert _hsmw_self_insert zle -N backward-delete-char _hsmw_backward_delete_char zle -N delete-char _hsmw_delete_char + (( __hsmw_reset_prompt_protect )) && zle -N reset-prompt _hsmw_reset_prompt # OMZ does funny things with zle-keymap-select zle -la zle-keymap-select && { @@ -405,7 +421,9 @@ if [[ "$__hsmw_hcw_call_count" -eq "1" ]]; then zle -A hsmw-saved-self-insert self-insert zle -A hsmw-saved-backward-delete-char backward-delete-char zle -A hsmw-saved-delete-char delete-char + (( __hsmw_reset_prompt_protect )) && zle -A hsmw-saved-reset-prompt reset-prompt zle -D hsmw-saved-self-insert hsmw-saved-backward-delete-char hsmw-saved-delete-char + (( __hsmw_reset_prompt_protect )) && zle -D hsmw-saved-reset-prompt zle -la hsmw-saved-zle-keymap-select && { zle -A hsmw-saved-zle-keymap-select zle-keymap-select zle -D hsmw-saved-zle-keymap-select