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

PATCH: Re: General comments on completion



Andrej Borsenkow wrote:

> Is it possible to insert prefix but still do not exit the current completion
> "session"? So, that the list that was generated first is used also for possible
> menu completion? I tried _oldlist - but it does not seem to work (this is with
> modified _match that always inserts prefix):

This adds the assoc array _lastcomp which is used by _main_complete to 
store information about the last completion.

Then I enhanced _oldlist a bit: the oldlist_list key may be set to the 
name of a completer function and if we encounter an old list generated 
by that completer, oldlist makes this list be used independent of the
widget currently used. Maybe we should use a different config key for
this -- if you are using _oldlist and find some strange behavior, tell 
me.

With that one can set match_insert=unambig and oldlist_list=_match to
get the behavior described by Andrej -- a list generated by _match
will be re-used.

Since I'm planning to give incremental-complete-word some more support 
in the future, I wanted to add some code to make information about the 
last completion globally available anyway and it may also become
useful in other places, I think.

Bye
 Sven

diff -u -r oc/Core/_main_complete Completion/Core/_main_complete
--- oc/Core/_main_complete	Wed Jul  7 08:50:57 1999
+++ Completion/Core/_main_complete	Thu Jul  8 09:52:42 1999
@@ -33,7 +33,7 @@
 # state than the global one for which you are completing.
 
 
-local comp
+local comp ret=1
 
 setopt localoptions nullglob rcexpandparam
 unsetopt markdirs globsubst shwordsplit nounset ksharrays
@@ -54,5 +54,19 @@
 # And now just call the completer functions defined.
 
 for comp; do
-  "$comp" && return
+  if "$comp"; then
+    ret=0
+    break;
+  fi
 done
+
+_lastcomp=( "${(@kv)compstate}" )
+_lastcomp[completer]="$comp"
+_lastcomp[prefix]="$PREFIX"
+_lastcomp[suffix]="$SUFFIX"
+_lastcomp[iprefix]="$IPREFIX"
+_lastcomp[isuffix]="$ISUFFIX"
+_lastcomp[qiprefix]="$QIPREFIX"
+_lastcomp[qisuffix]="$QISUFFIX"
+
+return ret
diff -u -r oc/Core/_match Completion/Core/_match
--- oc/Core/_match	Wed Jul  7 08:50:57 1999
+++ Completion/Core/_match	Thu Jul  8 08:58:03 1999
@@ -60,7 +60,7 @@
 compstate[pattern_match]="$opm"
 compstate[matcher]="$compstate[total_matchers]"
 
-[[ ret -eq 0 && "$compconfig[match_insert]" = unambig* &&
+[[ ret -eq 1 && "$compconfig[match_insert]" = unambig* &&
    $#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] && 
     compstate[pattern_insert]=unambiguous
 
diff -u -r oc/Core/_oldlist Completion/Core/_oldlist
--- oc/Core/_oldlist	Wed Jul  7 08:50:57 1999
+++ Completion/Core/_oldlist	Thu Jul  8 09:02:18 1999
@@ -4,10 +4,13 @@
 # and either the compconfig key oldlist_list is `always', or it is not `never'
 # and the list is not already shown, then use the existing list for listing
 # (even if it was generated by another widget).
+# Do this also if there is an old list and it was generated by the
+# completer named by the oldlist_list key.
 if [[ -n $compstate[old_list] && $compconfig[oldlist_list] != never &&
-  $WIDGET = *list* &&
-  ( $compconfig[oldlist_list] = always || $compstate[old_list] != shown ) ]]
-then
+      ( ( $WIDGET = *list* &&
+          ( $compconfig[oldlist_list] = always ||
+            $compstate[old_list] != shown ) ) ||
+        $compconfig[oldlist_list] = *${_lastcomp[completer]}* ) ]]; then
   compstate[old_list]=keep
   return 0
 fi
diff -u -r oc/Core/compinit Completion/Core/compinit
--- oc/Core/compinit	Wed Jul  7 08:50:58 1999
+++ Completion/Core/compinit	Thu Jul  8 08:59:32 1999
@@ -73,6 +73,11 @@
 typeset -gA _comps
 _patcomps=()
 
+# The associative array use to report information about the last
+# cmpletion to the outside.
+
+typeset -gA _lastcomp
+
 # This is the associative array used for configuration.
 
 typeset -gA compconfig

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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