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

PATCH: Tweaking predict-on



If you really want to pound on the completion system, enable predict-on for
a while.  Having completion attempted on every keystroke shows up all kinds
of things; in particular I've gotten the undo system into a very bad state
by cut'n'pasting a function definition during predict-on and then trying to
undo my way out of the resulting chaos.  Not reliably repeatable, though.

I'm wondering if it would be worthwhile for ZLE and completion widgets to
be able to do some sort of FIONREAD test and react differently when there
is typeahead ... it won't work everywhere, but ...

Of course that may go slightly less haywire after this patch, so if you're
interested in debugging "undo" you may want an older predict-on.

This patch changes:

* Remove "emulate -L zsh" for benefit of the completion system.

* Add test of whether we're inside a multi-line buffer, and don't attempt
  predictive typing in that case.

* Reformat a long line.

Index: Functions/Zle/predict-on
===================================================================
@@ -36,10 +36,15 @@
   zle -A .backward-delete-char backward-delete-char
 }
 insert-and-predict () {
-  emulate -L zsh
-  if [[ ${RBUFFER[1]} = ${KEYS[-1]} ]]
+  setopt localoptions noshwordsplit noksharrays
+  if [[ $LBUFFER = *$'\012'* ]]
   then
-    # same as what's typed, just move on
+    # Editing a multiline buffer, it's unlikely prediction is wanted
+    zle .$WIDGET "$@"
+    return
+  elif [[ ${RBUFFER[1]} = ${KEYS[-1]} ]]
+  then
+    # Same as what's typed, just move on
     ((++CURSOR))
   else
     LBUFFER="$LBUFFER$KEYS"
@@ -92,12 +97,15 @@
   return 0
 }
 delete-backward-and-predict() {
-  emulate -L zsh
   if [[ -n "$LBUFFER" ]]
   then
+    setopt localoptions noshwordsplit noksharrays
+    if [[ $LBUFFER = *$'\012'* ]] then
+      # Editing a multiline buffer, it's unlikely prediction is wanted
+      zle .$WIDGET "$@"
     # If the last widget was e.g. a motion, then probably the intent is
     # to actually edit the line, not change the search prefix.
-    if [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) ]]
+    elif [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) ]]
     then
       ((--CURSOR))
       zle .history-beginning-search-forward || RBUFFER=""
@@ -118,7 +126,8 @@
 
 predict-limit-list() {
   if (( compstate[list_lines]+BUFFERLINES > LINES ||
-	( compstate[list_max] != 0 && compstate[nmatches] > compstate[list_max] ) ))
+	( compstate[list_max] != 0 &&
+	    compstate[nmatches] > compstate[list_max] ) ))
   then
     compstate[list]=''
     compstate[force_list]=yes

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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