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

Re: Weird reset-prompt behavior



2008/8/24 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>:
> On Aug 23, 10:49pm, Björn wrote:
> } Subject: Weird reset-prompt behavior
> }
> } I'm pretty new to zsh so i don't know if this is already known, but i
> } discovered a pretty weird behavior when resetting the prompt and rprompt
>
> To address your specific problem, you shouldn't need zle-line-init at
> all for this.  The editor always starts in the same state with the
> viins keymap, so just set up PROMPT and RPROMPT in your precmd and let
> zle-keymap-select do all the rest of the work.
>
> However, your example does point out a bit of odd behavior.  Ignoring
> zle-keymap-select for the moment, try the following in a new shell.
>
> torch% n=0
> torch% zle-line-init() { RPS1=$[n++]; zle reset-prompt }
> torch% zle -N zle-line-init
> torch%
>
> Hmm.  Why didn't the right prompt appear when the new left prompt was
> printed after creating the widget?  It gets stranger, though; enter
> a command, such as "print $n" (using a 40-column terminal below so as
> to avoid line-wrapping) ...
>
> torch% print $n
> 1
> torch%                                0
>
> Well, OK, n=1 and RPS1=0, which is sort of as expected.  But now it gets
> really strange.  Begin typing anything (I started to type "print" again
> in the cut-and-paste below):
>
> torch% p                              1
>
> RPS1 just belatedly updated itself!  I'm pretty sure zle-line-init was
> not called again here, so there's some kind of delayed reaction (the
> $[n++] did happen when the widget was created, but the display was
> never updated).  Further demonstration, again starting fresh:
>
> torch%  zle-line-init() {
> function> zle -R $SECONDS
> function> PS1="$SECONDS %# "
> function> zle reset-prompt
> function> }
> torch% zle -N zle-line-init
> torch%
> 42
>
> Now start to type anything, and the screen suddenly looks like this:
>
> torch%  zle-line-init() {
> function> zle -R $SECONDS
> function> PS1="$SECONDS %# "
> function> zle reset-prompt
> function> }
> torch% zle -N zle-line-init
> 42 % p
>
> Note the "torch%" prompt has been updated and the "zle -R" output has
> been erased.  (Things are even stranger if I used "zle -M" instead,
> but leave that aside for now.)  Proceeding ...
>
> function> }
> torch% zle -N zle-line-init
> 42 % print $SECONDS
> 156
> 42 %
> 156
>
> This proves that zle-line-init ran when the editor started, but that
> Again start to type ...
>
> 42 % print $SECONDS
> 156
> 156 % p
>
> I almost suspect this is just a matter of a fflush() that hasn't yet
> happened, except for that $[n++] oddity in the very first example.

This may or may not be related, but I have the time in my PS1, and I've
noticed that sometimes the time changes just as I start typing. I have
never been able to discern a pattern though... It was especially annoying
before I switched to 0-padded hours since then it messed up the input line
too somehow I think. I'm not sure if I've noticed it "lately" though, might
have been months.

-- 
Mikael Magnusson


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