From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 16125 invoked from network); 25 May 2020 21:46:40 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 25 May 2020 21:46:40 -0000 Received: (qmail 27399 invoked by alias); 25 May 2020 21:46:28 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45915 Received: (qmail 26758 invoked by uid 1010); 25 May 2020 21:46:28 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot1-f67.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25821. spamassassin: 3.4.4. Clear:RC:0(209.85.210.67):SA:0(-1.9/5.0):. Processed in 1.934267 secs); 25 May 2020 21:46:28 -0000 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.210.67 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=itEM0jS4JIPbvs3cy7u7hBJMFQKOpVAbvbpSdHSlr3U=; b=gOK7nrYy6xwaa/VyD2tRPSptIMaLcaph8ceFFvCwzlXzVDPJLouEdMiOdZF0RsrNTt ZwDImwaCAtgs4rWms4KNguqXSHm1U+wlGxtBlN4FqSC889ZhjaB8VAusnL3wj6zWtrXH GDF0WPGjvRrEK8ilBSo4wixznLZFeplSXAl3uiUxI86n3j/r1CzaMJOqVf6esUOEH2RZ H5ZQamtnTVOuD3BMdq6gM0HJlQD9HQ/kp96U+G0hjgXNoxPYxZxZn8jSF6KTTFMxXdRP HEgda3bHoM9am8ni/QrvP0glaZRRp/9QzR7f0ww2rcklfFWEnzYVpGfLNRavqLXwm+jj WdUA== X-Gm-Message-State: AOAM533/m5Ka/tJHLK+BtO/eZr2sDEvX5wHT1d9PF70sn0OOF7+apXEG xC9ETY/jLONu/jz4s4w1kND8HvDgRP5Imr63kCtuYS4TG+lQAA== X-Google-Smtp-Source: ABdhPJw0arB7wAbwc6xv9P8FG9SkjusknaB9xoE62MFuFiA6yuzlI3qaBK+QpiFFAnmuBp0NjuXk+sR1TAVkGOy48GE= X-Received: by 2002:a05:6830:16c4:: with SMTP id l4mr23467711otr.161.1590443151395; Mon, 25 May 2020 14:45:51 -0700 (PDT) MIME-Version: 1.0 References: <22f19bb4707e388629092d2e8673d8294fa8e375.camel@ntlworld.com> <2d5fcc3630beeec538b7b4dc334991da7420968e.camel@ntlworld.com> <16a92121a737d366f8f0049bacb375c1693e5ca6.camel@ntlworld.com> In-Reply-To: <16a92121a737d366f8f0049bacb375c1693e5ca6.camel@ntlworld.com> From: Bart Schaefer Date: Mon, 25 May 2020 14:45:40 -0700 Message-ID: Subject: Re: [PATCH?] Re: Autocorrect for commands with a hyphen (dash) in the name To: "zsh-workers@zsh.org" Content-Type: text/plain; charset="UTF-8" On Mon, May 25, 2020 at 9:36 AM Peter Stephenson 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 == '/')