zsh-users
 help / color / mirror / code / Atom feed
* Problem with 'predict-on'
@ 2004-03-24  4:18 Thorsten Kampe
  2004-03-24 16:45 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Kampe @ 2004-03-24  4:18 UTC (permalink / raw)
  To: zsh-users

Hi zsh-users,

I'm testing the ZLE widget "predict-on" with...

autoload -U predict-on; predict-on
zle -N predict-on
zle -N predict-off
bindkey '^X^Z' predict-on
bindkey '^Z'   predict-off
zstyle ':predict' verbose 1

This means that predict-on is active by default. But there are some
flaws with predict-on: first of all I can not backspace the first
character I typed in the command line. Then pasting text via
[Shift]-[Ins] doesn't turn off prediction (like it should[1]).

So I RTFMed and chose "toggle"[2]: "zstyle ':predict' toggle 1".
But when I write this in my .zshrc, predict-on is automatically "off"
(although "toggle"'s conditions for "toggling" aren't met: "when
editing a multi-line buffer or after moving into the middle of a line
and then deleting a character").

So my question is: how can I turn on "predict-on" by default and
circumvent its negative circumstances when pasting text (and maybe
others I haven't discovered yet)?


Thorsten

[1] "Editing a multiline buffer or pasting in a chunk of text; it's
unlikely prediction is wanted"  --  functions/predict-on

[2] used by predict-on [...] in the context ':predict'. If set to
[...] 'true', predictive typing is automatically toggled off in
situations where it is unlikely to be useful, such as when editing a
multi-line buffer or after moving into the middle of a line and then
deleting a character.


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

* Re: Problem with 'predict-on'
  2004-03-24  4:18 Problem with 'predict-on' Thorsten Kampe
@ 2004-03-24 16:45 ` Bart Schaefer
  2004-03-24 20:25   ` Thorsten Kampe
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2004-03-24 16:45 UTC (permalink / raw)
  To: zsh-users

On Mar 24,  5:18am, Thorsten Kampe wrote:
} 
} I'm testing the ZLE widget "predict-on" with...

predict-on is probably due for an overhaul.  It was written for 3.1.x
(I've forgotten which value of 'x') and only updated once about a year
ago.

} autoload -U predict-on; predict-on

} This means that predict-on is active by default.

Actually a better way to accomplish this is

zle-line-init() { predict-on }
zle -N zle-line-init

Calling predict-on in .zshrc means it's on for the very first prompt,
but zle-line-init makes sure it's on at the beginning of every prompt.

Ideally, predict-on would give an error if it is called anywhere other
than in a widget, but the zle-line-init special widget didn't exist
when predict-on was created.

} But there are some flaws with predict-on:

Yes, several.  You'll also notice that it doesn't interact very well
with "undo".  (PWS or Wayne, if you're reading this, advice on how to
fix that would be appreciated.)

I've also just noticed a new problem with backspacing, one which I'm
quite sure has appeared quite recently ... I'm reporting that in another
message to zsh-workers right now.

} first of all I can not backspace the first
} character I typed in the command line.

Yes, that's true.  If there isn't at least one character, there's no
basis for predictive typing.  So the choices would be to delete the
entire line when the first character is deleted, or ... I'm not sure
what.  If "delete the entire line" seems like the right thing, try
this patch:

Index: predict-on
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Functions/Zle/predict-on,v
retrieving revision 1.2
diff -c -r1.2 predict-on
--- predict-on	15 Mar 2003 17:43:15 -0000	1.2
+++ predict-on	24 Mar 2004 16:08:52 -0000
@@ -120,6 +120,8 @@
       zle .history-beginning-search-forward || RBUFFER=""
       return 0
     fi
+  else
+    zle .kill-whole-line
   fi
 }
 delete-no-predict() {

However, that may not be very helpful until the history-search bug gets
fixed.

} Then pasting text via
} [Shift]-[Ins] doesn't turn off prediction (like it should[1]).

This probably means that ((PENDING)) doesn't work correctly on your
system, or that the implemention of Shift+Ins is such that the pasted
text does not appear as typeahead.

PENDING (integer)
     The number of bytes pending for input, i.e. the number of bytes
     which have already been typed and can immediately be read. On
     systems where the shell is not able to get this information, this
     parameter will always have a value of zero.  Read-only.

Unfortunately if insert-and-predict can't determine that there is more
than a single character being inserted, it doesn't know that a paste is
happening, and so doesn't turn itself off.


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

* Re: Problem with 'predict-on'
  2004-03-24 16:45 ` Bart Schaefer
@ 2004-03-24 20:25   ` Thorsten Kampe
  2004-03-25  3:17     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Kampe @ 2004-03-24 20:25 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer (2004-03-24 17:45 +0100)
> On Mar 24,  5:18am, Thorsten Kampe wrote:
> } I'm testing the ZLE widget "predict-on" with...
> 
> predict-on is probably due for an overhaul.  It was written for 3.1.x
> (I've forgotten which value of 'x') and only updated once about a year
> ago.
> 
> } autoload -U predict-on; predict-on
> 
> } This means that predict-on is active by default.
> 
> Actually a better way to accomplish this is
> 
> zle-line-init() { predict-on }
> zle -N zle-line-init
> 
> Calling predict-on in .zshrc means it's on for the very first prompt,
> but zle-line-init makes sure it's on at the beginning of every prompt.

It works in 4.2 (but not 4.1.X). And the problems with pasting seem to
be only a problem with the 4.1 Cygwin zsh and not my 4.2.0 Linux zsh.

But I think the real culprit is *toggle*. It should turn off
predict-on when predict-on doesn't make sense. But toggle turns off
predict-on as soon as I type my first character (and that *really*
doesn't make sense)

Thanks, Thorsten

[1]
autoload -U predict-on; predict-on

zle-line-init() { predict-on }
zle -N zle-line-init

zle -N predict-on
zle -N predict-off

bindkey '^Z'   predict-on
bindkey '^X^Z' predict-off

zstyle ':predict' toggle true
zstyle ':predict' verbose true


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

* Re: Problem with 'predict-on'
  2004-03-24 20:25   ` Thorsten Kampe
@ 2004-03-25  3:17     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2004-03-25  3:17 UTC (permalink / raw)
  To: zsh-users

On Mar 24,  9:25pm, Thorsten Kampe wrote:
}
} * Bart Schaefer (2004-03-24 17:45 +0100)
} 
} But I think the real culprit is *toggle*. It should turn off
} predict-on when predict-on doesn't make sense. But toggle turns off
} predict-on as soon as I type my first character (and that *really*
} doesn't make sense)

Hmm.  Try this:

Index: Functions/Zle/predict-on
===================================================================
retrieving revision 1.2
diff -c -r1.2 predict-on
--- predict-on	15 Mar 2003 17:43:15 -0000	1.2
+++ predict-on	25 Mar 2004 03:16:14 -0000
@@ -56,7 +56,7 @@
   else
     LBUFFER="$LBUFFER$KEYS"
     if [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) ||
-	  $LASTWIDGET == (complete-word|accept-*|predict-*) ]]
+	  $LASTWIDGET == (complete-word|accept-*|predict-*|zle-line-init) ]]
     then
       if ! zle .history-beginning-search-backward
       then

Hey, PWS!  I think zle-line-init should not put itself in LASTWIDGET.


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

end of thread, other threads:[~2004-03-25  3:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-24  4:18 Problem with 'predict-on' Thorsten Kampe
2004-03-24 16:45 ` Bart Schaefer
2004-03-24 20:25   ` Thorsten Kampe
2004-03-25  3:17     ` Bart Schaefer

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).