Re: A ZLE widget for calculator
Vincent Bernat <[email protected]> Tue, 3 Feb 2026 20:38:44 +0100
| Newsgroups | gmane.comp.shells.zsh.user |
|---|---|
| Message-ID | <[email protected]> |
On 2026-02-03 13:21, Peter Stephenson wrote: >> On 03/02/2026 07:16 GMT Vincent Bernat <[email protected]> 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? This is already there. It works. If I hit return, then up, it works. But if I press only up, it does not. It seems accept-line widget is needed for the line to be added to the history. > (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...) I can prefix with a space if that's what you mean, but in this case pressing up just after will recall this instance (which is quoted). So, yes, this is not as smooth as I would like. Thanks!