From 41bed1384d16d5c5043d02d2dd064e15aeaecbd7 Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Sat, 20 Nov 2021 21:07:46 +0200 Subject: [PATCH] Let most widgets remove history line suffix Resolves #370. --- .../completion/_autocomplete.history_lines | 19 ++++++++++++++----- .../.autocomplete.history-search.zle-widget | 2 -- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/functions/completion/_autocomplete.history_lines b/functions/completion/_autocomplete.history_lines index 507c0122..819ed1c8 100644 --- a/functions/completion/_autocomplete.history_lines +++ b/functions/completion/_autocomplete.history_lines @@ -122,12 +122,21 @@ _autocomplete.history_lines() { # functions -T _autocomplete.history_lines _autocomplete.history_lines.suffix() { - case $KEYS in - ( [$ZLE_SPACE_SUFFIX_CHARS$ZLE_REMOVE_SUFFIX_CHARS] ) + case $WIDGET in + ( (|.|*-)(hist(|ory)|search|delete|kill)(|-*) ) + ;; + ( (|.)(self-insert(|-*)|magic-space) ) + case $KEYS[-1] in + ( [$ZLE_SPACE_SUFFIX_CHARS$ZLE_REMOVE_SUFFIX_CHARS] ) + LBUFFER=$LBUFFER[1,-1-$1] + ;| + ( [$ZLE_SPACE_SUFFIX_CHARS] ) + LBUFFER+=' ' + ;; + esac + ;; + ( * ) LBUFFER=$LBUFFER[1,-1-$1] - ;| - ( [$ZLE_SPACE_SUFFIX_CHARS] ) - LBUFFER+=' ' ;; esac } diff --git a/functions/widget/.autocomplete.history-search.zle-widget b/functions/widget/.autocomplete.history-search.zle-widget index 50c951c4..acf23b8e 100644 --- a/functions/widget/.autocomplete.history-search.zle-widget +++ b/functions/widget/.autocomplete.history-search.zle-widget @@ -13,7 +13,6 @@ ${0}.context() { ${0}() { local -P lbuffer="$LBUFFER" rbuffer="$RBUFFER" local -P keymap_menuselect="$( builtin bindkey -M menuselect -L )" - typeset -g ZLE_REMOVE_SUFFIX_CHARS=${ZLE_REMOVE_SUFFIX_CHARS/ } { builtin bindkey -M menuselect -s \ '^R' '^_^_^R' \ @@ -36,7 +35,6 @@ ${0}() { builtin zle _history_search } always { - ZLE_REMOVE_SUFFIX_CHARS+=' ' builtin bindkey -M menuselect -r '^R' '^S' '\e'{\[,O}{D,C} eval "$keymap_menuselect" if [[ $BUFFER == $lcontext$rcontext ]] then