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

Re: Regression in bracketed-paste-magic (not in 5.2, but affects 5.3's test releases)

Bart wrote:
> This probably indicates a problem with undo-point handling around history
> search, which has been a sticky wicket in the past.  The patch you cite
> replaced b-p-m's internal handling of $BUFFER with reliance on the undo
> mechanism.

In this particular case, the problem is that fc -p doesn't result
in a call to zle's remember_edits(). remember_edits() updates the
table of history entries for the current line. The edit associated
with doing BUFFER= CURSOR=1 is thus lost. So when it does the
undo, the line is first restored when the history line is reselected
and then the contents are duplicated when the effect of clearing
$BUFFER is undone.

Unfortunately, the ZLE_CMD_SET_HIST_LINE callback happens after this
history line is updated so we can't call remember_edits() from there.
We could simply add another similar hook and call it earlier.

What I would suggest for 5.3 is the patch below. fc -p doesn't
trigger handleundo() either so by moving split-undo above the
clearing of the buffer, we ensure that the edit is missed by both
the undo and history. Referencing $UNDO_CHANGE_NO does force
handleundo() so the downside of this is that UNDO_LIMIT_NO will
allow an undo back to the state before clearing $BUFFER.

If you're wondering why I suggest this rather than adding a hook
to call remember_edits(), it is because, for a proper post-5.3
patch, fc -p wouldn't actually change the current history line. The
only thing that changes is the history number. If history internals
use the Histent to identify history entries then undo wouldn't see
fc -p/-P as a change of history line and we could kill the associated
bugs. I've got some unfinished work on this on a git branch if
someone's interested to play with it. But for now, calling fc -p
in a widget is going to get you undo oddities.

I don't use bracketed-paste-magic so would appreciate if someone
else could do some testing and make the call on what should go into


diff --git a/Functions/Zle/bracketed-paste-magic b/Functions/Zle/bracketed-paste-magic
index fb584d5..c3cc8b6 100644
--- a/Functions/Zle/bracketed-paste-magic
+++ b/Functions/Zle/bracketed-paste-magic
@@ -151,10 +151,10 @@ bracketed-paste-magic() {
 	integer bpm_mark=$MARK bpm_region=$REGION_ACTIVE
 	integer bpm_numeric=${NUMERIC:-1}
 	integer bpm_limit=$UNDO_LIMIT_NO bpm_undo=$UNDO_CHANGE_NO
 	zle .split-undo
 	fc -p -a /dev/null 0 0
 	if [[ $bmp_keymap = vicmd ]]; then
 	    zle -K viins

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