zsh-workers
 help / color / mirror / code / Atom feed
* Re:  PATCH: 3.1.5-pws-7++: #key-* style completions
@ 1999-02-15  9:25 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 1999-02-15  9:25 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> I've just noticed a slight problem with rebinding all completion-type key
> bindings to use the new functions, when combined with #key-* bindings: if
> you do (say) ^D, it will always generate the context-dependent list,
> replacing the list you just made with the #key-* function, whereas if ^D
> was bound as originally, it will use an existing completion list.  However,
> that was imperfect because if there was no existing completion list it
> would generate the one according to the old-style compctl's.  So the
> present arrangement is probably better, but not perfect.  Is there some way
> in shell code of making listing functions use an existing completion
> list where there is one (maybe as an option)?

Of course that's because list-choices and d-c-o-l generate the list
themselves, one might argue that the things from a key-bound special
completion aren't really choices.
Anyway, I was already talking about my wish to add some support for
the surroundings of the completion stuff (control the listing
etc.). This sounds like one of the things we might want to add
there. I'm currently too busy with the existing parts of the code to
think about what would be nice to have acces to, though.

But, maybe, some of you want to make suggestions, so that we can
collect a list?

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

* PATCH: 3.1.5-pws-7++: #key-* style completions
@ 1999-02-13 13:06 Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 1999-02-13 13:06 UTC (permalink / raw)
  To: Zsh hackers list

This alters the format of definitions for directly bindable completions via
#key-array or #key-function widgets (for intermittent readers, these
function like the old zle -C widgets I previously introduced) so that the
bindkey string comes last, and there can be zero or more of them.

I've just noticed a slight problem with rebinding all completion-type key
bindings to use the new functions, when combined with #key-* bindings: if
you do (say) ^D, it will always generate the context-dependent list,
replacing the list you just made with the #key-* function, whereas if ^D
was bound as originally, it will use an existing completion list.  However,
that was imperfect because if there was no existing completion list it
would generate the one according to the old-style compctl's.  So the
present arrangement is probably better, but not perfect.  Is there some way
in shell code of making listing functions use an existing completion
list where there is one (maybe as an option)?

--- Misc/Completion/__most_recent_file.bk	Sat Feb 13 13:48:43 1999
+++ Misc/Completion/__most_recent_file	Sat Feb 13 13:49:08 1999
@@ -1,2 +1,2 @@
-#key-array \C-xm expand-or-complete
+#key-array expand-or-complete \C-xm
 __most_recent_file=(-g '*(om[1])')
--- Misc/Completion/init.bk	Sat Feb 13 13:48:48 1999
+++ Misc/Completion/init	Sat Feb 13 13:55:12 1999
@@ -30,17 +30,18 @@
 #   `#pattern-array <pattern>'
 #     like `#pattern-function' but defining an array
 #
-#   `#key-function <key-sequence> <style>
-#     this is used to bind special completions to a <key-sequence>;
-#     the <style> is the name of one of the built-in completion widgets
-#     (complete-word, delete-char-or-list, expand-or-complete,
-#     expand-or-complete-prefix, list-choices, menu-complete,
-#     menu-expand-or-complete, or reverse-menu-complete); this will create
-#     a internal widget and bind the given key-sequence to this widget so
-#     that typing this key-sequence will have the effect of completing
-#     the word on the command line as defined in the file
+#   `#key-function <style> [ <key-sequence> ... ]
+#     this is used to bind special completions to all the given
+#     <key-sequence>(s). The <style> is the name of one of the built-in
+#     completion widgets (complete-word, delete-char-or-list,
+#     expand-or-complete, expand-or-complete-prefix, list-choices,
+#     menu-complete, menu-expand-or-complete, or reverse-menu-complete).
+#     This creates a widget behaving like <style> so that the
+#     completions are chosen as given in the the rest of the file,
+#     rather than by the context.  The widget has the same name as
+#     the autoload file and can be bound using bindkey in the normal way.
 #
-#   `#key-array <key-sequence> <style>
+#   `#key-array <style> [ <key-sequence> ... ]
 #     like `#key-function', but defining an array instead
 #
 #   `#helper'
@@ -108,11 +109,12 @@
 
 
 # This is used to define completion handlers directly bound to keys. The
-# first argument is as for `defcomp', giving the handler. The second argument
-# is a key-sequence usable fo `bindkey'. The third argument is the name of one
-# of the built-in completion widgets. Typing the given key sequence will
-# complete the word the cursor is on according to the completion definition
-# given and will behave as if the built-in completion widget was used.
+# first argument is as for `defcomp', giving the handler. The second
+# argument is the name of one of the built-in completion widgets. Any
+# remaining arguments are used as key sequences to bind the widget.
+# Typing that key sequence will complete the word the cursor is on
+# according to the completion definition given and will behave as if the
+# built-in completion widget was used.
 
 defkeycomp() {
   local name
@@ -126,9 +128,14 @@
   else
     name="$1"
   fi
-  zle -C "$name" "$3" __main_key_complete
-  bindkey "$2" "$name"
   keycomps[$name]="$1"
+  shift
+  zle -C "$name" "$1" __main_key_complete
+  shift
+  while (( $# )); do
+    bindkey "$1" "$name"
+    shift
+  done
 }
 
 # These can be used to easily save and restore the state of the special
@@ -202,25 +209,27 @@
 
 # Now we make the files automatically autoloaded.
 
-local dir file line
+local dir file line func
 
 for dir in $fpath; do
   [[ $dir = . ]] && continue
   for file in $dir/__*~*~(N); do
     read -rA line < $file
-    if [[ $line[1] = '#function' ]]; then
-      defcomp -a ${file:t} "${(@)line[2,-1]}"
-    elif [[ $line[1] = '#array' ]]; then
-      defcomp " $file" "${(@)line[2,-1]}"
-    elif [[ $line[1] = '#pattern-function' ]]; then
-      defpatcomp -a ${file:t} "$line[2]"
-    elif [[ $line[1] = '#pattern-array' ]]; then
-      defcomp " $file" "$line[2]"
-    elif [[ $line[1] = '#key-function' ]]; then
-      defkeycomp -a "${file:t}" "$line[2]" "$line[3]"
-    elif [[ $line[1] = '#key-array' ]]; then
-      defkeycomp " $file" "$line[2]" "$line[3]"
-    elif [[ $line[1] = '#helper' ]]; then
+    func=$line[1]
+    shift line
+    if [[ $func = '#function' ]]; then
+      defcomp -a ${file:t} "${line[@]}"
+    elif [[ $func = '#array' ]]; then
+      defcomp " $file" "${line[@]}"
+    elif [[ $func = '#pattern-function' ]]; then
+      defpatcomp -a ${file:t} "${line[@]}"
+    elif [[ $func = '#pattern-array' ]]; then
+      defcomp " $file" "${line[@]}"
+    elif [[ $func = '#key-function' ]]; then
+      defkeycomp -a "${file:t}" "${line[@]}"
+    elif [[ $func = '#key-array' ]]; then
+      defkeycomp " $file" "${line[@]}"
+    elif [[ $func = '#helper' ]]; then
       autoload ${file:t}
     fi
   done

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-02-15  9:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-15  9:25 PATCH: 3.1.5-pws-7++: #key-* style completions Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1999-02-13 13:06 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).