zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Budi <budikusasi@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: widget function must have zle codes
Date: Thu, 17 Aug 2023 18:07:28 -0700	[thread overview]
Message-ID: <CAH+w=7aORtEenabc4-zk6q4zhymtL-xzaK+QVXTTzMLeqfWTQA@mail.gmail.com> (raw)
In-Reply-To: <CAH0GyZDVjXS-PXxxV3C458eH3o5+JH5V_oigGb1VUPgqrhx5rQ@mail.gmail.com>

On Thu, Aug 17, 2023 at 5:11 PM Budi <budikusasi@gmail.com> 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
other.

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
like
  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
  Functions/Zle/history-search-end
  Functions/Zle/down-line-or-beginning-search
  Functions/Zle/up-line-or-beginning-search
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
  Functions/Zle/vi-pipe
but note that its setup commentary forgot to mention the "zle -N vi-pipe" part.


  reply	other threads:[~2023-08-18  1:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18  0:11 Budi
2023-08-18  1:07 ` Bart Schaefer [this message]
2023-08-18  1:27   ` Budi
2023-08-18  1:28     ` Budi
2023-08-18  4:42     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7aORtEenabc4-zk6q4zhymtL-xzaK+QVXTTzMLeqfWTQA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=budikusasi@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).