From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2059 invoked by alias); 20 Jul 2015 09:25:11 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35838 Received: (qmail 28327 invoked from network); 20 Jul 2015 09:25:07 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1437383951; bh=FD9aYEf4f4PoBJRAhfljIYwibg8vrzX5WSxMA5bBUno=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=ptmBcsQOee1jD5HabCIXJnTblsG9rOh5MQHg1EG4Q8RrDmEoOC+zCfMcwu9VTxmVSCLZg59uru6m8e2H3VWk2yiDWwUaj61nJa0lNlOpSM3IeeSZ7KM5UdeHZo2mQJFNSMxcy34y7RlPBv6UStckesOjtafe/CGE79Rm2Z1oQVmNIufDcAcH5k+bf/dIgej7cBiYvPsKF+VtINZm1e0YKmTTCS1jSgdaLLwWwadJO4sY2KeWYEUuVxFCbGnMJ1SWfTj+sm1xAlWdkDYNNyLKjTkj0Fr49Ib+PHeaHDo1Zu/t+3dry0g7qhHgfb5EIfxBvlTQZ1i7HC6ozXTrvD12Lg== X-Yahoo-Newman-Id: 856450.72080.bm@smtp135.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: FJ8AVdMVM1mS2OmVyDGHrBdaa_dbIm4.HumVfh0DNCQc34z UeHFYgX9AIuExE9y3fZWJA0RnLsQiOzb5y6EJWKPbGmB5c1fO_iF6CorZEn4 1U9Hlr9NscWyQLcRpWyOYxjLuRGBsWxc_hnc4mbBLU5kB5ue1Opw53rcJ80g crKPN3DzFqhqG_A1zEF1PaNEw6Zs70oPTGopAjSAysTV5O6PUJhZrxNj_9Yq IwsjAF2axwsItk7a2spFPOWzlWgfbxaEz7kJV6MsGNWKCirQBf4VMHurSl4i 7ga2hGgYKjHeoDfkem2Z0wKi05zNjL5Af2ld.QteRe1WXb5uVbFtADJGZ1P4 h3PgUK0jX1ntV_cM8Sgyk66Sbeym42gfnQLZm6BZ4bw59f5_43QClxawAvS9 GObu01S39XrQP8co5ghR73uuw.LHQEEYQGH4Z8D6qvCOnMEEsNqdK.kwfht7 dvb5Kf0qgZhWGRIjTh9ZfbafjNYnHlDyiybzhdbci37KdetQXtGtnI3n7L27 nrgyH3MLbMEk3cDmzSRf1kEL0xINoTg-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <150719012304.ZM18439@torch.brasslantern.com> From: Oliver Kiddle References: <150620102144.ZM5618@torch.brasslantern.com> <150718164224.ZM4759@torch.brasslantern.com> <19747.1437278114@thecus.kiddle.eu> <150719012304.ZM18439@torch.brasslantern.com> To: zsh workers Subject: Re: PATCH: narrow-to-region (was Re: This widget implementation feels a bit clunky) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9926.1437383950.1@thecus.kiddle.eu> Date: Mon, 20 Jul 2015 11:19:10 +0200 Message-ID: <9927.1437383950@thecus.kiddle.eu> Bart wrote: > } It'd also be good for the function to use the new undo limit features. > > I was going to send a follow-up message about undo-ing and whether a call > to split-undo is needed before (and/or after) the recursive-edit. It is needed immediately after you've setup PREDISPLAY and emptied BUFFER. I would have been fairly sure of that answer but my own attempts to make it work had failed so I went back to see again first. I now realise that the problem I had is elsewhere. I've attached a very rudimentary patch to narrow-to-region. My main use of narrow-to-region is to retrieve history lines into the middle of the current line. And it is just this situation that is breaking it. When doing: zle undo $_ntr_changeno it is falling foul of the first line of unapplychange which is: if(ch->hist != histline) { and not undoing enough changes. This is a consequence of the fix in 10328. If I comment out the two lines of undo() which do else break; it appears to work fine and the problem that 10328 targetted doesn't seem to come back. But it is hard to know how that was failing at the time. > Related, should -S / -R implicitly set undo points? I've never used those two options and am not sure I quite understand what they're for. At least not without digging in the archives. With the patch below, it is fairly obviously broken for them because _ntr_changeno is set in a different block from the one which does zle undo to revert to it. Oliver diff --git a/Functions/Zle/narrow-to-region b/Functions/Zle/narrow-to-region index 293f89b..ae4addd 100644 --- a/Functions/Zle/narrow-to-region +++ b/Functions/Zle/narrow-to-region @@ -29,8 +29,9 @@ emulate -L zsh setopt extendedglob -local _ntr_lbuf_return _ntr_rbuf_return +local _ntr_new_lbuf _ntr_newrbuf _ntr_lbuf_return _ntr_rbuf_return local _ntr_predisplay=$PREDISPLAY _ntr_postdisplay=$POSTDISPLAY +integer _ntr_savelim=$UNDO_LIMIT_NO _ntr_changeno integer _ntr_start _ntr_end _ntr_swap _ntr_cursor=$CURSOR _ntr_mark=$MARK integer _ntr_stat @@ -98,6 +99,7 @@ if [[ -n $_ntr_save || -z $_ntr_restore ]]; then then _ntr_posttext=$_ntr_rbuffer fi + _ntr_changeno=$UNDO_CHANGE_NO PREDISPLAY="$_ntr_predisplay$_ntr_pretext" POSTDISPLAY="$_ntr_posttext$_ntr_postdisplay" @@ -110,16 +112,25 @@ if [[ -n $_ntr_save || -z $_ntr_restore ]]; then BUFFER=${BUFFER[_ntr_start+1,_ntr_end-1]} CURSOR=$_ntr_cursor MARK=$_ntr_mark + zle split-undo fi if [[ -z $_ntr_save && -z $_ntr_restore ]]; then - zle recursive-edit - _ntr_stat=$? - - [[ -n $_ntr_lbuf_return ]] && - builtin typeset -g ${_ntr_lbuf_return}="${LBUFFER}" - [[ -n $_ntr_rbuf_return ]] && - builtin typeset -g ${_ntr_rbuf_return}="${RBUFFER}" + { + UNDO_LIMIT_NO=$UNDO_CHANGE_NO + zle recursive-edit + _ntr_stat=$? + _ntr_newlbuf="$LBUFFER" + _ntr_newrbuf="$RBUFFER" + + [[ -n $_ntr_lbuf_return ]] && + builtin typeset -g ${_ntr_lbuf_return}="${LBUFFER}" + [[ -n $_ntr_rbuf_return ]] && + builtin typeset -g ${_ntr_rbuf_return}="${RBUFFER}" + } always { + zle undo $_ntr_changeno + UNDO_LIMIT_NO=_ntr_savelim + } fi if [[ -n $_ntr_restore || -z $_ntr_save ]]; then @@ -135,8 +146,8 @@ if [[ -n $_ntr_restore || -z $_ntr_save ]]; then PREDISPLAY=$_ntr_predisplay POSTDISPLAY=$_ntr_postdisplay - LBUFFER="$_ntr_lbuffer$BUFFER" - RBUFFER="$_ntr_rbuffer" + LBUFFER="$_ntr_lbuffer$_ntr_newlbuf" + RBUFFER="$_ntr_newrbuf$_ntr_rbuffer" MARK=${#_ntr_lbuffer} fi