Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: smart-insert-last-word bug in zsh 5.0.7



On Jun 13,  5:52pm, Peter Stephenson wrote:
} Subject: Re: smart-insert-last-word bug in zsh 5.0.7
}
} On Fri, 12 Jun 2015 12:12:42 -0700
} Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > Now that we have UNDO_CHANGE_NO, that's probably a better way to track
} > the state, but maybe someone can find a different problem with that?
} 
} I suppose you could do both that and cursor position, but using an
} intervening change seems entirely logical if that becomes the documented way
} of doing it.

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.

OTOH, does anyone recall why we didn't use the typical LASTWIDGET test?

diff --git a/Functions/Zle/smart-insert-last-word b/Functions/Zle/smart-insert-last-word
index 27b0849..5673136 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
@@ -116,4 +119,11 @@ fi
 (( NUMERIC > $#lastcmd )) && return 1
 
 LBUFFER[lcursor+1,cursor+1]=$lastcmd[-NUMERIC]
-_ilw_cursor=$CURSOR
+
+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

-- 
Barton E. Schaefer



Messages sorted by: Reverse Date, Date, Thread, Author