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

PATCH: fake parameters



Some time ago Felix told us about his specialised version of
_parameters that allows to complete names of as-yet unset
parameters. We were then discussing using the fake style for this.

Here is a first implementation. I've used the name `fake-parameters',
mainly to ask (again) if we should either name it just `fake', too, or 
if we should rename the `fake' style to `fake-files'.

The format of `fake-parameters' is different: the values are just the
names of the parameters to be completed, optionally followed by a
colon and a type-string (e.g. `foo:array' to say that it should
complete the name `foo' and treat it like an array).

Because of the different format I think it would be sensible to rename 
`fake' to `fake-files', I'm just not sure how many setups it would
break (not too much yet, I guess). So what do you all think?


The patch also contains a hunk for _vars (and an accompanying hunk in
_subscript) to use _subscript for completing, well, subscripts.


The hunk in _math only ensures that one can complete other parameters
than integers and floats in math contexts again. I have been playing
with an implementation for the parameter-patterns style we were
discussing at that time, too. But it still seemed like overkill for
something as simple as completing parameters. But maybe if we use a
much simpler version (i.e. not allowing everything file-patterns
does)... dunno. (And there wasn't much of a discussion either, so
maybe others think that it isn't really needed, too. Hm.)

Bye
 Sven

Index: Completion/Base/_math
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_math,v
retrieving revision 1.3
diff -u -r1.3 _math
--- Completion/Base/_math	2000/08/10 21:12:03	1.3
+++ Completion/Base/_math	2000/10/10 13:59:11
@@ -9,4 +9,4 @@
   SUFFIX="${SUFFIX%%[^a-zA-Z0-9_]*}"
 fi
 
-_parameters -g '(integer|float)*'
+_parameters -g '(integer|float)*' || _parameters
Index: Completion/Base/_subscript
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_subscript,v
retrieving revision 1.3
diff -u -r1.3 _subscript
--- Completion/Base/_subscript	2000/05/31 09:38:26	1.3
+++ Completion/Base/_subscript	2000/10/10 13:59:11
@@ -1,7 +1,13 @@
 #compdef -subscript-
 
-local expl
+local expl osuf=']'
 
+if [[ "$1" = -q ]]; then
+  osuf='] '
+  compquote osuf
+  shift
+fi
+
 if [[ "$PREFIX" = :* ]]; then
   _wanted characters expl 'character class' \
       compadd -p: -S ':]' alnum alpha blank cntrl digit graph \
@@ -9,7 +15,7 @@
 elif [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
   local suf
 
-  [[ "$RBUFFER" != \]* ]] && suf=']'
+  [[ "$RBUFFER" != (|\\)\]* ]] && suf="$osuf"
 
   _wanted association-keys expl 'association key' \
       compadd -S "$suf" -k "$compstate[parameter]"
@@ -37,12 +43,12 @@
         disp=()
       fi
 
-      if [[ "$RBUFFER" = \]* ]]; then
+      if [[ "$RBUFFER" = (|\\)\]* ]]; then
         _all_labels -V indexes expl 'array index' \
             compadd -S '' "$disp[@]" -a ind && ret=0
       else
         _all_labels -V indexes expl 'array index' \
-            compadd -S ']' "$disp[@]" -a ind && ret=0
+            compadd -S "$osuf" "$disp[@]" -a ind && ret=0
       fi
     fi
     _requested parameters && _parameters && ret=0
Index: Completion/Builtins/_vars
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_vars,v
retrieving revision 1.5
diff -u -r1.5 _vars
--- Completion/Builtins/_vars	2000/08/10 21:22:25	1.5
+++ Completion/Builtins/_vars	2000/10/10 13:59:11
@@ -6,20 +6,12 @@
 local ret=1
 
 if [[ $PREFIX = *\[* ]]; then
-  local var=${PREFIX%%\[*}
-  local elt="${PREFIX#*\]}${SUFFIX%\]}"
-  local addclose
+  compstate[parameter]=${PREFIX%%(|\\)\[*}
 
-  compset -p $(( ${#var} + 1 ))
-  if ! compset -S \]; then
-    addclose=(-S "${${QIPREFIX:+]}:-\]}")
-  fi
-  if [[ ${(tP)var} = assoc* ]]; then
-    local expl
+  IPREFIX=${PREFIX%%\[*}\[
+  PREFIX=${PREFIX#*\[}
 
-    _wanted -C subscript association-keys expl 'association key' \
-        compadd $addclose -k "$var"
-  fi
+  _subscript -q
 else
   _parameters -g '^a*' "$@" && ret=0
   
Index: Completion/Builtins/_zstyle
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_zstyle,v
retrieving revision 1.18
diff -u -r1.18 _zstyle
--- Completion/Builtins/_zstyle	2000/08/15 09:31:20	1.18
+++ Completion/Builtins/_zstyle	2000/10/10 13:59:11
@@ -25,6 +25,7 @@
   domains                c:
   expand		 c:
   fake			 c:fake
+  fake-parameters	 c:fake-params
   file-patterns		 c:filepat
   file-sort              c:fsort
   force-list             c:
@@ -267,6 +268,10 @@
 
     fake)
       _message 'prefix and names'
+      ;;
+
+    fake-params)
+      _message 'name and optional type'
       ;;
 
     ignline) 
Index: Completion/Core/_parameters
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_parameters,v
retrieving revision 1.4
diff -u -r1.4 _parameters
--- Completion/Core/_parameters	2000/08/11 12:19:35	1.4
+++ Completion/Core/_parameters	2000/10/10 13:59:11
@@ -6,10 +6,25 @@
 # If you specify a -g option with a pattern, the pattern will be used to
 # restrict the type of parameters matched.
 
-local expl pattern
+local expl pattern fakes faked tmp
 
 pattern=(-g \*)
 zparseopts -D -K -E g:=pattern
 
-_wanted parameters expl parameter compadd "$@" \
-   -Q -k "parameters[(R)${pattern[2]}~*local*]"
+fakes=()
+faked=()
+if zstyle -a ":completion:${curcontext}:" fake-parameters tmp; then
+  for i in "$tmp[@]"; do
+    if [[ "$i" = *:* ]]; then
+      faked=( "$faked[@]" "$i" )
+    else
+      fakes=( "$fakes[@]" "$i" )
+    fi
+  done
+fi
+
+_wanted parameters expl parameter \
+    compadd "$@" -Q - \
+        "${(@k)parameters[(R)${pattern[2]}~*local*]}" \
+        "$fakes[@]" \
+        "${(@)${(@M)faked:#${~pattern[2]}}%%:*}"
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.98
diff -u -r1.98 compsys.yo
--- Doc/Zsh/compsys.yo	2000/10/05 08:41:36	1.98
+++ Doc/Zsh/compsys.yo	2000/10/10 13:59:12
@@ -1020,6 +1020,17 @@
 This can be useful on systems that support special filesystems whose
 top-level pathnames can not be listed or generated with glob patterns.
 )
+kindex(fake-parameters, completion style)
+item(tt(fake-parameters))(
+This is used by the completion function generating parameter names as
+matches.  Its values are names of parameters which might not yet be
+set, but which should be completed nonetheless.  Each name may also be 
+followed by a colon and a string specifying the type of the parameter
+(like `tt(scalar)', `tt(array)' or `tt(integer)').  If such a type is
+given, the name will only be completed if parameters of that type are
+requested in the particular context.  Names for which no type is
+specified will always be completed.
+)
 kindex(file-patterns, completion style)
 item(tt(file-patterns))(
 In most places where filenames are completed, the function tt(_files)

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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