* PATCH: use `always' with _approximate
@ 2005-03-21 22:08 Peter Stephenson
0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2005-03-21 22:08 UTC (permalink / raw)
To: Zsh hackers list
I've been meaning to do this for a while.
You've probably noticed the message:
_main_complete:unfunction:161: no such hash table element: compadd
you sometimes get from aborting approximate completion at the wrong
point.
The key feature here is the "dounfunction" variable and the extra test
for $+functions[compadd]. However, the "always" block ensures that the
code is always executed, which you couldn't easily ensure with a trap.
You should be able to convince yourself, I hope, that it's
impossible for the unfunction to be run or omitted incorrectly.
Index: Completion/Base/Completer/_approximate
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Completer/_approximate,v
retrieving revision 1.7
diff -u -r1.7 _approximate
--- Completion/Base/Completer/_approximate 7 Jan 2002 14:38:14 -0000 1.7
+++ Completion/Base/Completer/_approximate 21 Mar 2005 22:04:24 -0000
@@ -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 @@
# 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 @@
builtin compadd "$_correct_expl[@]" "$@"
}
- trap 'unfunction compadd' EXIT INT
fi
_comp_correct=1
@@ -101,13 +106,20 @@
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
--
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-03-21 22:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-21 22:08 PATCH: use `always' with _approximate Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).