Subject: Re: Deliberately abstract question about calling zle widgets
From: Daniel Shahaf <[email-masked]>
To: [email-masked]
Date: Sat, 06 Aug 2016 00:06:36 +0000
List-Id: Zsh Workers List <zsh-workers.zsh.org>

Bart Schaefer wrote on Fri, Aug 05, 2016 at 16:19:37 -0700:
> Ignoring for the moment the pseudo-keymaps that switch on internal thingy
> names of builtin widgets ... can anyone tell me whether the following is
> a true assertion?
> 
>   Given an absence of other user-defined widgets and a function
>     wrap_builtin_widget() { zle .$WIDGET "$@" }
>   then for any (every) builtin widget bltinwid,
>     zle -N bltinwid wrap_builtin_widget
>   has no observable side-effects.
> 

The assertion is false, for two reasons:

1. The function should have been defined with a double-minus guard:
wrap_builtin_widget() { zle .$WIDGET -- "$@" }

2. The wrapper needs to call «zle -f 'yank'» if the wrapped widget has
the ZLE_YANK flag, etc..

> When I say "no side effects" I'm referring to things like loss of suffix
> autoremoval when bltinwid is a completion widget, changed "undo" handling,
> mishandled numeric prefixes, etc.  I'm not looking for obscure ways to
> break it such as aliasing or disabling the zle command.
> 
> If the assertion is known to be false, please name any builtin widgets you
> are aware of for which this assertion does not hold.

Any widget with ZLE_YANK / ZLE_KILL set.  Example:

% bindkey -e
% wrap_builtin_widget() { zle .$WIDGET -- "$@" }
% echo foo bar ^W^W^Y^C
% zle -N backward-kill-word wrap_builtin_widget
% echo foo bar ^W^W^Y^C

> Thanks.
> 

You're welcome. It's being the maintainer of z-sy-h that taught me this
answer.

Cheers,

Daniel