From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6419 invoked by alias); 15 Jun 2015 02:47:27 -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: 35469 Received: (qmail 679 invoked from network); 15 Jun 2015 02:47:24 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=RGZmnHhIfUTnafYNIj/7rNnUWX4wqXgR9vc+GDeldBk=; b=P637kOMzsmHbJ1svWOeFbp+UyT9HgE0pq8ruvRdkQR/4LajIy0RnYyrIexqExHKAYn wNAZPmGRp6CL8UPcX9S9eB2nmCmirA0uw7SCt6d3qUAaMw4hpJIVVpXPxdolbwbKBujb s7TMJNGPRVO13FACQgRw3hLvjGxCrChbaDzdIKAC3tl8OKG1SpPJrdKOHgzTDKgmVCA/ DYShzH0tqu4EBavghpiW9KczmouFAmUIFPjPSK8B6BDauPa4StwmW9O+uWv6rlkNxPb3 M40YPRAbPSeQGtThL5s1E3nyEmPKidzLnwH6seEdmUqngrIj4JvL9nqxQP/JiPPranAK CuCQ== X-Gm-Message-State: ALoCoQksR0CEE/J5czhmQsET4LzVxbt4MR2o+e9v9LET6cS+/QqWagJ8DLe+DH2wXhH8z3MK/K6k X-Received: by 10.60.34.74 with SMTP id x10mr21663993oei.4.1434336440424; Sun, 14 Jun 2015 19:47:20 -0700 (PDT) From: Bart Schaefer Message-Id: <150614194716.ZM24039@torch.brasslantern.com> Date: Sun, 14 Jun 2015 19:47:16 -0700 In-Reply-To: <150613112335.ZM2551@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: smart-insert-last-word bug in zsh 5.0.7" (Jun 13, 11:23am) References: <20150612091627.GA10815@ypig.lip.ens-lyon.fr> <150612121242.ZM789@torch.brasslantern.com> <20150613175200.0de7319f@ntlworld.com> <150613112335.ZM2551@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: smart-insert-last-word bug in zsh 5.0.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jun 13, 11:23am, Bart Schaefer wrote: } } After further testing, the change number doesn't quite work because it's } not updated soon enough -- the value saved at the end is never the same } as the new value on re-entry. Also, executing "zle undo" doesn't alter } UNDO_CHANGE_NO. So probably some test of both is necessary. Alas, this is still not sufficient. The ugly bit is here: } +if (( _ilw_cursor != CURSOR )) } +then } + _ilw_cursor=$CURSOR } + } + # UNDO_CHANGE_NO increments after we return, but why by two? } + _ilw_changeno=$((UNDO_CHANGE_NO+2)) } +fi If two consecutive last words have the same number of characters, _ilw_cursor == CURSOR and then _ilw_changeno is not updated. But if _ilw_changeno is updated unconditionally, then it becomes wrong if UNDO_CHANGE_NO is not incremented, which might happen if two consecutive last words are the same string (a replacement of a string by itself is not treated as an undo-able change). The answer seems to be to force an undo point with split-undo. diff --git a/Functions/Zle/smart-insert-last-word b/Functions/Zle/smart-insert-last-word index 27b0849..67adea7 100644 --- a/Functions/Zle/smart-insert-last-word +++ b/Functions/Zle/smart-insert-last-word @@ -47,13 +47,15 @@ setopt extendedglob nohistignoredups zle auto-suffix-retain # Not strictly necessary: -# (($+_ilw_hist)) || integer -g _ilw_hist _ilw_count _ilw_cursor _ilw_lcursor +# (($+_ilw_hist)) || integer -g _ilw_hist _ilw_count _ilw_cursor _ilw_lcursor _ilw_changeno integer cursor=$CURSOR lcursor=$CURSOR local lastcmd pattern numeric=$NUMERIC # Save state for repeated calls -if (( HISTNO == _ilw_hist && cursor == _ilw_cursor )); then +if (( HISTNO == _ilw_hist && cursor == _ilw_cursor && + UNDO_CHANGE_NO == _ilw_changeno )) +then NUMERIC=$[_ilw_count+1] lcursor=$_ilw_lcursor else @@ -61,7 +63,8 @@ else _ilw_lcursor=$lcursor fi # Handle the up to three arguments of .insert-last-word -if (( $+1 )); then +if (( $+1 )) +then if (( $+3 )); then ((NUMERIC = -($1))) else @@ -117,3 +120,6 @@ fi LBUFFER[lcursor+1,cursor+1]=$lastcmd[-NUMERIC] _ilw_cursor=$CURSOR + +# This is necessary to update UNDO_CHANGE_NO immediately +zle split-undo && _ilw_changeno=$UNDO_CHANGE_NO