Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A ZLE widget for calculator
- X-seq: zsh-users 30432
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: A ZLE widget for calculator
- Date: Tue, 3 Feb 2026 12:21:41 +0000 (GMT)
- Archived-at: <https://zsh.org/users/30432>
- Feedback-id: 20260203-p.w.stephenson@xxxxxxxxxxxx:oxsmtp-prd-nl-vmo:Authrelay:p.w.stephenson@xxxxxxxxxxxx
- Importance: Normal
- In-reply-to: <a1738285-db4e-4658-8148-ea694387e6a8@luffy.cx>
- List-id: <zsh-users.zsh.org>
- References: <a1738285-db4e-4658-8148-ea694387e6a8@luffy.cx>
> On 03/02/2026 07:16 GMT Vincent Bernat <bernat@xxxxxxxx> wrote:
> # Simple calculator
> _vbe_calc_accept_line() {
> if [[ $BUFFER =~ "= *" ]]; then
> local expr=${BUFFER#= }
> zle -I
> command numbat -e "$expr"
> print
> print -s $BUFFER
> BUFFER=""
> else
> zle .accept-line
> fi
> }
> zle -N accept-line _vbe_calc_accept_line
>
> It almost work, but the buffer is not available in the immediate history
> (because no accept-line was called). If I press the up arrow, I get the
> previous one instead.
Does adding "print -s <line>" to the function work?
(I was thinking about getting the shell to ignore the line executed as
well --- there are features for this --- but it's not quite smooth as
the line does hang around until after you execute something else, so
doesn't look like that would be what you want. But maybe you now have
enough anyway...)
cheers
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author