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

Re: completion for $x:



On Fri, 24 Jan 2014 08:39:26 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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