zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zhiming Wang <zmwangx@gmail.com>, Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Regression in bracketed-paste-magic (not in 5.2, but affects 5.3's test releases)
Date: Wed, 07 Dec 2016 13:39:51 +0100	[thread overview]
Message-ID: <13854.1481114391@hydra.kiddle.eu> (raw)
In-Reply-To: <CAH+w=7ZbZdfN7rhXQ-yi4_kqyjyAv1w8B7hKi55TPEBnc5Yfvg@mail.gmail.com>

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

Oliver

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
-	BUFFER=
-	CURSOR=1
 	zle .split-undo
 	UNDO_LIMIT_NO=$UNDO_CHANGE_NO
+	BUFFER=
+	CURSOR=1
 	fc -p -a /dev/null 0 0
 	if [[ $bmp_keymap = vicmd ]]; then
 	    zle -K viins


  parent reply	other threads:[~2016-12-07 12:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07  2:57 Zhiming Wang
2016-12-07  3:25 ` Bart Schaefer
2016-12-07  4:02   ` Zhiming Wang
2016-12-07 12:39   ` Oliver Kiddle [this message]
2016-12-07 18:23     ` Zhiming Wang
2016-12-24  8:28     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=13854.1481114391@hydra.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zmwangx@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).