Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Magic-Backspace



On 11 Sep, Pascal Wittmann wrote:
> 
> I thought of implementing some magic-backspace that removes characters
> until the 'current' completion is ambiguous (i.e. some extended version
> of undo).

I've got a function which does roughly this. It has a number of issues
and, as I wrote it over eight years ago, I can't remember what those
issues are. I've attached it below. It works by removing characters
from the PREFIX and trying completion. It is intended to be used as a
completion widget via _generic:
  zle -C retract complete-word _generic
  zstyle ':completion:retract::::' completer _retract
  bindkey '^[[24~' retract  # F12

I'm not sure what the commented out line was for.

Oliver

#autoload

local _comp_backup=1 bumax=30

if (( ! $+functions[compadd] )); then
  compadd() {
    local save oldp="$PREFIX"
    SUFFIX=
    # removing the -O option is a nasty way to make this work from _multi_parts
    zparseopts -D -E O:=save
    local i
    for ((i=_comp_backup;i>0;i--)); do
      PREFIX="${PREFIX%?}"
    done

    builtin compadd -S '' -F "( $oldp* )" "$@"
  }
  trap 'unfunction compadd' EXIT INT
fi

while [[ _comp_backup -le bumax ]]; do
  _complete && return
  (( _comp_backup++ ))
done

#builtin compadd - ''

return 1
    



Messages sorted by: Reverse Date, Date, Thread, Author