Skip to content

Commit

Permalink
Work around a crashing bug in Zsh
Browse files Browse the repository at this point in the history
See [zsh-workers 48936](https://www.zsh.org/mla/workers/2021/msg01162.html).
Fixes issue #274.
  • Loading branch information
marlonrichert committed May 27, 2021
1 parent a99fcd4 commit 70f6aa0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
10 changes: 5 additions & 5 deletions module/.autocomplete.async
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ bindkey -s -M menuselect '^S' '^G^S'
.autocomplete.async.complete() {
.autocomplete.zle-flags $LASTWIDGET

[[ -v MENUSELECT && ( -z $KEYS || $( bindkey "$KEYS" ) != *'" '$LASTWIDGET ) ]] &&
return

unset MENUSELECT

(( KEYS_QUEUED_COUNT || PENDING )) &&
return 0

Expand All @@ -117,11 +122,6 @@ bindkey -s -M menuselect '^S' '^G^S'
[[ -v functions[_zsh_autosuggest_highlight_apply] ]] &&
_zsh_autosuggest_highlight_apply

[[ -v MENUSELECT && $( bindkey "$KEYS" ) != *'" '$LASTWIDGET ]] &&
return

unset MENUSELECT

if (( REGION_ACTIVE )) ||
[[ -v _autocomplete__isearch && $LASTWIDGET == *(incremental|isearch)* ]]; then
zle -Rc
Expand Down
12 changes: 8 additions & 4 deletions module/.autocomplete.key-binding
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ zmodload -Fa zsh/parameter p:funcstack p:functions
.autocomplete.key

local tab_style; zstyle -s :autocomplete:tab: widget-style tab_style ||
tab_style='complete-word'
tab_style='complete-word'
local backtab_style; zstyle -s :autocomplete:shift-tab: widget-style backtab_style ||
backtab_style=${tab_style:/menu-complete/reverse-menu-complete}

if zstyle -t :autocomplete:tab: fzf || zstyle -t :autocomplete:tab: fzf-completion; then
typeset -gH fzf_default_completion=$tab_style
Expand All @@ -28,15 +30,17 @@ zmodload -Fa zsh/parameter p:funcstack p:functions
bindkey -M emacs $key[Tab] $tab_style
bindkey -M viins $key[Tab] $tab_style
fi
local backtab_style=${tab_style:/menu-complete/reverse-menu-complete}
bindkey -M emacs $key[Shift-Tab] $backtab_style
bindkey -M viins $key[Shift-Tab] $backtab_style

if [[ $tab_style == menu-* ]]; then
if [[ $tab_style == *menu-* ]]; then
bindkey -M menuselect $key[Tab] menu-complete
bindkey -M menuselect $key[Shift-Tab] reverse-menu-complete
else
bindkey -M menuselect $key[Tab] accept-line
fi
if [[ $backtab_style == *menu-* ]]; then
bindkey -M menuselect $key[Shift-Tab] reverse-menu-complete
else
bindkey -M menuselect $key[Shift-Tab] send-break
fi
}
Expand Down
35 changes: 22 additions & 13 deletions widget/.autocomplete.complete-word.post
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
#autoload
unset MENUSELECT
unset curcontext
compstate[insert]=
compstate[list]=

local key_name=${(kL)key[(Re)$KEYS]}
local key_style; zstyle -s :autocomplete:${key_name}: widget-style key_style

if ( [[ $KEYS == $key[Shift-Tab] ]] ||
zstyle -t ":autocomplete:${(kL)key[(Re)$KEYS]}:" insert-unambiguous
zstyle -t ":autocomplete:${key_name}:" insert-unambiguous
) && [[ $IPREFIX$PREFIX$SUFFIX$ISUFFIX != *${compstate[unambiguous]:#?}* ]]; then
compstate[insert]=${${(M)WIDGET:#*menu-*}:+automenu-}unambiguous
# Work around a crashing bug in Zsh.
# See [zsh-workers 48936](https://www.zsh.org/mla/workers/2021/msg01162.html).
[[ $key_style == *menu-* && $KEYS == ($key[Tab]|$key[Shift-Tab]) ]] &&
compstate[insert]='automenu-'

compstate[insert]+=unambiguous
return
fi

compstate[insert]=
unset MENUSELECT

if [[ $WIDGET == *menu-select ]]; then
# Determine which terminal line we're on (for async completion).
(( _autocomplete__buffer_start_line = max( BUFFERLINES, LINES - compstate[list_lines] ) ))
MENUSELECT=0
fi

# Work around a crashing bug in Zsh.
# See [zsh-workers 48936](https://www.zsh.org/mla/workers/2021/msg01162.html).
[[ $key_style == *menu-* && $KEYS == ($key[Tab]|$key[Shift-Tab]) ]] &&
compstate[insert]='menu:'

if [[ $KEYS == $key[Shift-Tab] ]]; then
compstate[insert]+=0
compstate[insert]+='0'
else
compstate[insert]+=1
compstate[insert]+='1'
fi

local -a tags; zstyle -a :autocomplete: add-space tags ||
tags=( executables aliases functions builtins reserved-words commands )
if [[ $RBUFFER != [[:space:]]* && -n ${${=${_comp_tags:-$_lastcomp[tags]}}:*tags} ]]; then
[[ $WIDGET == *menu-* ]] &&
compstate[insert]="menu:$compstate[insert]"
compstate[insert]+=' '
fi
tags=( executables aliases functions builtins reserved-words commands )
[[ $RBUFFER != [[:space:]]* && -n ${${=${_comp_tags:-$_lastcomp[tags]}}:*tags} ]] &&
compstate[insert]+=' '

0 comments on commit 70f6aa0

Please sign in to comment.