zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: [PATCH?] Re: Autocorrect for commands with a hyphen (dash) in the name
Date: Mon, 25 May 2020 14:45:40 -0700	[thread overview]
Message-ID: <CAH+w=7Z3g5TXTfR1c6O-QgE3QcmCD-anQp-R4mFUdBFyhVn+5A@mail.gmail.com> (raw)
In-Reply-To: <16a92121a737d366f8f0049bacb375c1693e5ca6.camel@ntlworld.com>

On Mon, May 25, 2020 at 9:36 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> 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 == '/')

  reply	other threads:[~2020-05-25 21:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAOoO2vg=-9P7v=ATOzrbh6VF35o_xzK_-yF+EA6OgTHsQBik-A@mail.gmail.com>
     [not found] ` <CAH+w=7bKpm7GO2ZhbA5Apr0sBDz5=kmX1=WK2X0nTcWxpkHPPQ@mail.gmail.com>
     [not found]   ` <ab8b7655-83e8-45b2-889f-043314faea62@www.fastmail.com>
     [not found]     ` <CAH+w=7aqAO37qpSvtmJXMPWq3zP=pUAZCe3i-BFyn0knRmFjVQ@mail.gmail.com>
2020-05-23 19:33       ` Bart Schaefer
2020-05-23 19:44         ` Peter Stephenson
2020-05-23 19:54           ` Bart Schaefer
2020-05-23 20:30             ` Peter Stephenson
2020-05-23 21:18               ` Bart Schaefer
2020-05-24 17:11                 ` Peter Stephenson
2020-05-24 18:39                   ` Bart Schaefer
2020-05-25  5:46                     ` Bart Schaefer
2020-05-25 16:35                       ` Peter Stephenson
2020-05-25 21:45                         ` Bart Schaefer [this message]
2020-05-30 21:25                           ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7Z3g5TXTfR1c6O-QgE3QcmCD-anQp-R4mFUdBFyhVn+5A@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).