zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: smart-insert-last-word bug in zsh 5.0.7
Date: Sun, 14 Jun 2015 19:47:16 -0700	[thread overview]
Message-ID: <150614194716.ZM24039@torch.brasslantern.com> (raw)
In-Reply-To: <150613112335.ZM2551@torch.brasslantern.com>

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


      reply	other threads:[~2015-06-15  2:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12  9:16 Vincent Lefevre
2015-06-12 19:12 ` Bart Schaefer
2015-06-13 16:52   ` Peter Stephenson
2015-06-13 18:23     ` Bart Schaefer
2015-06-15  2:47       ` Bart Schaefer [this message]

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=150614194716.ZM24039@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).