Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: widget function must have zle codes
- X-seq: zsh-users 29166
- From: Budi <budikusasi@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: widget function must have zle codes
- Date: Fri, 18 Aug 2023 08:28:48 +0700
- Archived-at: <https://zsh.org/users/29166>
- In-reply-to: <CAH0GyZC-1jSx1xs4ZDjH4VLo3PEzUmtqTQF4uOnNc0nrTf=z+Q@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAH0GyZDVjXS-PXxxV3C458eH3o5+JH5V_oigGb1VUPgqrhx5rQ@mail.gmail.com> <CAH+w=7aORtEenabc4-zk6q4zhymtL-xzaK+QVXTTzMLeqfWTQA@mail.gmail.com> <CAH0GyZC-1jSx1xs4ZDjH4VLo3PEzUmtqTQF4uOnNc0nrTf=z+Q@mail.gmail.com>
original simpe aim:
to nullify any std output in bind -s, (Bash bind-x default)
bindkey -s "^m" "\e[H 2>/dev/null [[ $- =~ x ]]&&{ set +x;echo Trace
OFF ;} ||{ set -x;echo Trace ON;};print -s '\e[F'\r\e[A"
How is the precise correct one ?
On 8/18/23, Budi <budikusasi@xxxxxxxxx> wrote:
> original simpe aim,
> to nullify any std output in bind -s, (Bash bind-x default)
>
>
>
> bindkey -s "^m" "\e[H 2>/dev/null [[ $- =~ x ]]&&{ set +x;echo Trace
> OFF ;} ||{ set -x;echo Trace ON;};print -s '\e[F'\r\e[A"
>
>
> How is the precise correct one ?
>
>
> On 8/18/23, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>> 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
>> 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.
>>
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author