Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] With CORRECT_ALL, an interrupted correct puts a truncated entry in history



On Mon, Dec 4, 2023 at 6:12 PM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
>
> zira% setopt CORRECT_ALL
> zira% echo fil && true
> zsh: correct 'fil' to 'file' [nyae]?
>
> Here, type Ctrl-C to interrupt.
>
> "echo fil" shouldn't have been put in the history.

What's happening here is that the corrections occur in-place as the
parser reads words from the input line, much the same way that aliases
are expanded.

When you hit ctrl-c you cause an interrupt signal which stops the
parser from reading any further input, but because it's interactive
the shell itself doesn't exit, it just forces the parser to return.
The history mechanism then records what the parser read so far.

Conversely when you hit e.g. 'a' the parser is not interrupted,
continues to the end of the line, and then returns.  Again the history
mechanism records what the parser read so far.

Changing this would potentially require changing the way the
lexer+parser handle interrupt signals in general ... or changing both
^C and 'a' to skip the history, I suspect.

> BTW, the behavior in case of several spelling corrections should
> be documented.

Something like this?
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index cbd3d0f8e..c3af8dd33 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1214,6 +1214,9 @@ Note that, when the tt(HASH_LIST_ALL) option is not set or when some
 directories in the path are not readable, this may falsely report spelling
 errors the first time some commands are used.
 
+Refer to the shell variable tt(SPROMPT) for an explanation of the
+`tt([nyae])' (no/yes/abort/edit) prompt that is offered.
+
 The shell variable tt(CORRECT_IGNORE) may be set to a pattern to
 match words that will never be offered as corrections.
 )
@@ -1222,7 +1225,10 @@ pindex(NO_CORRECT_ALL)
 pindex(CORRECTALL)
 pindex(NOCORRECTALL)
 item(tt(CORRECT_ALL) (tt(-O)))(
-Try to correct the spelling of all arguments in a line.
+Try to correct the spelling of all arguments in a line, in order from
+left to right, treating each as a file name.  Answering `tt(a)' or
+`tt(e)' at any prompt stops all corrections, otherwise every correction
+is prompted for.
 
 The shell variable tt(CORRECT_IGNORE_FILE) may be set to a pattern to
 match file names that will never be offered as corrections.


Messages sorted by: Reverse Date, Date, Thread, Author