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

Re: namespace completions ?



Marc Chantreux wrote:
> 
> month later, we're happy users of the 'uze' convention: 
> https://github.com/eiro/uze. but we want more! we want completion: 

It's a pity that isn't using function autoloading. It had never occurred
to me before but it apparently works to autoload functions with slashes
in their names and have them picked up out of subdirectories of your
function path.

> saying https://github.com/eiro/uze is set and ready, i would like to
> write this from the CLI: 
> 
>     mc@xxxxxxxxxxxx> a=unistra/annuaire
>     mc@xxxxxxxxxxxx> . uze/$a 
>     mc@xxxxxxxxxxxx> $a/<tab>

So basically, you want completion of shell functions to handle the
beginning of the function being a variable reference in much the same
way as is done for filename completion. By copying parts of _path_files
to _functions, this can be done by modifying _functions as in the patch
below.

I'm not sure if it makes sense to commit this or some variant of it. Any
thoughts? Having borrowed from _path_files, it relies on / to mark the
end of the variable expression.

Oliver

diff --git a/Completion/Zsh/Type/_command_names b/Completion/Zsh/Type/_command_names
index d9fc62d..31cebb0 100644
--- a/Completion/Zsh/Type/_command_names
+++ b/Completion/Zsh/Type/_command_names
@@ -8,10 +8,6 @@ local args defs ffilt
 
 zstyle -t ":completion:${curcontext}:commands" rehash && rehash
 
-zstyle -t ":completion:${curcontext}:functions" prefix-needed && \
- [[ $PREFIX != [_.]* ]] && \
- ffilt='[(I)[^_.]*]'
-
 defs=(
   'commands:external command:_path_commands'
 )
@@ -28,7 +24,7 @@ else
 
   defs=( "$defs[@]"
     'builtins:builtin command:compadd -Qk builtins'
-    "functions:shell function:compadd -k 'functions$ffilt'"
+    "functions:shell function:_functions"
     'aliases:alias:compadd -Qk aliases'
     'suffix-aliases:suffix alias:_suffix_alias_files'
     'reserved-words:reserved word:compadd -Qk reswords'
diff --git a/Completion/Zsh/Type/_functions b/Completion/Zsh/Type/_functions
index 4d33669..0f4b5c6 100644
--- a/Completion/Zsh/Type/_functions
+++ b/Completion/Zsh/Type/_functions
@@ -1,9 +1,24 @@
 #compdef unfunction
 
-local expl ffilt
+local expl funcs
+local ffilt=functions
 
 zstyle -t ":completion:${curcontext}:functions" prefix-needed && \
  [[ $PREFIX != [_.]* ]] && \
- ffilt='[(I)[^_.]*]'
+ ffilt+='[(I)[^_.]*]'
 
-_wanted functions expl 'shell function' compadd -k "$@" - "functions$ffilt"
+funcs=( ${(kP)ffilt} )
+if [[ "$PREFIX" = \$*/* && "$compstate[quote]" != \' ]]; then
+  local realstr
+  local linestr="${(M)PREFIX##*\$[^/]##/}"
+  function {
+    # do not treat an unset parameter expansion as the empty string
+    setopt localoptions nounset
+    eval 'realstr=${(e)~linestr}' 2>/dev/null
+  }
+  [[ -z "$realstr" || "$realstr" = "$linestr" ]] && return 1
+  funcs=( ${${(M)funcs:#$realstr*}##$realstr} )
+  compset -P $linestr
+fi
+
+_wanted functions expl 'shell function' compadd -a "$@" - funcs



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