Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH?] Re: Autocorrect for commands with a hyphen (dash) in the name
On Mon, May 25, 2020 at 9:36 AM Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
>
> I think this might be a good approach, given all the complexities
> the other way, but I'd suggest a dupstring if we find a Dash ---
> [...] I don't think we can guarantee they don't intersect
> with cases where spell checking is live.
This definitely doesn't apply to zle_tricky.c, because it
unconditionally untokenizes both before and after spckword() and then
inserts the string returned.
Which leaves lex.c when CORRECT_ALL is in effect. I've tried several
variations but can't engineer a situation where spckword() is called
on a pattern where Dash matters, because it's only called for tokens
of type STRING and when !incasepat. The string would also have to not
include any other tokens preceding the Dash, because spckword() bails
out on the first successful itok(). I don't believe there's any
legitimate pattern that starts with a Dash? But a leading Dash has to
be handled separately anyway, I missed that.
Hmm, so a command word starting with a hyphen has never been
spell-checked? Should we fix that, as below?
Gmail is probably going to mess up lines again, but this still might
not be the final form of the patch. A couple of early bail-out cases
reordered for minor efficiency improvement.
diff --git a/Src/utils.c b/Src/utils.c
index 5158a70..5151b89 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3128,11 +3128,13 @@ spckword(char **s, int hist, int cmd, int ask)
int preflen = 0;
int autocd = cmd && isset(AUTOCD) && strcmp(*s, ".") && strcmp(*s, "..");
- if ((histdone & HISTFLAG_NOEXEC) || **s == '-' || **s == '%')
+ if (!(*s)[0] || !(*s)[1])
return;
- if (!strcmp(*s, "in"))
+ if ((histdone & HISTFLAG_NOEXEC) ||
+ /* Leading % is a job, else leading hyphen is an option */
+ (cmd ? **s == '%' : (**s == '-' || **s == Dash)))
return;
- if (!(*s)[0] || !(*s)[1])
+ if (!strcmp(*s, "in"))
return;
if (cmd) {
if (shfunctab->getnode(shfunctab, *s) ||
@@ -3151,8 +3153,12 @@ spckword(char **s, int hist, int cmd, int ask)
if (*t == Tilde || *t == Equals || *t == String)
t++;
for (; *t; t++)
- if (itok(*t))
- return;
+ if (itok(*t)) {
+ if (*t == Dash)
+ *t = '-';
+ else
+ return;
+ }
best = NULL;
for (t = *s; *t; t++)
if (*t == '/')
Messages sorted by:
Reverse Date,
Date,
Thread,
Author