summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2023-08-27 15:27:45 -0700
committerBart Schaefer <schaefer@zsh.org>2023-08-27 15:27:45 -0700
commit5f984319b5154e9370dbf9c2012b12a133708f48 (patch)
treeb8314d8f01a172d3105850af264c2f6d8bd839a6
parent2a854aae481e7eb064729db28a71ed0efb2f33e6 (diff)
downloadzsh-5f984319b5154e9370dbf9c2012b12a133708f48.tar.gz
zsh-5f984319b5154e9370dbf9c2012b12a133708f48.zip
Marlon Richert: 51861: fix _approximate when compadd has been overridden
Before this patch, if compadd had been overridden by a function of the same name, _approximate would not do corrections.
-rw-r--r--ChangeLog4
-rw-r--r--Completion/Base/Completer/_approximate48
2 files changed, 26 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 412dbda61..6b7b1173b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2023-08-27 Bart Schaefer <schaefer@zsh.org>
+ * Marlon Richert: 51861 (tweaked for 52028):
+ Completion/Base/Completer/_approximate: allow _approximate
+ to provide corrections even when compadd is overridden
+
* 52028: Completion/Base/Utility/_shadow, Doc/Zsh/compsys.yo,
Doc/Zsh/contrib.yo, Functions/Misc/mkshadow: improve _shadow
and _unshadow, add helper function and update documentation
diff --git a/Completion/Base/Completer/_approximate b/Completion/Base/Completer/_approximate
index dcd8b2776..96860b5a7 100644
--- a/Completion/Base/Completer/_approximate
+++ b/Completion/Base/Completer/_approximate
@@ -12,7 +12,6 @@
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
@@ -44,34 +43,31 @@ fi
_tags corrections original
-# Otherwise temporarily define a function to use instead of
-# the builtin that adds matches. This is used to be able
-# to stick the `(#a...)' in the right place (after an
-# ignored prefix).
+# Otherwise temporarily define a function to use instead of 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.
+# Current shell structure for use with "always", to make sure we unfunction our
+# compadd and restore any compadd function defined previously.
{
-if (( ! $+functions[compadd] )); then
- dounfunction=1
- compadd() {
- local ppre="$argv[(I)-p]"
-
- [[ ${argv[(I)-[a-zA-Z]#U[a-zA-Z]#]} -eq 0 &&
- "${#:-$PREFIX$SUFFIX}" -le _comp_correct ]] && return
-
- if [[ "$PREFIX" = \~* && ( ppre -eq 0 || "$argv[ppre+1]" != \~* ) ]]; then
- PREFIX="~(#a${_comp_correct})${PREFIX[2,-1]}"
- else
- PREFIX="(#a${_comp_correct})$PREFIX"
- fi
+_shadow -s _approximate compadd
+compadd() {
+ local ppre="$argv[(I)-p]"
- (( $_correct_group && ${${argv[1,(r)-(|-)]}[(I)-*[JV]]} )) &&
- _correct_expl[_correct_group]=${argv[1,(r)-(-|)][(R)-*[JV]]}
+ [[ ${argv[(I)-[a-zA-Z]#U[a-zA-Z]#]} -eq 0 &&
+ "${#:-$PREFIX$SUFFIX}" -le _comp_correct ]] && return
- builtin compadd "$_correct_expl[@]" "$@"
- }
-fi
+ if [[ "$PREFIX" = \~* && ( ppre -eq 0 || "$argv[ppre+1]" != \~* ) ]]; then
+ PREFIX="~(#a${_comp_correct})${PREFIX[2,-1]}"
+ else
+ PREFIX="(#a${_comp_correct})$PREFIX"
+ fi
+
+ (( $_correct_group && ${${argv[1,(r)-(|-)]}[(I)-*[JV]]} )) &&
+ _correct_expl[_correct_group]=${argv[1,(r)-(-|)][(R)-*[JV]]}
+
+ compadd@_approximate "$_correct_expl[@]" "$@"
+}
_comp_correct=1
@@ -115,7 +111,7 @@ while [[ _comp_correct -le comax ]]; do
done
} always {
- [[ -n $dounfunction ]] && (( $+functions[compadd] )) && unfunction compadd
+ _unshadow
}
(( ret == 0 )) && return 0