about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2005-03-21 22:11:30 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2005-03-21 22:11:30 +0000
commit4883bbeebcb5df803c381deaddb181323606fd80 (patch)
treea5dba0d8e3fe2d154882aad5558f24c9153cf231 /Completion
parent24699f961dc3757ddf692413028a4c0f03abe0fd (diff)
downloadzsh-4883bbeebcb5df803c381deaddb181323606fd80.tar.gz
zsh-4883bbeebcb5df803c381deaddb181323606fd80.tar.xz
zsh-4883bbeebcb5df803c381deaddb181323606fd80.zip
21046: make unfunction compadd more reliable
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Base/Completer/_approximate18
1 files changed, 15 insertions, 3 deletions
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