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

Re: widget function must have zle codes

On Thu, Aug 17, 2023 at 5:11 PM Budi <budikusasi@xxxxxxxxx> wrote:
> How can;t this work
> a widget function having zle codes

I'm not entirely sure what you're attempting to accomplish here.

> t:1: bad pattern: e[H

You're getting that specific error because you haven't quoted the
string properly, but I don't think it would do what you want anyway.
It looks like you're trying to extrapolate Roman's "bind-x" example to
a case it wasn't meant to cover.  One would not normally create a
widget by assigning to the functions[] array, Roman did that
specifically in order to construct a new function body from the values
in the positional parameters of the "bind-x" function.

Further, it's the "zle -N" command that creates a widget, the function
is the widget implementation.  Neither of them works without the

In ZLE widgets, you don't normally refer to an action by it's key
binding, instead you refer to it by its widget name, and use the "zle"
command to run it.  So instead of $'\e[H' (which would be the correct
quoting you were after), you would write
   zle beginning-of-line
(or whatever action you wanted).  Each built-in widget has a special
name starting with a "." that you can use to avoid calling some
user-defined replacement implementation, so you might see examples
  zle .beginning-of-line

> functions[t]="zle -I; \e[H   2>/dev/null echo Test preceding word"

I can't tell what you're expecting to have happen with that "echo".
If you meant for "Test preceding word" to become part of the line
being edited, you need to assign that to one of the BUFFER, LBUFFER,
or RBUFFER variables (please see the doc).

I strongly suggest you look at some of the examples in Functions/Zle/
in the distribution.  Many are a bit esoteric but most have extensive
explanatory comments.  The easiest to understand might be
Note these files are function bodies only, they expect to be turned
into actual widgets by (for example)
  autoload history-search-end
  Zle -N history-search-end

There's also
but note that its setup commentary forgot to mention the "zle -N vi-pipe" part.

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