Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: accept-line question
- X-seq: zsh-users 20071
- From: Dave Yost <Dave@xxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: accept-line question
- Date: Thu, 2 Apr 2015 14:50:33 -0700
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:subject:mime-version:content-type:in-reply-to:date:cc :sendlaterdate:message-id:references:to; bh=xSZFX7pKpRw9e38S4jSIraYBK/KgeckbpTQpcxaZaMw=; b=IxImxiE0aKOhKaYt/ZyhCUmM/SMiKxdB6UJhJZJ9Xs501mJ5+XZlapMZjKMAA6kTLh lg019P/4TTiQ+lvD+BkPKs21LruN3R3JIqJDamRHh2g6P9iyj10Ru1PX4crnJn4Xvc1F D9Mz2UC9E1BlNxiTxSxAsmkoW/rctIDRp2owoNiyQIYNf651UEana1P0qfeGY3p1VGVR Bhl1QoyE08ctwpSrVSzJxFkjl8jWxpm9zkcrAIk+yd6bs/ABvuhcfQJeXjX0Z+kvGw4W XNmurLV5iwVdH5GLrVO2U6K5krrKP5fl6BJehaHzTbekFQCvA2VyoFjyLL9PLDfgGmBh f84w==
- In-reply-to: <E00A4521-8A4E-486C-BB2E-5D8D80639156@yost.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <FF62FDC6-BDD8-4BF3-AD44-F36E834D3B4F@yost.com> <E00A4521-8A4E-486C-BB2E-5D8D80639156@yost.com>
- Sender: Dave Yost <daveyostcom@xxxxxxxxx>
- Sendlaterdate: Thu, 2 Apr 2015 14:50:33 -0700
That works.
I do want the executed command to be inserted into history.
I searched the manual in vain for a way to do that. Any chance you could illuminate further?
Thanks
Dave
> Bart Schaefer wrote:
>
> That's now how it works; accept-line in x1 does not run the command and
> then resume ZLE inside the x2 function, and even if it did it would not
> reprint the prompt in that way.
>
> All "accept-line" does is assert that the buffer is now in its final
> state, so that after ZLE finishes, the regular shell parser should read
> that line as the input. However, ZLE does not finish until the current
> active widget has also finished, so if accept-line is run again it can
> still change the previously-accepted buffer.
>
> You'd need something like this:
>
> --- 8< ---
> execute-now() {
> zle -I
> eval "$BUFFER"
> BUFFER=
> zle -R
> }
>
> zle -N execute-now
> --- 8< ---
>
> Then replace any "zle accept-line" with "zle execute-now".
>
> However, *that* does not push the buffer onto the history stack, so even
> more may be necessary depending on what you intend to accomplish.
>
> --
> Barton E. Schaefer
>
>
>> On 2015-04-02, at 10:12 AM, Dave Yost <Dave@xxxxxxxx> wrote:
>>
>> Sorry, that email was flawed. Let me try again.
>>
>> Below, after sourcing a script, I type ^a then ^b.
>> The ^a works as expected, but not the ^b
>>
>> There must be something more I have to do besides “accept-line”. But what?
>>
>> 0 Thu 9:59:38 yost DaveBook ~
>> 206 Z% cat accept-line-test.zsh
>> function xxx {
>> BUFFER="$1"
>> zle -R
>> zle accept-line
>> }
>>
>> function x1 {
>> xxx echo\ 1
>> }
>>
>> function x2 {
>> xxx echo\ 2
>> xxx echo\ 3
>> }
>>
>> zle -N x1
>> zle -N x2
>>
>> bindkey ^a x1
>> bindkey ^b x2
>> 0 Thu 9:59:47 yost DaveBook ~
>> 207 Z% source accept-line-test.zsh
>> 0 Thu 9:59:54 yost DaveBook ~
>> 208 Z% echo 1
>> 1
>> 0 Thu 9:59:55 yost DaveBook ~
>> 209 Z% echo 3
>> 3
>> 0 Thu 9:59:59 yost DaveBook ~
>> 210 Z%
>>
>> The output I want from ^b is
>>
>> 0 Wed 0:30:03 yost DaveBook ~
>> 240 Z% echo 2
>> 2
>> 0 Wed 0:30:04 yost DaveBook ~
>> 241 Z% echo 3
>> 3
>> 0 Wed 0:30:04 yost DaveBook ~
>> 242 Z%
>>
>> Extra credit:
>>
>> Is there a way to write a function x3 that calls x2, such that I can issue x3 from the command line get the result above instead of the result below?
>>
>> 0 Thu 10:04:32 yost DaveBook ~
>> 216 Z% x2
>> xxx:zle:3: widgets can only be called when ZLE is active
>> xxx:zle:3: widgets can only be called when ZLE is active
>> 1 Thu 10:05:55 yost DaveBook ~
>> 217 Z%
>>
>> Thanks
>>
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author