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

Re: Proposal: Let compinit make standard widgets with _generic instead of _main_complete



On Sat, Mar 20, 2021 at 11:09 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:

A potential issue with this is that it introduces a difference for
other wrapper widgets that assume _main_complete is THE completion
entry point.

How about this?  It introduces a generic-widgets style, a list of widget names that _main_complete hands off to _generic (which changes the context and hands them back).

diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete
index 169ca1f40..62d94e3ae 100644
--- a/Completion/Base/Core/_main_complete
+++ b/Completion/Base/Core/_main_complete
@@ -10,6 +10,14 @@
 # In case non-standard separators are in use.
 local IFS=$' \t\n\0'
 
+# Test generic-widgets only in global context to avoid recursion
+if [[ "${curcontext:-:::}" == ::: ]] &&
+   zstyle -t ":completion:::::" generic-widgets "$WIDGET"
+then
+    _generic "$@"
+    return
+fi
+
 # If you want to complete only set or unset options for the unsetopt
 # and setopt builtin, un-comment these lines:
 #


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