* completion for $x:
@ 2014-01-24 6:40 Dave Yost
2014-01-24 16:39 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Dave Yost @ 2014-01-24 6:40 UTC (permalink / raw)
To: zsh-workers
I couldn’t remember what the modifiers were, so I hit the tab key after
Z% echo $x:
It would be nice if zsh would show all the : modifiers with a quick summary of what each does.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: completion for $x:
2014-01-24 6:40 completion for $x: Dave Yost
@ 2014-01-24 16:39 ` Bart Schaefer
2014-01-24 23:15 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2014-01-24 16:39 UTC (permalink / raw)
To: zsh-workers
On Jan 23, 10:40pm, Dave Yost wrote:
}
} I couldn't remember what the modifiers were, so I hit the tab key after
} Z% echo $x:
Hmm, curious. When completing after "$x" (no colon), the internals have
identified "p" as the prefix and know that we're in parameter context,
before _main_complete is even invoked. With the colon, however, the
context has reverted to "command", and we attempt to complete for the
arguments of "echo" instead. This happens even if you have an opening
brace "${x:" with no matching close, in contrast to "${x" which goes
into brace_parameter context.
So it appears there's some relatively low-level parsing that needs to
be tweaked to recognize that ":" does not end a parameter expansion,
before we can even think about describing the modifiers.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: completion for $x:
2014-01-24 16:39 ` Bart Schaefer
@ 2014-01-24 23:15 ` Peter Stephenson
0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2014-01-24 23:15 UTC (permalink / raw)
To: zsh-workers
On Fri, 24 Jan 2014 08:39:26 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Jan 23, 10:40pm, Dave Yost wrote:
> }
> } I couldn't remember what the modifiers were, so I hit the tab key after
> } Z% echo $x:
>
> Hmm, curious. When completing after "$x" (no colon), the internals have
> identified "p" as the prefix and know that we're in parameter context,
> before _main_complete is even invoked. With the colon, however, the
> context has reverted to "command", and we attempt to complete for the
> arguments of "echo" instead. This happens even if you have an opening
> brace "${x:" with no matching close, in contrast to "${x" which goes
> into brace_parameter context.
check_param() does some typically hairy second guessing of the shell
syntax.
Here's a simple-minded approach to this case, however there's so much
more to parameters that this just scratches the surface.
Note this sometimes gets usurped by the shell trying expansions if you
are using _expand, but only sometimes; I haven't worked out what the
criterion is.
diff --git a/Completion/Zsh/Context/_brace_parameter b/Completion/Zsh/Context/_brace_parameter
index c0ecf25..2aeb12b 100644
--- a/Completion/Zsh/Context/_brace_parameter
+++ b/Completion/Zsh/Context/_brace_parameter
@@ -185,6 +185,9 @@ if [[ $PREFIX = *'${('[^\)]# ]]; then
)
_describe -t flags "parameter flag" flags -Q -S ''
return
+elif compset -P '*:'; then
+ _history_modifiers p
+ return
fi
_parameters -e
diff --git a/Completion/Zsh/Type/_parameters b/Completion/Zsh/Type/_parameters
index 5156e3e..eaad3ca 100644
--- a/Completion/Zsh/Type/_parameters
+++ b/Completion/Zsh/Type/_parameters
@@ -8,6 +8,11 @@
local expl pattern fakes faked tmp pfilt
+if compset -P '*:'; then
+ _history_modifiers p
+ return
+fi
+
pattern=(-g \*)
zparseopts -D -K -E g:=pattern
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index 5c5628a..ac7785a 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -1260,6 +1260,20 @@ check_param(char *s, int set, int test)
ispar = (br >= 2 ? 2 : 1);
b[we-wb] = '\0';
return b;
+ } else if (offs > e - s && *e == ':') {
+ /*
+ * Guess whether we are in modifiers.
+ * If the name is followed by a : and the stuff after
+ * that is either colons or alphanumerics we probably are.
+ * This is a very rough guess.
+ */
+ char *offsptr = s + offs;
+ for (; e < offsptr; e++) {
+ if (*e != ':' && !ialnum(*e))
+ break;
+ }
+ ispar = (br >= 2 ? 2 : 1);
+ return NULL;
}
}
return NULL;
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-24 23:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-24 6:40 completion for $x: Dave Yost
2014-01-24 16:39 ` Bart Schaefer
2014-01-24 23:15 ` 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).