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

Re: A weird smart-insert-last-word bug



On Fri, Nov 2, 2018 at 5:03 PM Wayne Davison <wayne@xxxxxxxxxxxxx> wrote:
>
> I make use of smart-insert-last-word like this:
>
> zlewidget '' insert-last-word smart-insert-last-word

Sorry, what is "zlewidget" exactly?

> Every now and then it destroys some part of the command line when starting
> a new insert sequence.  This seems to be caused by its simple conditional
> at the start of its file being inadequate

Does this help?  (Apologies if lines wrap)

diff --git a/Functions/Zle/smart-insert-last-word
b/Functions/Zle/smart-insert-last-word
index cf8715d..05f23cb 100644
--- a/Functions/Zle/smart-insert-last-word
+++ b/Functions/Zle/smart-insert-last-word
@@ -48,13 +48,14 @@ zle auto-suffix-retain

 # Not strictly necessary:
 # (($+_ilw_hist)) || integer -g _ilw_hist _ilw_count _ilw_cursor
_ilw_lcursor _ilw_changeno
+# (($+_ilw_result)) || typeset -g _ilw_result

 integer cursor=$CURSOR lcursor=$CURSOR
 local lastcmd pattern numeric=$NUMERIC

 # Save state for repeated calls
 if (( HISTNO == _ilw_hist && cursor == _ilw_cursor &&
-      UNDO_CHANGE_NO == _ilw_changeno ))
+      UNDO_CHANGE_NO == _ilw_changeno )) && [[ $BUFFER == $_ilw_result ]]
 then
     NUMERIC=$[_ilw_count+1]
     lcursor=$_ilw_lcursor
@@ -119,7 +120,7 @@ fi
 (( NUMERIC > $#lastcmd )) && return 1

 LBUFFER[lcursor+1,cursor+1]=$lastcmd[-NUMERIC]
-typeset -g _ilw_cursor=$CURSOR
+typeset -g _ilw_cursor=$CURSOR _ilw_result=$BUFFER

 # This is necessary to update UNDO_CHANGE_NO immediately
 zle split-undo && typeset -g _ilw_changeno=$UNDO_CHANGE_NO



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