Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: help with _match, globcomplete etc. (with a PATCH)
- X-seq: zsh-workers 9752
- From: Oliver Kiddle <opk@xxxxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxxxxxxxxx>
- Subject: Re: help with _match, globcomplete etc. (with a PATCH)
- Date: Tue, 15 Feb 2000 19:53:50 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <200002151608.RAA14415@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Sven Wischnowsky wrote:
> I couldn't reproduce your `[' problem, unless that was a typo and you
> meant a quoted `{'. In this case it's the same as for the quoted
> globbing characters.
It wasn't a typo. It only occurs when the referenced associative array is set. I can reproduce it as follows:
zsh -f
bindkey -me
unsetopt glob
typeset -A code
code[ai]=foo
echo $code[ai]/{a,<tab>
and, in a separate message:
> You can bind expand-word to ^X$. Expansion of parameter substitutions
> is a problem, because the completion (shell) code doesn't get the
> whole string. We only get the stuff after the $, so we can't really
> change such things.
I don't quite understand what you mean here. _expand seems to get the whole thing including the '$'. The main limiting factor on my configuration is that I can't do parameter expansion, command substitution and arithmetic expansion independantly. Maybe the e parameter expansion flag could allow options to select them. Also, I can't see a way of doing globbing, while preserving variable references.
In general, I don't like the substitution in _expand but the trouble with not having it enabled is that glob expansion will not work on lines with parameters. My solution is the following patch to _expand which adds the style subst-globs-only which if used with substitute and glob, only does expansion if globbing was able to do something meaningful. If you (Sven) are happy with this addition, I'll do a doc patch aswell.
and elsewhere:
> > Another thing which I would like to configure with expansion is when
> > there is only one match, I'd prefer if the space suffix was not added -
> > this is one of the things that makes the variable expansion annoying.
> > Ideally, the suffix would be as if normal completion was used so
> > directories would get a '/'.
> When speaking about variables: see above. When speaking about other
> expansions: _match does that and _expand could be made to do it
> (adding a loop that appends slashes to directory names).
It is only really when the globbing results in only one match that I am concerned about the suffix because my cursor is at the end of that match and I'm likely to go on adding more to it and doing more completion. I'll add a patch for this. Should I make it depend on a zstyle thing? Will it be needed for both of the compadds in _expand?
Out of interest, why does the check in _expand need to check against "$word"(|\(N\)) as opposed to just "$word": under what circumstances can the (N) find its way into $exp?
Thanks for your help
Oliver
--- Completion/Core/_expand.bak Tue Feb 15 19:25:20 2000
+++ Completion/Core/_expand Tue Feb 15 19:26:24 2000
@@ -7,7 +7,7 @@
# the expansions done produce no result or do not change the original
# word from the line.
-local exp word="$PREFIX$SUFFIX" sort expr expl
+local exp word="$PREFIX$SUFFIX" sort expr expl subd
local curcontext="${curcontext/:[^:]#:/:expand:}"
# First, see if we should insert all *completions*.
@@ -34,17 +34,25 @@
[[ -z "$exp" ]] && exp=("$word")
+subd="$exp"
+
# Now try globbing.
zstyle -s ":completion:${curcontext}:" glob expr &&
[[ "${(e):-\$[$expr]}" -eq 1 ]] &&
exp=( ${~exp}(N) )
-
+
# If we don't have any expansions or only one and that is the same
# as the original string, we let other completers run.
[[ $#exp -eq 0 ||
( $#exp -eq 1 && "$exp[1]" = "$word"(|\(N\)) ) ]] && return 1
+
+# With subst-globs-only we bail out if there were no glob expansions,
+# regardless of any substitutions
+zstyle -s ":completion:${curcontext}:" subst-globs-only expr &&
+ [[ "${(e):-\$[$expr]}" -eq 1 ]] &&
+ [[ "$subd" = "$exp"(|\(N\)) ]] && return 1
# Now add as matches whatever the user requested.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author