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

Very odd behaviour with zsh, maybe corruption bug



Hi,

Seeing Bart's suggestion to Oliver Kiddle about the use of
history-beginning-search-backward/up-line-or-history, I decided that was
nearly what I wanted, so decided to fiddle with it until it was exactly
what I wanted. Anyhow, it essentially works except that a condition which
should evaluate to true is sometimes returning false for no reason I can
figure.

I'm using zsh-4.1.0-dev-2, and I can reproduce this with zsh -f. It is
however not completely reproducible in that it appears to involve some kind
of random effect/corruption so it needs a few goes before it happens. I'm
using Zsh on:
SunOS gdd-odybin2 5.6 Generic_105181-28 sun4u sparc
SUNW,Ultra-Enterprise-10000

First extract this into a file:

=== START bizzarre.sh
_up_fn() {
  if [[ $LBUFFER == *$'\n'* ]]
  then
    _searching=''
    zle .up-line-or-history
  else
    _searching=$WIDGET
    zle .history-beginning-search-backward
  fi
}

_down_fn() {
  setopt local_options
  set -x
  if [[ ${LASTWIDGET} == ${_searching} ]]
  then
    _searching=$WIDGET
    zle .history-beginning-search-forward
  else
    if [[ $RBUFFER == *$'\n'* ]]
    then
      _searching=''
      zle .down-line-or-history
    else
      _searching=$WIDGET
      zle .history-beginning-search-forward
    fi
  fi
}

zle -N new-up _up_fn
zle -N new-down _down_fn

bindkey "^[[A" new-up
bindkey "^[[B" new-down
=== END

Then execute as here:

% zsh -f
gdd-odybin2% . ./bizzarre.sh
gdd-odybin2% "abc
dquote> def"
zsh: command not found: abc\ndef
gdd-odybin2%

Now if I type a single " and play around with using the four cursor keys
trying to use the history matching & down, after a couple of minutes I can
be pretty sure it will have gone wrong. (Sometimes I ctrl-c or press enter
and try again - don't know if that matters.) Once it has gone wrong it
appears to continually go wrong until the down function is re-defined
(that's the minimum it seems to need to 'reset' it). Due to the 'set -x'
you'll get a messed up screen display, but just try and ignore that!

The 'gone wrong' is where the following line returns false even though both
variables are the same (you can see because of the 'set -x' I added - this
was only added for debugging, and isn't needed to make it go wrong).
--->  if [[ ${LASTWIDGET} == ${_searching} ]]

Here is an example trace where it has gone wrong (once the bug had been
'activated' I just pressed up followed by down to get this):

gdd-odybin2% +_down_fn:3> [[ new-up == new-up ]]
+_down_fn:8> [[ "abc
def" == *
* ]]
+_down_fn:10> _searching=
+_down_fn:11> zle .down-line-or-history

gdd-odybin2%

As far as I can analyse these variables they are exactly the same, as it
appears in the listing, and this first condition should return true, but is
actually giving false. Please tell me if I'm doing something obviously
stupid, its by far the easist solution. ;)

Cheers,

Martin.




This e-mail message is CONFIDENTIAL and may contain legally privileged
information.  If you are not the intended recipient you should not  read,
copy, distribute, disclose or otherwise use the information in this e-mail.
Please also telephone or fax us immediately and delete the message from
your system.  E-mail may be susceptible to data corruption, interception
and unauthorised amendment, and we do not accept liability for any such
corruption, interception or amendment or the consequences thereof.



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