From 4883bbeebcb5df803c381deaddb181323606fd80 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 21 Mar 2005 22:11:30 +0000 Subject: 21046: make unfunction compadd more reliable --- Completion/Base/Completer/_approximate | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'Completion/Base') diff --git a/Completion/Base/Completer/_approximate b/Completion/Base/Completer/_approximate index b0d8c43c2..dcd8b2776 100644 --- a/Completion/Base/Completer/_approximate +++ b/Completion/Base/Completer/_approximate @@ -12,6 +12,8 @@ local _comp_correct _correct_expl _correct_group comax cfgacc match local oldcontext="${curcontext}" opm="$compstate[pattern_match]" +local dounfunction +integer ret=1 if [[ "$1" = -a* ]]; then cfgacc="${1[3,-1]}" @@ -46,8 +48,12 @@ _tags corrections original # the builtin that adds matches. This is used to be able # to stick the `(#a...)' in the right place (after an # ignored prefix). - +# +# Current shell structure for use with "always", to make sure +# we unfunction the compadd. +{ if (( ! $+functions[compadd] )); then + dounfunction=1 compadd() { local ppre="$argv[(I)-p]" @@ -65,7 +71,6 @@ if (( ! $+functions[compadd] )); then builtin compadd "$_correct_expl[@]" "$@" } - trap 'unfunction compadd' EXIT INT fi _comp_correct=1 @@ -101,13 +106,20 @@ while [[ _comp_correct -le comax ]]; do fi compstate[pattern_match]="$opm" - return 0 + ret=0 + break fi [[ "${#:-$PREFIX$SUFFIX}" -le _comp_correct+1 ]] && break (( _comp_correct++ )) done +} always { + [[ -n $dounfunction ]] && (( $+functions[compadd] )) && unfunction compadd +} + +(( ret == 0 )) && return 0 + compstate[pattern_match]="$opm" return 1 -- cgit 1.4.1