Re: A ZLE widget for calculator
Vincent Bernat <[email protected]> Sun, 8 Feb 2026 16:06:41 +0100
| Newsgroups | gmane.comp.shells.zsh.user |
|---|---|
| Message-ID | <[email protected]> |
On 2026-02-07 03:51, Bart Schaefer wrote: >> Changing the reorded history compared with what's actually executed >> seems a reasonable thing to have, given all the other things you can do >> with history. > > I'm a little confused by this one: > > On Mon, Feb 2, 2026 at 11:22 PM Vincent Bernat <[email protected]> wrote: >> >> _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 >> } > > The original problem statement as I understand it, is: When the buffer > starts with "= ", form a single quoted word to pass as an argument to > "numbat -e", but preserve the original buffer in the shell history. > > The first implementation, which modifies $BUFFER and then calls > .accept-line, un-quotes and re-quotes the tail of the buffer. You > said: >> a bit clunky to detect when something was quoted and undo it > The implementation above never handles the un-quote part. If that was > required in the first implementation, why is that no longer necessary > there? Won't unwanted extra quotes that appear in the original > $BUFFER be passed through to numbat via "$expr"? On the first implementation, BUFFER was modified then executed. On the second implementation, the numbat command is executed directly and BUFFER is pushed to history (with print -s) without any alteration. No call to accept-line. > I think the attached does what you want. It's based on the > modify-$BUFFER + .accept-line variation because among other things > that has the advantage of working at the PS2 prompt. It > unconditionally removes and re-adds quotes. The original $BUFFER is > saved in a global variable which is then added to the history by the > preexec hook, after suppressing the automatic history with > zshaddhistory hook. This could probably use a function instead of an > alias for "=", but I didn't change that. Thanks, it works perfectly!