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

Re: New completion - redefine widgets instead of rebinding keys RE: pws-22



Peter Stephenson wrote:
> "Andrej Borsenkow" wrote:
> > Since I've never seen any reply to this, I repeat it here.
> > 
> > My suggestion was, that instead of rebinding keys (as is done currently) we
> > should simply redefine corresponding widgets.
> 
> This certainly looks like a good idea.

I haven't had a problem with this, so here's the diff.  compdef uses the
`.' form of the completion widgets, though after the patch I sent that's no
longer necessary.  Now binding completion keys before or after compinit and
in any keymap will work transparently.

--- Completion/Core/compinit	Wed Jun  9 09:28:57 1999
+++ /home/user2/pws/bin/comp/compinit	Wed Jun 16 18:02:06 1999
@@ -215,7 +215,11 @@
       fi
 
       # Define the widget.
-      zle -C "$func" "$1" "$func"
+      if [[ $1 = .* ]]; then
+	zle -C "$func" "$1" "$func"
+      else
+	zle -C "$func" ".$1" "$func"
+      fi
       shift
 
       # And bind the keys...
@@ -335,6 +339,14 @@
   fi
 fi
 
+
+# Rebind the standard widgets
+for _i_line in complete-word delete-char-or-list expand-or-complete \
+  expand-or-complete-prefix list-choices menu-complete \
+  menu-expand-or-complete reverse-menu-complete; do
+  zle -C $_i_line .$_i_line _main_complete
+done
+
 _i_done=''
 
 # If we have a dump file, load it.
@@ -368,23 +380,6 @@
       esac
     done
   done
-
-  bindkey |
-    while read -rA _i_line; do
-      case "$_i_line[2]" in
-      (complete-word) ;&
-      (delete-char-or-list) ;&
-      (expand-or-complete) ;&
-      (expand-or-complete-prefix) ;&
-      (list-choices) ;&
-      (menu-complete) ;&
-      (menu-expand-or-complete) ;&
-      (reverse-menu-complete)
-	zle -C _complete_$_i_line[2] $_i_line[2] _main_complete
-	bindkey "${_i_line[1][2,-2]}" _complete_$_i_line[2]
-	;;
-      esac
-    done
 
   unset _i_dir _i_line _i_file _i_tag
 
--- Completion/Core/compdump	Wed Jun  9 09:28:56 1999
+++ /home/user2/pws/bin/comp/compdump	Wed Jun 16 18:03:08 1999
@@ -44,11 +44,13 @@
 # Now dump the key bindings. We dump all bindings for zle widgets
 # whose names start with a underscore.
 # We need both the zle -C's and the bindkey's to recreate.
+# We can ignore any zle -C which rebinds a standard widget (second
+# argument to zle does not begin with a `_').
 
 _d_bks=()
 zle -lL |
   while read -rA _d_line; do
-    if [[ ${_d_line[5]} = _* ]]; then
+    if [[ ${_d_line[3]} = _* && ${_d_line[5]} = _* ]]; then
       print -r - ${_d_line}
       _d_bks=($_d_bks ${_d_line[3]})
     fi
--- Doc/Zsh/compsys.yo.bak	Thu Jun 17 14:01:38 1999
+++ Doc/Zsh/compsys.yo	Fri Jun 18 16:53:11 1999
@@ -59,6 +59,8 @@
 start and finish), you can rerun tt(compinstall) and it will correctly
 locate and modify these lines.  Note, however, that any code you add to
 this section by hand is likely to be lost if you rerun tt(compinstall).
+The new code will take effect next time you start the shell, or run
+tt(.zshrc) by hand.
 
 You can run it as `tt(source )var(<path>)tt(/compinstall)' or
 `tt(. )var(<path>)tt(/compinstall)', where var(<path>) is where the
@@ -72,6 +74,11 @@
 
 You can abort the installation any time you are being prompted for
 information, and your tt(.zshrc) will not be altered at all.
+
+After initialization all the builtin completion widgets such as
+tt(expand-or-complete) will be redefined to use the new completion system.
+Should you need to, you can still bind keys to the old functions by putting
+a `tt(.)' in front, e.g. `tt(.expand-or-complete)'.
 
 subsect(Use of compinit)
 

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



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