zsh-workers
 help / color / mirror / code / Atom feed
* A weird smart-insert-last-word bug
@ 2018-11-03  0:03 Wayne Davison
  2018-11-03  0:37 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Wayne Davison @ 2018-11-03  0:03 UTC (permalink / raw)
  To: Zsh list

[-- Attachment #1: Type: text/plain, Size: 1381 bytes --]

Here's something I've seen very sporadically but I couldn't work out a test
case before today.
I make use of smart-insert-last-word like this:

zlewidget '' insert-last-word smart-insert-last-word
zstyle :insert-last-word match '[^,]??*'
zstyle :insert-last-word auto-previous 1

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 to know when it is really
continuing:

if (( HISTNO == _ilw_hist && cursor == _ilw_cursor &&
UNDO_CHANGE_NO == _ilw_changeno ))

Since I have hist_ignore_space set, this makes it possible to trigger the
bug on successive command lines when typing a series of commands that begin
with a space.  Imagine that the underscore char is a leading space:

echo foo
echo bar
_echo <Esc>.
_echo <Esc>.<Esc>.
testing12<Esc>.

at that point the command buffer will be "testinfoo".  Note that it took 2
space-starting commands to be able to trigger the bug on a successive
command-line and that the column has to line up with the column where it
left off on the prior line.

The bug can also happen during an edit on a single line if you initiate the
function a second time from the column where it left off, even though some
editing has happened in between. For example:

echo <Esc>.<Bksp><Bksp><Bksp>bug<Esc>.

..wayne..

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: A weird smart-insert-last-word bug
  2018-11-03  0:03 A weird smart-insert-last-word bug Wayne Davison
@ 2018-11-03  0:37 ` Bart Schaefer
  2018-11-08  1:58   ` Wayne Davison
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2018-11-03  0:37 UTC (permalink / raw)
  To: wayne; +Cc: zsh-workers

On Fri, Nov 2, 2018 at 5:03 PM Wayne Davison <wayne@opencoder.net> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: A weird smart-insert-last-word bug
  2018-11-03  0:37 ` Bart Schaefer
@ 2018-11-08  1:58   ` Wayne Davison
  0 siblings, 0 replies; 3+ messages in thread
From: Wayne Davison @ 2018-11-08  1:58 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh list

[-- Attachment #1: Type: text/plain, Size: 816 bytes --]

On Fri, Nov 2, 2018 at 5:37 PM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> Sorry, what is "zlewidget" exactly?
>

Oops. I got it from Peter a long time ago:
https://www.zsh.org/mla/users/2014/msg00270.html

My version has been modified to allow an empty KEY value to be able to
avoid the bindkey at the end:

function zlewidget # KEY WIDGET [FUNCTION]
{
    # bindkey KEY to new WIDGET, possibly implemented by optional FUNCTION.
    # FUNCTION defaults to WIDGET and will be marked for autoload -Uz.
    # If KEY is an empty string, the bindkey call is skipped.
    local key=$1
    local widget=$2
    local func=${3:-$2}

    autoload -Uz $func
    zle -N $widget $func
    [[ -z $key ]] || bindkey $key $widget
}

Does this help? [... patch elided ...]
>

Yup, that works well for me. Thanks!

..wayne..

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-08  2:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-03  0:03 A weird smart-insert-last-word bug Wayne Davison
2018-11-03  0:37 ` Bart Schaefer
2018-11-08  1:58   ` Wayne Davison

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).