zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: PATCH: Re: Undo and narrow-to-region (was ...)
Date: Mon, 17 Aug 2015 20:43:02 -0700	[thread overview]
Message-ID: <150817204302.ZM28285@torch.brasslantern.com> (raw)
In-Reply-To: <150817145829.ZM27968@torch.brasslantern.com>

On Aug 17,  2:58pm, I wrote:
}
} Oliver may not be able to get to this for a while.  Is it possible for
} you to try reverting just the change to the narrow-to-region shell code
} and see if that fixes things, or if both the shell and C code changes
} need to be reverted?

I was able to reproduce the broken behavior with 832130c and then back
that out to determine that Daniel's example works correctly with the
previous version of narrow-to-region.

Oliver said:
> This is still not perfect with history changes.

In fact it's actually horribly broken with respect to history changes,
at least with -R / -S, as far as I can tell ...

In Daniel's example, we start with BUFFER='', record $UNDO_CHANGE_NO,
wander about in the history a bit, then do "zle undo $_ntr_changeno"
with the expectation that will return us to the previous state, that
is, an empty BUFFER.  But it doesn't.

It mostly works as long as BUFFER isn't empty when $UNDO_CHANGE_NO is
saved.  This goes back to Oliver's grumbling that undo decides what to
do based on whether the text on the line matches the text at the undo
point,  In this case there is no text at the undo point, so anything
will match and nothing gets undone.

The following brute-forces the history back to the same line where the
undo point was set before performing the undo.  This works for Daniel's
example but I have no idea what it will do for other cases.  It can't
make things any worse, in theory.


diff --git a/Functions/Zle/narrow-to-region b/Functions/Zle/narrow-to-region
index 0ef28a8..261d821 100644
--- a/Functions/Zle/narrow-to-region
+++ b/Functions/Zle/narrow-to-region
@@ -32,7 +32,7 @@ setopt localoptions noshwordsplit noksharrays
 
 local _ntr_newbuf _ntr_lbuf_return _ntr_rbuf_return
 local _ntr_predisplay=$PREDISPLAY _ntr_postdisplay=$POSTDISPLAY
-integer _ntr_savelim=UNDO_LIMIT_NO _ntr_changeno
+integer _ntr_savelim=UNDO_LIMIT_NO _ntr_changeno _ntr_histno=HISTNO
 integer _ntr_start _ntr_end _ntr_swap _ntr_cursor=$CURSOR _ntr_mark=$MARK
 integer _ntr_stat
 
@@ -108,7 +108,7 @@ if [[ -n $_ntr_save || -z $_ntr_restore ]]; then
     builtin typeset -ga $_ntr_save
     set -A $_ntr_save "${_ntr_predisplay}" "${_ntr_postdisplay}" \
 	"${_ntr_savelim}" "${_ntr_changeno}" \
-	"${_ntr_start}" "${_ntr_end}" || return 1
+	"${_ntr_start}" "${_ntr_end}" "${_ntr_histno}" || return 1
   fi
 
   BUFFER=${BUFFER[_ntr_start+1,_ntr_end]}
@@ -135,13 +135,15 @@ if [[ -n $_ntr_restore || -z $_ntr_save ]]; then
 	   _ntr_savelim="${${(@P)_ntr_restore}[3]}"
 	   _ntr_changeno="${${(@P)_ntr_restore}[4]}"
 	   _ntr_start="${${(@P)_ntr_restore}[5]}"
-	   _ntr_end="${${(@P)_ntr_restore}[6]}" }; then
+	   _ntr_end="${${(@P)_ntr_restore}[6]}"
+	   _ntr_histno="${${(@P)_ntr_restore}[7]}" }; then
       zle -M Failed. >&2
       return 1
     fi
   fi
 
   _ntr_newbuf="$BUFFER"
+  HISTNO=_ntr_histno
   zle undo $_ntr_changeno
   PREDISPLAY=$_ntr_predisplay
   POSTDISPLAY=$_ntr_postdisplay

-- 
Barton E. Schaefer


  reply	other threads:[~2015-08-18  3:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-20  9:16 This widget implementation feels a bit clunky (edit-quoted-word) Mikael Magnusson
2015-06-20 17:06 ` Peter Stephenson
2015-06-21  7:09   ` Mikael Magnusson
2015-06-21 17:17     ` Peter Stephenson
2015-06-22  2:26       ` Mikael Magnusson
2015-06-22  0:18     ` PATCH: Document narrow-to-region -l and -r Mikael Magnusson
2015-06-20 17:21 ` This widget implementation feels a bit clunky (edit-quoted-word) Bart Schaefer
2015-07-18 23:42   ` PATCH: narrow-to-region (was Re: This widget implementation feels a bit clunky) Bart Schaefer
2015-07-19  3:55     ` Oliver Kiddle
2015-07-19  8:23       ` Bart Schaefer
2015-07-20  9:19         ` Oliver Kiddle
2015-07-20 16:29           ` Bart Schaefer
2015-07-23  5:41           ` Undo and narrow-to-region (was Re: PATCH: narrow-to-region (was ...)) Bart Schaefer
2015-07-27 15:44             ` Oliver Kiddle
2015-08-12 17:00               ` PATCH: Re: Undo and narrow-to-region (was ...) Oliver Kiddle
2015-08-17 21:15                 ` Daniel Hahler
2015-08-17 21:58                   ` Bart Schaefer
2015-08-18  3:43                     ` Bart Schaefer [this message]
2015-08-18  7:05                   ` 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=150817204302.ZM28285@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).