On Sun, Dec 17, 2023 at 5:54 AM Vincent Lefevre wrote: > > On 2023-12-09 13:44:42 -0800, Bart Schaefer wrote: > > Ah. It's in the buffer managed in ZLE as $BUFFER, but corrections > > apply left to right as that buffer is converted into a parse tree, > > they don't alter the buffer itself. > > But if one does a first correction, for the second proposed > correction, one types 'e' to edit, one gets the buffer with > the first correction applied. When you type 'e', correction (and alias expansion!) is temporarily disabled, the parser is allowed to run to the end, then the parsed result is reassembled and pushed onto the editor stack (like "print -z") and zle restarts. Watch what happens if you type 'e' for a correction at the PS2 prompt. The parser hasn't reached the end yet, so you get back a PS2 with empty input, and that will keep happening until a full valid statement is entered or you interrupt, and then you get back the entire input so far. This is another reason 'a' doesn't throw away the history -- you could lose many lines of typing above the point of canceling the correction. > > > Or just use 'e', then immediately put the command in the history > > > without running it. Is there a zle widget for that? I would find > > > this useful even when there are no spelling corrections. > > > > Correction is not itself a ZLE action -- it happens after ZLE has > > returned control to the parser, and works even if ZLE is disabled. So > > there's no widget to fiddle with it. > > But what matters to that after 'e', one is in ZLE. You asked if there was a widget to immediately put the command in the history after 'e'. There's not a widget to do all of that, because there's not a widget triggered on 'e'. That said ... attached is an actual ZLE implementation of correctall. I'm not entirely happy with it yet -- problems are: * the tricks using "zstyle -e" are rather fragile * _path_files alters the leading path and then offers only to correct the file name at the end ... * ... which makes it a pain to prompt correctly for the 'n' action * quoted words muddy things. Features of interest: * uses completion, so corrections are context-sensitive rather than simple file globs * offers a menu for multiple corrections (which muddies what 'y' should do, unfortunately) * 'u' (undo) backs out if you TAB too often at that menu * 'a' does in fact discard the current line from the history, but at PS2 it keeps what went before * '!' skips all remaining corrections and runs the command The patch includes a fix for an error I kept encountering in _approximate ... I think this but happens when the "fake" style is used, but haven't run it to ground other than working around it. I will not be pushing this in its current state, use at your own risk (which would be true even if it were pushed, I suppose).