Subject: Re: Bug in undo/redo handling in conjunction with history-beginning-search-backward
From: Bart Schaefer <[email-masked]>
To: zsh workers <[email-masked]>
Date: Thu, 2 Jun 2016 15:09:18 -0700
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Jun 2,  5:12pm, Oliver Kiddle wrote:
}
} bracketed-paste-magic does fc -p which invalidates HISTNO.
} 
} So one undo blanks the whole line; a second undo tries to move to
} history line 0 - which fails.

Oof.

} fc -p/-P are not part of zle so don't save histline. This also explains
} why change 8 has a history line of 803 instead of 804. Use of fc -p
} within zle appears to be unique to bracketed-paste-magic.

Functions/Misc/sticky-note also uses it within ZLE, and has for years.

} What is the
} reason for using it? Are you trying to block history widgets even where
} they are listed in active-widgets?

That's the reason in bracketed-paste-magic; in sticky-note it differs.
History motions should be able to move around within the pasted text
(up-line-or-history) but not out of the paste into the actual history.

In sticky-note, an alternate history is substituted and the intention
is to let you move around and interact within it.

} So does anyone have any thoughts on how to handle this. The simplest is
} for fc -p/-P to detect zle being active and print an error.

That would be unfortunate.

} Perhaps we need some module callbacks for pushing and popping history.
} Zle would hook the callback, save histline and somehow mark this in
} the undo structure.

Either that, or perhaps there's some way for undo to detect that the
history has changed since the last time an undo point was recorded?
I'm not familiar with how the history push/pop works internally.

} I attach a patch to the state saving and restoring in
} bracketed-paste-magic. Don't expect this to fix anything. I did it to
} make things easier to understand. Was there a reason for half the state
} saving/restoring to be outside the if statement?

Basically (a) I first implemented it without using split-undo and (b) I
didn't trust undo to save and restore everything correctly for the context
needed by the paste-finish functions.